test: add e2e tests (#21)
* test: add e2e tests Spin up GCP resources for testing dynamic host catalogs. The resources are tested with tests that focus on credential changes and rotation for host catalog and host set creation and updates using labels. - The tests all depend on each other so they need to run in order. - The test can also only be executed locally for now. - The resources are cleaned up after the test as part of the test.
This commit is contained in:
1 parent
baa2c7a2e7
commit
d3a155bd3f
11 files changed
+1274
-103
No files matched your search
Vendored
+77
@@ -0,0 +1,77 @@
|
||||
# Copyright (c) HashiCorp, Inc.
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
resource "random_id" "service_account_client_email" {
|
||||
prefix = "test-${var.user_prefix}"
|
||||
byte_length = 2
|
||||
}
|
||||
|
||||
resource "google_service_account" "test_service_account" {
|
||||
project = var.project_id
|
||||
account_id = random_id.service_account_client_email.dec
|
||||
display_name = "test-${var.user_prefix}"
|
||||
}
|
||||
|
||||
resource "google_project_iam_binding" "test_service_account_user" {
|
||||
project = var.project_id
|
||||
count = length(var.rolesList)
|
||||
role = var.rolesList[count.index]
|
||||
members = [
|
||||
"serviceAccount:${google_service_account.test_service_account.email}"
|
||||
]
|
||||
}
|
||||
|
||||
resource "google_service_account_key" "test_service_account_key" {
|
||||
service_account_id = google_service_account.test_service_account.name
|
||||
public_key_type = "TYPE_X509_PEM_FILE"
|
||||
private_key_type = "TYPE_GOOGLE_CREDENTIALS_FILE"
|
||||
key_algorithm = "KEY_ALG_RSA_2048"
|
||||
}
|
||||
|
||||
resource "google_service_account_key" "test_service_account_keys" {
|
||||
count = var.num_service_account_keys
|
||||
service_account_id = google_service_account.test_service_account.name
|
||||
public_key_type = "TYPE_X509_PEM_FILE"
|
||||
private_key_type = "TYPE_GOOGLE_CREDENTIALS_FILE"
|
||||
key_algorithm = "KEY_ALG_RSA_2048"
|
||||
}
|
||||
|
||||
resource "google_compute_instance" "instances" {
|
||||
project = var.project_id
|
||||
count = var.num_instances
|
||||
name = "boundary-${count.index}"
|
||||
machine_type = "n2-standard-2"
|
||||
zone = var.zone
|
||||
labels = var.labels
|
||||
tags = ["test-instance-${count.index}"]
|
||||
|
||||
boot_disk {
|
||||
initialize_params {
|
||||
image = "ubuntu-os-cloud/ubuntu-2204-lts"
|
||||
labels = var.labels
|
||||
}
|
||||
}
|
||||
|
||||
network_interface {
|
||||
network = "default"
|
||||
|
||||
access_config {
|
||||
// Ephemeral public IP
|
||||
}
|
||||
}
|
||||
|
||||
metadata = {
|
||||
ssh-keys = "ubuntu:${tls_private_key.ssh.public_key_openssh}"
|
||||
}
|
||||
|
||||
service_account {
|
||||
email = google_service_account.test_service_account.email
|
||||
scopes = ["cloud-platform"]
|
||||
}
|
||||
}
|
||||
|
||||
# RSA key of size 4096 bits
|
||||
resource "tls_private_key" "ssh" {
|
||||
algorithm = "RSA"
|
||||
rsa_bits = 4096
|
||||
}
|
||||
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
# Copyright (c) HashiCorp, Inc.
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
output "client_email" {
|
||||
value = google_service_account.test_service_account.email
|
||||
}
|
||||
|
||||
output "private_keys" {
|
||||
value = [for key in google_service_account_key.test_service_account_keys : jsondecode(base64decode(key.private_key)).private_key]
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
output "private_key_ids" {
|
||||
value = [for key in google_service_account_key.test_service_account_keys : chomp(reverse(split("/", key.id))[0])]
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
output "instance_ids" {
|
||||
value = google_compute_instance.instances.*.id
|
||||
}
|
||||
|
||||
output "instance_tags" {
|
||||
value = {
|
||||
for instance in google_compute_instance.instances : instance.id => instance.tags
|
||||
}
|
||||
}
|
||||
|
||||
output "instance_labels" {
|
||||
value = {
|
||||
for instance in google_compute_instance.instances : instance.id => instance.labels
|
||||
}
|
||||
}
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
# Copyright (c) HashiCorp, Inc.
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
terraform {
|
||||
required_providers {
|
||||
google = {
|
||||
source = "hashicorp/google"
|
||||
version = "~> 5.22.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "google" {
|
||||
region = var.region
|
||||
project = var.project_id
|
||||
}
|
||||
Vendored
+50
@@ -0,0 +1,50 @@
|
||||
# Copyright (c) HashiCorp, Inc.
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
data "google_client_openid_userinfo" "current" {}
|
||||
|
||||
variable "labels" {
|
||||
type = map(string)
|
||||
default = {
|
||||
repository = "boundary-plugin-gcp"
|
||||
purpose = "testing"
|
||||
}
|
||||
}
|
||||
|
||||
variable "project_id" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "region" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "zone" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "num_instances" {
|
||||
type = number
|
||||
default = 3
|
||||
}
|
||||
|
||||
variable "service_account_email" {
|
||||
type = string
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "rolesList" {
|
||||
type = list(string)
|
||||
description = "List of roles to assign to the service account"
|
||||
default = ["roles/compute.viewer","roles/iam.serviceAccountKeyAdmin"]
|
||||
}
|
||||
|
||||
variable "user_prefix" {
|
||||
type = string
|
||||
default = "boundary-gcp-plugin"
|
||||
}
|
||||
|
||||
variable "num_service_account_keys" {
|
||||
type = number
|
||||
default = 6
|
||||
}
|
||||
Reference in new issue
Block a user