test(e2e): add GCP dynamic host catalog e2e tests (#5294)

* test(e2e): add GCP infra resources and tests for enos testing

- add 1 new `gcp_target` module that creates a GCP VM instance with labels for filtering
- add GCP dynamic host catalog e2e tests
This commit is contained in:
Elim Tsiagbey authored and GitHub committed 2024-12-17 14:06:14 -05:00
1 parent 862a30c389
commit a4f2a704fd
16 files changed
+992 -6

No files matched your search

+160
View File
@@ -0,0 +1,160 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: BUSL-1.1
terraform {
required_providers {
enos = {
source = "registry.terraform.io/hashicorp-forge/enos"
}
}
}
variable "target_count" {}
variable "enos_user" {}
variable "additional_labels" {
default = {}
}
variable "instance_type" {
description = "The type of instance to create."
type = string
default = "e2-micro"
}
variable "environment" {
description = "Name of the environment."
type = string
default = "enos-environment"
}
variable "private_cidr_block" {
type = list(string)
default = ["10.0.0.0/8"]
}
variable "gcp_zone" {
description = "The zone to deploy the resources."
type = string
default = "us-central1-a"
}
data "enos_environment" "current" {}
resource "random_string" "test_string" {
length = 5
lower = true
upper = false
numeric = false
special = false
}
resource "google_compute_network" "boundary_compute_network" {
name = "boundary-enos-network-${random_string.test_string.result}"
}
resource "random_id" "filter_label1" {
prefix = "enos_boundary"
byte_length = 4
}
resource "random_id" "filter_label2" {
prefix = "enos_boundary"
byte_length = 4
}
resource "tls_private_key" "ssh" {
algorithm = "RSA"
rsa_bits = 4096
}
resource "google_compute_address" "boundary_external_ip" {
count = var.target_count
name = "boundary-external-ip-${random_string.test_string.result}-${count.index}"
address_type = "EXTERNAL"
}
resource "google_compute_firewall" "boundary_private_ssh" {
name = "boundary-private-ssh-${random_string.test_string.result}"
network = google_compute_network.boundary_compute_network.name
source_ranges = var.private_cidr_block
target_tags = ["boundary-target-${random_string.test_string.result}"]
allow {
protocol = "tcp"
ports = ["22"]
}
}
resource "google_compute_firewall" "boundary_enos_ssh" {
name = "boundary-enos-ssh-${random_string.test_string.result}"
network = google_compute_network.boundary_compute_network.name
source_ranges = flatten([formatlist("%s/32", data.enos_environment.current.public_ipv4_addresses)])
target_tags = ["boundary-target-${random_string.test_string.result}"]
allow {
protocol = "tcp"
ports = ["22"]
}
}
resource "google_compute_instance" "boundary_target" {
count = var.target_count
name = "boundary-target-${random_string.test_string.result}-${count.index}"
machine_type = var.instance_type
zone = var.gcp_zone
boot_disk {
initialize_params {
image = "ubuntu-os-cloud/ubuntu-2204-lts"
}
}
network_interface {
network = google_compute_network.boundary_compute_network.id
access_config {
nat_ip = google_compute_address.boundary_external_ip[count.index].address
}
}
tags = ["boundary-target-${random_string.test_string.result}"]
metadata = {
ssh-keys = "ubuntu:${tls_private_key.ssh.public_key_openssh}"
}
labels = merge(var.additional_labels, {
"name" : "boundary-target-${random_string.test_string.result}-${count.index}",
"type" : "target",
"project" : "enos",
"project_name" : "qti-enos-boundary",
"environment" : var.environment,
"enos_user" : var.enos_user,
"filter_label_1" : random_id.filter_label1.hex
"filter_label_2" : random_id.filter_label2.hex
})
}
output "target_private_ips" {
value = [for instance in google_compute_instance.boundary_target : instance.network_interface[0].network_ip]
}
output "target_public_ips" {
value = [for instance in google_compute_instance.boundary_target : instance.network_interface[0].access_config[0].nat_ip]
}
output "target_ips" {
value = flatten([
[for instance in google_compute_instance.boundary_target : instance.network_interface[0].network_ip],
[for instance in google_compute_instance.boundary_target : instance.network_interface[0].access_config[0].nat_ip]
])
}
output "target_ssh_key" {
value = tls_private_key.ssh.private_key_pem
sensitive = true
}
output "filter_label1" {
value = "labels.filter_label_1=${random_id.filter_label1.hex}"
}
output "filter_label2" {
value = "labels.filter_label_2=${random_id.filter_label2.hex}"
}
+66
View File
@@ -222,6 +222,63 @@ variable "test_timeout" {
type = string
default = "25m"
}
variable "gcp_private_key_id" {
description = "ID of the private key used to authenticate with GCP"
type = string
sensitive = true
default = ""
}
variable "gcp_private_key" {
description = "Private key used to authenticate with GCP"
type = string
sensitive = true
default = ""
}
variable "gcp_project_id" {
description = "GCP project where the resources will be created"
type = string
default = ""
}
variable "gcp_zone" {
description = "GCP zone where the resources will be created"
type = string
default = ""
}
variable "gcp_target_ssh_key" {
description = "SSH key used to authenticate with GCP target"
type = string
sensitive = true
default = ""
}
variable "gcp_client_email" {
description = "GCP client email associated with the private key"
type = string
sensitive = true
default = ""
}
variable "gcp_host_set_filter1" {
description = "value for the first filter in the host set"
type = string
default = ""
}
variable "gcp_host_set_filter2" {
description = "value for the second filter in the host set"
type = string
default = ""
}
variable "gcp_host_set_ips" {
description = "List of IP addresses"
type = list(string)
default = [""]
}
resource "enos_local_exec" "get_go_version" {
count = var.go_version == "" ? 1 : 0
@@ -284,6 +341,15 @@ resource "enos_local_exec" "run_e2e_test" {
E2E_LDAP_USER_NAME = var.ldap_user_name
E2E_LDAP_USER_PASSWORD = var.ldap_user_password
E2E_LDAP_GROUP_NAME = var.ldap_group_name
E2E_GCP_PRIVATE_KEY_ID = var.gcp_private_key_id
E2E_GCP_PRIVATE_KEY = var.gcp_private_key
E2E_GCP_PROJECT_ID = var.gcp_project_id
E2E_GCP_CLIENT_EMAIL = var.gcp_client_email
E2E_GCP_ZONE = var.gcp_zone
E2E_GCP_TARGET_SSH_KEY = var.gcp_target_ssh_key
E2E_GCP_HOST_SET_FILTER1 = var.gcp_host_set_filter1
E2E_GCP_HOST_SET_FILTER2 = var.gcp_host_set_filter2
E2E_GCP_HOST_SET_IPS = jsonencode(var.gcp_host_set_ips)
E2E_MAX_PAGE_SIZE = var.max_page_size
E2E_CONTROLLER_CONTAINER_NAME = var.controller_container_name
BOUNDARY_DIR = abspath(var.local_boundary_src_dir)
@@ -45,6 +45,15 @@ docker run \
-e "E2E_LDAP_USER_NAME=$E2E_LDAP_USER_NAME" \
-e "E2E_LDAP_USER_PASSWORD=$E2E_LDAP_USER_PASSWORD" \
-e "E2E_LDAP_GROUP_NAME=$E2E_LDAP_GROUP_NAME" \
-e "E2E_GCP_PRIVATE_KEY_ID=$E2E_GCP_PRIVATE_KEY_ID" \
-e "E2E_GCP_PRIVATE_KEY=$E2E_GCP_PRIVATE_KEY" \
-e "E2E_GCP_CLIENT_EMAIL=$E2E_GCP_CLIENT_EMAIL" \
-e "E2E_GCP_PROJECT_ID=$E2E_GCP_PROJECT_ID" \
-e "E2E_GCP_ZONE=$E2E_GCP_ZONE" \
-e "E2E_GCP_TARGET_SSH_KEY=$E2E_GCP_TARGET_SSH_KEY" \
-e "E2E_GCP_HOST_SET_FILTER1=$E2E_GCP_HOST_SET_FILTER1" \
-e "E2E_GCP_HOST_SET_FILTER2=$E2E_GCP_HOST_SET_FILTER2" \
-e "E2E_GCP_HOST_SET_IPS=$E2E_GCP_HOST_SET_IPS" \
-e "E2E_MAX_PAGE_SIZE=$E2E_MAX_PAGE_SIZE" \
-e "E2E_CONTROLLER_CONTAINER_NAME=$E2E_CONTROLLER_CONTAINER_NAME" \
--mount type=bind,src=$BOUNDARY_DIR,dst=/src/boundary/ \