From da7d41cab8ced6a3634356a3028e947236f118c5 Mon Sep 17 00:00:00 2001 From: David Bloss Date: Thu, 17 Oct 2024 10:22:29 -0500 Subject: [PATCH] update aws, gcp, azure integration tests, add test debug task (#510) * WIP: update aws integration test, add test debug task * WIP: update google_cloud integration test, rm unused test files * testing integrations expect correct errors * remove unused azure integration test files --- Taskfile.yml | 6 + opslevel/resource_opslevel_integration_aws.go | 2 +- ...ce_opslevel_integration_azure_resources.go | 2 +- taskfiles/Debug.yml | 16 +- tests/integration_aws.tftest.hcl | 286 ++++++++++++++++++ ...=> integration_azure_resources.tftest.hcl} | 125 +++++++- ...cl => integration_google_cloud.tftest.hcl} | 77 ++++- tests/opslevel_modules | 2 +- tests/remote/integration_aws/main.tf | 8 - tests/remote/integration_aws/variables.tf | 32 -- tests/remote/integration_aws_all.tftest.hcl | 156 ---------- tests/remote/integration_aws_min.tftest.hcl | 144 --------- .../integration_azure_resources/main.tf | 10 - .../integration_azure_resources/variables.tf | 37 --- ...integration_azure_resources_min.tftest.hcl | 133 -------- tests/remote/integration_google_cloud/main.tf | 7 - .../integration_google_cloud/outputs.tf | 5 - .../integration_google_cloud/variables.tf | 27 -- .../integration_google_cloud_min.tftest.hcl | 112 ------- 19 files changed, 493 insertions(+), 694 deletions(-) create mode 100644 tests/integration_aws.tftest.hcl rename tests/{remote/integration_azure_resources_all.tftest.hcl => integration_azure_resources.tftest.hcl} (53%) rename tests/{remote/integration_google_cloud_all.tftest.hcl => integration_google_cloud.tftest.hcl} (59%) delete mode 100644 tests/remote/integration_aws/main.tf delete mode 100644 tests/remote/integration_aws/variables.tf delete mode 100644 tests/remote/integration_aws_all.tftest.hcl delete mode 100644 tests/remote/integration_aws_min.tftest.hcl delete mode 100644 tests/remote/integration_azure_resources/main.tf delete mode 100644 tests/remote/integration_azure_resources/variables.tf delete mode 100644 tests/remote/integration_azure_resources_min.tftest.hcl delete mode 100644 tests/remote/integration_google_cloud/main.tf delete mode 100644 tests/remote/integration_google_cloud/outputs.tf delete mode 100644 tests/remote/integration_google_cloud/variables.tf delete mode 100644 tests/remote/integration_google_cloud_min.tftest.hcl diff --git a/Taskfile.yml b/Taskfile.yml index 8c4f16d6..1c2cb37a 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -114,6 +114,12 @@ tasks: cmds: - task: debug:do-debug-plan + debug-test: + desc: After debug-start and debug-attach, run "terraform test" with 'TF_REATTACH_PROVIDERS' + aliases: ["dbg-test"] + cmds: + - task: debug:do-debug-test + terraform-clean: desc: Completely wipe terraform state, terraform generated files, and local OpsLevel provider binaries aliases: ["clean"] diff --git a/opslevel/resource_opslevel_integration_aws.go b/opslevel/resource_opslevel_integration_aws.go index 5ce0681a..683c6e05 100644 --- a/opslevel/resource_opslevel_integration_aws.go +++ b/opslevel/resource_opslevel_integration_aws.go @@ -163,7 +163,7 @@ func (r *IntegrationAwsResource) Read(ctx context.Context, req resource.ReadRequ return } - awsIntegration, err := r.client.GetIntegration(opslevel.ID(stateModel.Id.ValueString())) + awsIntegration, err := r.client.GetIntegration(asID(stateModel.Id)) if err != nil { if (awsIntegration == nil || awsIntegration.Id == "") && opslevel.IsOpsLevelApiError(err) { resp.State.RemoveResource(ctx) diff --git a/opslevel/resource_opslevel_integration_azure_resources.go b/opslevel/resource_opslevel_integration_azure_resources.go index 11b59493..9f6ba41a 100644 --- a/opslevel/resource_opslevel_integration_azure_resources.go +++ b/opslevel/resource_opslevel_integration_azure_resources.go @@ -208,7 +208,7 @@ func (r *IntegrationAzureResourcesResource) Read(ctx context.Context, req resour return } - azureResourcesIntegration, err := r.client.GetIntegration(opslevel.ID(stateModel.Id.ValueString())) + azureResourcesIntegration, err := r.client.GetIntegration(asID(stateModel.Id)) if err != nil { if (azureResourcesIntegration == nil || azureResourcesIntegration.Id == "") && opslevel.IsOpsLevelApiError(err) { resp.State.RemoveResource(ctx) diff --git a/taskfiles/Debug.yml b/taskfiles/Debug.yml index 691a7b52..c4cb7ce9 100644 --- a/taskfiles/Debug.yml +++ b/taskfiles/Debug.yml @@ -24,26 +24,24 @@ tasks: - echo "Set breakpoints once connected, then run 'task debug-plan' in a new shell" - dlv connect 127.0.0.1:{{.LOCAL_PORT}} - do-debug-apply: - desc: After debug-start and debug-attach, run "terraform plan" with 'TF_REATTACH_PROVIDERS' - aliases: ["dbg-apply"] + do-debug-*: + desc: After debug-start and debug-attach, run "terraform {{index .MATCH 0}}" with 'TF_REATTACH_PROVIDERS' vars: TF_REATTACH_PROVIDERS: sh: grep 'TF_REATTACH_PROVIDERS=' {{.DEBUG_LOG}} | cut -d'=' -f2- interactive: true cmds: - - TF_REATTACH_PROVIDERS={{.TF_REATTACH_PROVIDERS}} terraform -chdir="{{.ROOT_DIR}}/{{.WORKSPACE_DIR}}" apply + - echo "After 'terraform {{index .MATCH 0}}' is started, return to shell with interactive delve session" + - TF_REATTACH_PROVIDERS={{.TF_REATTACH_PROVIDERS}} terraform -chdir="{{.ROOT_DIR}}/{{.WORKSPACE_DIR}}" {{index .MATCH 0}} - do-debug-plan: - desc: After debug-start and debug-attach, run "terraform plan" with 'TF_REATTACH_PROVIDERS' - aliases: ["dbg-plan"] + do-debug-test: + desc: After debug-start and debug-attach, run "terraform test" with 'TF_REATTACH_PROVIDERS' vars: TF_REATTACH_PROVIDERS: sh: grep 'TF_REATTACH_PROVIDERS=' {{.DEBUG_LOG}} | cut -d'=' -f2- interactive: true cmds: - - echo "After 'terraform plan' is started, return to shell with interactive delve session" - - TF_REATTACH_PROVIDERS={{.TF_REATTACH_PROVIDERS}} terraform -chdir="{{.ROOT_DIR}}/{{.WORKSPACE_DIR}}" plan + - TF_REATTACH_PROVIDERS={{.TF_REATTACH_PROVIDERS}} terraform -chdir="{{.ROOT_DIR}}/{{.TEST_DIR}}" test -var-file=test.tfvars {{.CLI_ARGS}} do-debug-start: desc: First, start headless debug diff --git a/tests/integration_aws.tftest.hcl b/tests/integration_aws.tftest.hcl new file mode 100644 index 00000000..2ce22009 --- /dev/null +++ b/tests/integration_aws.tftest.hcl @@ -0,0 +1,286 @@ +variables { + resource_name = "opslevel_integration_aws" + + # required fields + external_id = "194c7dfc-3a3f-4b0a-b898-578ce7e8f6dc" + iam_role = "arn:aws:iam::994866125780:user/opslevel-test" + name = "TF Test AWS Integration" + + # optional fields + ownership_tag_overrides = false + ownership_tag_keys = ["one", "two", "three", "four", "five"] + region_override = ["eu-west-1", "us-east-1"] + + # default values - computed from API + default_ownership_tag_keys = tolist(["owner"]) + default_ownership_tag_overrides = true +} + +run "resource_integration_aws_create_with_all_fields" { + + module { + source = "./opslevel_modules/modules/integration/aws" + } + + assert { + condition = alltrue([ + can(opslevel_integration_aws.this.external_id), + can(opslevel_integration_aws.this.iam_role), + can(opslevel_integration_aws.this.id), + can(opslevel_integration_aws.this.ownership_tag_keys), + can(opslevel_integration_aws.this.ownership_tag_overrides), + can(opslevel_integration_aws.this.name), + can(opslevel_integration_aws.this.region_override), + ]) + error_message = replace(var.error_unexpected_resource_fields, "TYPE", var.resource_name) + } + + assert { + condition = opslevel_integration_aws.this.external_id == var.external_id + error_message = format( + "expected '%v' but got '%v'", + var.external_id, + opslevel_integration_aws.this.external_id, + ) + } + + assert { + condition = opslevel_integration_aws.this.iam_role == var.iam_role + error_message = format( + "expected '%v' but got '%v'", + var.iam_role, + opslevel_integration_aws.this.iam_role, + ) + } + + assert { + condition = startswith(opslevel_integration_aws.this.id, var.id_prefix) + error_message = replace(var.error_wrong_id, "TYPE", var.resource_name) + } + + assert { + condition = opslevel_integration_aws.this.name == var.name + error_message = format( + "expected '%v' but got '%v'", + var.name, + opslevel_integration_aws.this.name, + ) + } + + assert { + condition = opslevel_integration_aws.this.ownership_tag_keys == var.ownership_tag_keys + error_message = format( + "expected '%v' but got '%v'", + var.ownership_tag_keys, + opslevel_integration_aws.this.ownership_tag_keys, + ) + } + + assert { + condition = opslevel_integration_aws.this.ownership_tag_overrides == var.ownership_tag_overrides + error_message = format( + "expected '%v' but got '%v'", + var.ownership_tag_overrides, + opslevel_integration_aws.this.ownership_tag_overrides, + ) + } + + assert { + condition = opslevel_integration_aws.this.region_override == var.region_override + error_message = format( + "expected '%v' but got '%v'", + var.region_override, + opslevel_integration_aws.this.region_override, + ) + } + +} + +run "resource_integration_aws_unset_optional_fields" { + + variables { + ownership_tag_keys = null + ownership_tag_overrides = null + region_override = null + } + + module { + source = "./opslevel_modules/modules/integration/aws" + } + + assert { + condition = opslevel_integration_aws.this.ownership_tag_keys == var.default_ownership_tag_keys + error_message = format( + "expected default '%v' but got '%v'", + var.default_ownership_tag_keys, + opslevel_integration_aws.this.ownership_tag_keys, + ) + } + + assert { + condition = opslevel_integration_aws.this.ownership_tag_overrides == var.default_ownership_tag_overrides + error_message = format( + "expected default '%v' but got '%v'", + var.default_ownership_tag_overrides, + opslevel_integration_aws.this.ownership_tag_overrides, + ) + } + + assert { + condition = opslevel_integration_aws.this.region_override == null + error_message = var.error_expected_null_field + } + +} + +run "delete_aws_integration_outside_of_terraform" { + + variables { + resource_id = run.resource_integration_aws_create_with_all_fields.this.id + resource_type = "integration" + } + + module { + source = "./provisioner" + } +} + +run "resource_integration_aws_create_with_required_fields" { + + variables { + ownership_tag_overrides = null + ownership_tag_keys = null + region_override = null + } + + module { + source = "./opslevel_modules/modules/integration/aws" + } + + assert { + condition = run.resource_integration_aws_create_with_all_fields.this.id != opslevel_integration_aws.this.id + error_message = format( + "expected old id '%v' to be different from new id '%v'", + run.resource_integration_aws_create_with_all_fields.this.id, + opslevel_integration_aws.this.id, + ) + } + + assert { + condition = opslevel_integration_aws.this.external_id == var.external_id + error_message = format( + "expected '%v' but got '%v'", + var.external_id, + opslevel_integration_aws.this.external_id, + ) + } + + assert { + condition = opslevel_integration_aws.this.iam_role == var.iam_role + error_message = format( + "expected '%v' but got '%v'", + var.iam_role, + opslevel_integration_aws.this.iam_role, + ) + } + + assert { + condition = startswith(opslevel_integration_aws.this.id, var.id_prefix) + error_message = replace(var.error_wrong_id, "TYPE", var.resource_name) + } + + assert { + condition = opslevel_integration_aws.this.name == var.name + error_message = format( + "expected '%v' but got '%v'", + var.name, + opslevel_integration_aws.this.name, + ) + } + + assert { + condition = opslevel_integration_aws.this.ownership_tag_keys == var.default_ownership_tag_keys + error_message = format( + "expected '%v' but got '%v'", + var.default_ownership_tag_keys, + opslevel_integration_aws.this.ownership_tag_keys, + ) + } + + assert { + condition = opslevel_integration_aws.this.ownership_tag_overrides == var.default_ownership_tag_overrides + error_message = format( + "expected '%v' but got '%v'", + var.default_ownership_tag_overrides, + opslevel_integration_aws.this.ownership_tag_overrides, + ) + } + + assert { + condition = opslevel_integration_aws.this.region_override == null + error_message = var.error_expected_null_field + } + +} + +run "resource_integration_aws_set_all_fields" { + + module { + source = "./opslevel_modules/modules/integration/aws" + } + + assert { + condition = opslevel_integration_aws.this.external_id == var.external_id + error_message = format( + "expected '%v' but got '%v'", + var.external_id, + opslevel_integration_aws.this.external_id, + ) + } + + assert { + condition = opslevel_integration_aws.this.iam_role == var.iam_role + error_message = format( + "expected '%v' but got '%v'", + var.iam_role, + opslevel_integration_aws.this.iam_role, + ) + } + + assert { + condition = opslevel_integration_aws.this.name == var.name + error_message = format( + "expected '%v' but got '%v'", + var.name, + opslevel_integration_aws.this.name, + ) + } + + assert { + condition = opslevel_integration_aws.this.ownership_tag_keys == var.ownership_tag_keys + error_message = format( + "expected '%v' but got '%v'", + var.ownership_tag_keys, + opslevel_integration_aws.this.ownership_tag_keys, + ) + } + + assert { + condition = opslevel_integration_aws.this.ownership_tag_overrides == var.ownership_tag_overrides + error_message = format( + "expected '%v' but got '%v'", + var.ownership_tag_overrides, + opslevel_integration_aws.this.ownership_tag_overrides, + ) + } + + assert { + condition = opslevel_integration_aws.this.region_override == var.region_override + error_message = format( + "expected '%v' but got '%v'", + var.region_override, + opslevel_integration_aws.this.region_override, + ) + } + +} diff --git a/tests/remote/integration_azure_resources_all.tftest.hcl b/tests/integration_azure_resources.tftest.hcl similarity index 53% rename from tests/remote/integration_azure_resources_all.tftest.hcl rename to tests/integration_azure_resources.tftest.hcl index 7ddcfd86..6bb1b48e 100644 --- a/tests/remote/integration_azure_resources_all.tftest.hcl +++ b/tests/integration_azure_resources.tftest.hcl @@ -20,7 +20,7 @@ variables { run "resource_integration_azure_create_with_all_fields" { module { - source = "./integration_azure_resources" + source = "./opslevel_modules/modules/integration/azure_resources" } assert { @@ -106,14 +106,15 @@ run "resource_integration_azure_create_with_all_fields" { } -run "resource_integration_azure_unset_ownership_tag_keys" { +run "resource_integration_azure_unset_optional_fields" { variables { ownership_tag_keys = null + ownership_tag_overrides = null } module { - source = "./integration_azure_resources" + source = "./opslevel_modules/modules/integration/azure_resources" } assert { @@ -125,25 +126,137 @@ run "resource_integration_azure_unset_ownership_tag_keys" { ) } + assert { + condition = opslevel_integration_azure_resources.this.ownership_tag_overrides == var.default_ownership_tag_overrides + error_message = format( + "expected default '%v' but got '%v'", + var.default_ownership_tag_overrides, + opslevel_integration_azure_resources.this.ownership_tag_overrides, + ) + } + +} + +run "delete_azure_integration_outside_of_terraform" { + + variables { + resource_id = run.resource_integration_azure_create_with_all_fields.this.id + resource_type = "integration" + } + + module { + source = "./provisioner" + } } -run "resource_integration_azure_unset_ownership_tag_overrides" { +run "resource_integration_azure_create_with_required_fields" { variables { + ownership_tag_keys = null ownership_tag_overrides = null } module { - source = "./integration_azure_resources" + source = "./opslevel_modules/modules/integration/azure_resources" + } + + assert { + condition = run.resource_integration_azure_create_with_all_fields.this.id != opslevel_integration_azure_resources.this.id + error_message = format( + "expected old id '%v' to be different from new id '%v'", + run.resource_integration_azure_create_with_all_fields.this.id, + opslevel_integration_azure_resources.this.id, + ) + } + + assert { + condition = opslevel_integration_azure_resources.this.client_id == var.client_id + error_message = format( + "expected '%v' but got '%v'", + var.client_id, + opslevel_integration_azure_resources.this.client_id, + ) + } + + assert { + condition = opslevel_integration_azure_resources.this.client_secret == var.client_secret + error_message = "expected different client_secret value, not printing sensitive value" + } + + assert { + condition = opslevel_integration_azure_resources.this.name == var.name + error_message = format( + "expected '%v' but got '%v'", + var.name, + opslevel_integration_azure_resources.this.name, + ) + } + + assert { + condition = opslevel_integration_azure_resources.this.ownership_tag_keys == var.default_ownership_tag_keys + error_message = format( + "expected '%v' but got '%v'", + var.default_ownership_tag_keys, + opslevel_integration_azure_resources.this.ownership_tag_keys, + ) } assert { condition = opslevel_integration_azure_resources.this.ownership_tag_overrides == var.default_ownership_tag_overrides error_message = format( - "expected default '%v' but got '%v'", + "expected '%v' but got '%v'", var.default_ownership_tag_overrides, opslevel_integration_azure_resources.this.ownership_tag_overrides, ) } + assert { + condition = opslevel_integration_azure_resources.this.subscription_id == var.subscription_id + error_message = format( + "expected '%v' but got '%v'", + var.subscription_id, + opslevel_integration_azure_resources.this.subscription_id, + ) + } + + assert { + condition = opslevel_integration_azure_resources.this.tenant_id == var.tenant_id + error_message = format( + "expected '%v' but got '%v'", + var.tenant_id, + opslevel_integration_azure_resources.this.tenant_id, + ) + } + +} + +run "resource_integration_azure_set_all_fields" { + + variables { + ownership_tag_keys = ["one", "two", "three", "four", "five"] + ownership_tag_overrides = false + } + + module { + source = "./opslevel_modules/modules/integration/azure_resources" + } + + assert { + condition = opslevel_integration_azure_resources.this.ownership_tag_keys == var.ownership_tag_keys + error_message = format( + "expected default '%v' but got '%v'", + var.ownership_tag_keys, + opslevel_integration_azure_resources.this.ownership_tag_keys, + ) + } + + assert { + condition = opslevel_integration_azure_resources.this.ownership_tag_overrides == var.ownership_tag_overrides + error_message = format( + "expected default '%v' but got '%v'", + var.ownership_tag_overrides, + opslevel_integration_azure_resources.this.ownership_tag_overrides, + ) + } + } diff --git a/tests/remote/integration_google_cloud_all.tftest.hcl b/tests/integration_google_cloud.tftest.hcl similarity index 59% rename from tests/remote/integration_google_cloud_all.tftest.hcl rename to tests/integration_google_cloud.tftest.hcl index 3fa498b9..e90cec08 100644 --- a/tests/remote/integration_google_cloud_all.tftest.hcl +++ b/tests/integration_google_cloud.tftest.hcl @@ -18,7 +18,7 @@ variables { run "resource_integration_google_cloud_create_with_all_fields" { module { - source = "./integration_google_cloud" + source = "./opslevel_modules/modules/integration/google_cloud" } assert { @@ -85,14 +85,15 @@ run "resource_integration_google_cloud_create_with_all_fields" { } -run "resource_integration_google_cloud_unset_ownership_tag_keys" { +run "resource_integration_google_cloud_unset_optional_fields" { variables { ownership_tag_keys = null + ownership_tag_overrides = null } module { - source = "./integration_google_cloud" + source = "./opslevel_modules/modules/integration/google_cloud" } assert { @@ -104,16 +105,56 @@ run "resource_integration_google_cloud_unset_ownership_tag_keys" { ) } + assert { + condition = opslevel_integration_google_cloud.this.ownership_tag_overrides == var.default_ownership_tag_overrides + error_message = format( + "expected default '%v' but got '%v'", + var.default_ownership_tag_overrides, + opslevel_integration_google_cloud.this.ownership_tag_overrides, + ) + } + } -run "resource_integration_google_cloud_unset_ownership_tag_overrides" { +run "delete_google_cloud_integration_outside_of_terraform" { variables { + resource_id = run.resource_integration_google_cloud_create_with_all_fields.this.id + resource_type = "integration" + } + + module { + source = "./provisioner" + } +} + +run "resource_integration_google_cloud_create_with_required_fields" { + + variables { + ownership_tag_keys = null ownership_tag_overrides = null } module { - source = "./integration_google_cloud" + source = "./opslevel_modules/modules/integration/google_cloud" + } + + assert { + condition = run.resource_integration_google_cloud_create_with_all_fields.this.id != opslevel_integration_google_cloud.this.id + error_message = format( + "expected old id '%v' to be different from new id '%v'", + run.resource_integration_google_cloud_create_with_all_fields.this.id, + opslevel_integration_google_cloud.this.id, + ) + } + + assert { + condition = opslevel_integration_google_cloud.this.ownership_tag_keys == var.default_ownership_tag_keys + error_message = format( + "expected default '%v' but got '%v'", + var.default_ownership_tag_keys, + opslevel_integration_google_cloud.this.ownership_tag_keys, + ) } assert { @@ -126,3 +167,29 @@ run "resource_integration_google_cloud_unset_ownership_tag_overrides" { } } + +run "resource_integration_google_cloud_set_all_fields" { + + module { + source = "./opslevel_modules/modules/integration/google_cloud" + } + + assert { + condition = opslevel_integration_google_cloud.this.ownership_tag_keys == var.ownership_tag_keys + error_message = format( + "expected '%v' but got '%v'", + var.ownership_tag_keys, + opslevel_integration_google_cloud.this.ownership_tag_keys, + ) + } + + assert { + condition = opslevel_integration_google_cloud.this.ownership_tag_overrides == var.ownership_tag_overrides + error_message = format( + "expected '%v' but got '%v'", + var.ownership_tag_overrides, + opslevel_integration_google_cloud.this.ownership_tag_overrides, + ) + } + +} diff --git a/tests/opslevel_modules b/tests/opslevel_modules index 37985513..00d9d278 160000 --- a/tests/opslevel_modules +++ b/tests/opslevel_modules @@ -1 +1 @@ -Subproject commit 379855133ab2b4c7ece41fda63e2e5c822370226 +Subproject commit 00d9d278a38387ed526536617626291d1849a714 diff --git a/tests/remote/integration_aws/main.tf b/tests/remote/integration_aws/main.tf deleted file mode 100644 index 7ee85bef..00000000 --- a/tests/remote/integration_aws/main.tf +++ /dev/null @@ -1,8 +0,0 @@ -resource "opslevel_integration_aws" "this" { - name = var.name - iam_role = var.iam_role - external_id = var.external_id - ownership_tag_overrides = var.ownership_tag_overrides - ownership_tag_keys = var.ownership_tag_keys - region_override = var.region_override -} diff --git a/tests/remote/integration_aws/variables.tf b/tests/remote/integration_aws/variables.tf deleted file mode 100644 index 3b06d05e..00000000 --- a/tests/remote/integration_aws/variables.tf +++ /dev/null @@ -1,32 +0,0 @@ -variable "external_id" { - type = string - description = "The External ID defined in the trust relationship to ensure OpsLevel is the only third party assuming this role (See https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-user_externalid.html for more details)." -} - -variable "iam_role" { - type = string - description = "The IAM role OpsLevel uses in order to access the AWS account." -} - -variable "ownership_tag_keys" { - type = list(string) - description = "An Array of tag keys used to associate ownership from an integration. Max 5" - default = null -} - -variable "ownership_tag_overrides" { - type = bool - description = "Allow tags imported from AWS to override ownership set in OpsLevel directly." - default = null -} - -variable "name" { - type = string - description = "The name of the integration." -} - -variable "region_override" { - type = list(string) - description = "Overrides the AWS region(s) that will be synchronized by this integration." - default = null -} diff --git a/tests/remote/integration_aws_all.tftest.hcl b/tests/remote/integration_aws_all.tftest.hcl deleted file mode 100644 index 61579c86..00000000 --- a/tests/remote/integration_aws_all.tftest.hcl +++ /dev/null @@ -1,156 +0,0 @@ -variables { - resource_name = "opslevel_integration_aws" - - # required fields - external_id = "194c7dfc-3a3f-4b0a-b898-578ce7e8f6dc" - iam_role = "arn:aws:iam::994866125780:user/opslevel-test" - name = "TF Test AWS Integration" - - # optional fields - ownership_tag_overrides = false - ownership_tag_keys = ["one", "two", "three", "four", "five"] - region_override = ["eu-west-1", "us-east-1"] - - # default values - computed from API - default_ownership_tag_keys = tolist(["owner"]) - default_ownership_tag_overrides = true -} - -run "resource_integration_aws_create_with_all_fields" { - - module { - source = "./integration_aws" - } - - assert { - condition = alltrue([ - can(opslevel_integration_aws.this.external_id), - can(opslevel_integration_aws.this.iam_role), - can(opslevel_integration_aws.this.id), - can(opslevel_integration_aws.this.ownership_tag_keys), - can(opslevel_integration_aws.this.ownership_tag_overrides), - can(opslevel_integration_aws.this.name), - can(opslevel_integration_aws.this.region_override), - ]) - error_message = replace(var.error_unexpected_resource_fields, "TYPE", var.resource_name) - } - - assert { - condition = opslevel_integration_aws.this.external_id == var.external_id - error_message = format( - "expected '%v' but got '%v'", - var.external_id, - opslevel_integration_aws.this.external_id, - ) - } - - assert { - condition = opslevel_integration_aws.this.iam_role == var.iam_role - error_message = format( - "expected '%v' but got '%v'", - var.iam_role, - opslevel_integration_aws.this.iam_role, - ) - } - - assert { - condition = startswith(opslevel_integration_aws.this.id, var.id_prefix) - error_message = replace(var.error_wrong_id, "TYPE", var.resource_name) - } - - assert { - condition = opslevel_integration_aws.this.name == var.name - error_message = format( - "expected '%v' but got '%v'", - var.name, - opslevel_integration_aws.this.name, - ) - } - - assert { - condition = opslevel_integration_aws.this.ownership_tag_keys == var.ownership_tag_keys - error_message = format( - "expected '%v' but got '%v'", - var.ownership_tag_keys, - opslevel_integration_aws.this.ownership_tag_keys, - ) - } - - assert { - condition = opslevel_integration_aws.this.ownership_tag_overrides == var.ownership_tag_overrides - error_message = format( - "expected '%v' but got '%v'", - var.ownership_tag_overrides, - opslevel_integration_aws.this.ownership_tag_overrides, - ) - } - - assert { - condition = opslevel_integration_aws.this.region_override == var.region_override - error_message = format( - "expected '%v' but got '%v'", - var.region_override, - opslevel_integration_aws.this.region_override, - ) - } - -} - -run "resource_integration_aws_unset_ownership_tag_keys" { - - variables { - ownership_tag_keys = null - } - - module { - source = "./integration_aws" - } - - assert { - condition = opslevel_integration_aws.this.ownership_tag_keys == var.default_ownership_tag_keys - error_message = format( - "expected default '%v' but got '%v'", - var.default_ownership_tag_keys, - opslevel_integration_aws.this.ownership_tag_keys, - ) - } - -} - -run "resource_integration_aws_unset_ownership_tag_overrides" { - - variables { - ownership_tag_overrides = null - } - - module { - source = "./integration_aws" - } - - assert { - condition = opslevel_integration_aws.this.ownership_tag_overrides == var.default_ownership_tag_overrides - error_message = format( - "expected default '%v' but got '%v'", - var.default_ownership_tag_overrides, - opslevel_integration_aws.this.ownership_tag_overrides, - ) - } - -} - -run "resource_integration_aws_unset_region_override" { - - variables { - region_override = null - } - - module { - source = "./integration_aws" - } - - assert { - condition = opslevel_integration_aws.this.region_override == null - error_message = var.error_expected_null_field - } - -} diff --git a/tests/remote/integration_aws_min.tftest.hcl b/tests/remote/integration_aws_min.tftest.hcl deleted file mode 100644 index 5afa096f..00000000 --- a/tests/remote/integration_aws_min.tftest.hcl +++ /dev/null @@ -1,144 +0,0 @@ -variables { - resource_name = "opslevel_integration_aws" - - # required fields - external_id = "194c7dfc-3a3f-4b0a-b898-578ce7e8f6dc" - iam_role = "arn:aws:iam::994866125780:user/opslevel-test" - name = "TF Test AWS Integration" - - # optional fields - ownership_tag_overrides = null - ownership_tag_keys = null - region_override = null - - # default values - computed from API - default_ownership_tag_keys = tolist(["owner"]) - default_ownership_tag_overrides = true -} - -run "resource_integration_aws_create_with_required_fields" { - - module { - source = "./integration_aws" - } - - assert { - condition = opslevel_integration_aws.this.external_id == var.external_id - error_message = format( - "expected '%v' but got '%v'", - var.external_id, - opslevel_integration_aws.this.external_id, - ) - } - - assert { - condition = opslevel_integration_aws.this.iam_role == var.iam_role - error_message = format( - "expected '%v' but got '%v'", - var.iam_role, - opslevel_integration_aws.this.iam_role, - ) - } - - assert { - condition = startswith(opslevel_integration_aws.this.id, var.id_prefix) - error_message = replace(var.error_wrong_id, "TYPE", var.resource_name) - } - - assert { - condition = opslevel_integration_aws.this.name == var.name - error_message = format( - "expected '%v' but got '%v'", - var.name, - opslevel_integration_aws.this.name, - ) - } - - assert { - condition = opslevel_integration_aws.this.ownership_tag_keys == var.default_ownership_tag_keys - error_message = format( - "expected '%v' but got '%v'", - var.default_ownership_tag_keys, - opslevel_integration_aws.this.ownership_tag_keys, - ) - } - - assert { - condition = opslevel_integration_aws.this.ownership_tag_overrides == var.default_ownership_tag_overrides - error_message = format( - "expected '%v' but got '%v'", - var.default_ownership_tag_overrides, - opslevel_integration_aws.this.ownership_tag_overrides, - ) - } - - assert { - condition = opslevel_integration_aws.this.region_override == null - error_message = var.error_expected_null_field - } - -} - -run "resource_integration_aws_set_ownership_tag_keys" { - - variables { - ownership_tag_keys = ["owner", "team"] - } - - module { - source = "./integration_aws" - } - - assert { - condition = opslevel_integration_aws.this.ownership_tag_keys == var.ownership_tag_keys - error_message = format( - "expected default '%v' but got '%v'", - var.ownership_tag_keys, - opslevel_integration_aws.this.ownership_tag_keys, - ) - } - -} - -run "resource_integration_aws_set_ownership_tag_overrides" { - - variables { - ownership_tag_overrides = false - } - - module { - source = "./integration_aws" - } - - assert { - condition = opslevel_integration_aws.this.ownership_tag_overrides == var.ownership_tag_overrides - error_message = format( - "expected default '%v' but got '%v'", - var.ownership_tag_overrides, - opslevel_integration_aws.this.ownership_tag_overrides, - ) - } - -} - - -run "resource_integration_aws_set_region_override" { - - variables { - region_override = ["eu-west-1", "us-east-1"] - } - - module { - source = "./integration_aws" - } - - assert { - condition = opslevel_integration_aws.this.region_override == var.region_override - error_message = format( - "expected '%v' but got '%v'", - var.region_override, - opslevel_integration_aws.this.region_override, - ) - } - -} diff --git a/tests/remote/integration_azure_resources/main.tf b/tests/remote/integration_azure_resources/main.tf deleted file mode 100644 index cb3c905e..00000000 --- a/tests/remote/integration_azure_resources/main.tf +++ /dev/null @@ -1,10 +0,0 @@ -resource "opslevel_integration_azure_resources" "this" { - client_id = var.client_id - client_secret = var.client_secret - name = var.name - ownership_tag_keys = var.ownership_tag_keys - ownership_tag_overrides = var.ownership_tag_overrides - subscription_id = var.subscription_id - tenant_id = var.tenant_id -} - diff --git a/tests/remote/integration_azure_resources/variables.tf b/tests/remote/integration_azure_resources/variables.tf deleted file mode 100644 index 8266a067..00000000 --- a/tests/remote/integration_azure_resources/variables.tf +++ /dev/null @@ -1,37 +0,0 @@ -variable "client_id" { - type = string - description = "The client id OpsLevel uses to access the Azure account." -} - -variable "client_secret" { - type = string - sensitive = true - description = "The client secret OpsLevel uses to access the Azure account." -} - -variable "name" { - type = string - description = "The name of the integration." -} - -variable "ownership_tag_keys" { - type = list(string) - description = "An Array of tag keys used to associate ownership from an integration. Max 5" - default = null -} - -variable "ownership_tag_overrides" { - type = bool - description = "Allow tags imported from AWS to override ownership set in OpsLevel directly." -} - -variable "subscription_id" { - type = string - description = "The subscription OpsLevel uses to access the Azure account." -} - -variable "tenant_id" { - type = string - description = "The tenant OpsLevel uses to access the Azure account." -} - diff --git a/tests/remote/integration_azure_resources_min.tftest.hcl b/tests/remote/integration_azure_resources_min.tftest.hcl deleted file mode 100644 index 2daa7a72..00000000 --- a/tests/remote/integration_azure_resources_min.tftest.hcl +++ /dev/null @@ -1,133 +0,0 @@ -variables { - resource_name = "opslevel_integration_azure_resources" - - # required fields - client_id = "XXX_CLIENT_ID_XXX" - client_secret = "XXX_CLIENT_SECRET_XXX" - name = "TF Test azure_resources Integration" - subscription_id = "01234567-0123-0123-0123-012345678901" - tenant_id = "98765432-9876-9876-9876-987654321098" - - # optional fields - ownership_tag_keys = null - ownership_tag_overrides = null - - # default values - computed from API - default_ownership_tag_keys = tolist(["owner"]) - default_ownership_tag_overrides = true -} - -run "resource_integration_azure_create_with_required_fields" { - - module { - source = "./integration_azure_resources" - } - - assert { - condition = opslevel_integration_azure_resources.this.client_id == var.client_id - error_message = format( - "expected '%v' but got '%v'", - var.client_id, - opslevel_integration_azure_resources.this.client_id, - ) - } - - assert { - condition = opslevel_integration_azure_resources.this.client_secret == var.client_secret - error_message = "expected different client_secret value, not printing sensitive value" - } - - assert { - condition = startswith(opslevel_integration_azure_resources.this.id, var.id_prefix) - error_message = replace(var.error_wrong_id, "TYPE", var.resource_name) - } - - assert { - condition = opslevel_integration_azure_resources.this.name == var.name - error_message = format( - "expected '%v' but got '%v'", - var.name, - opslevel_integration_azure_resources.this.name, - ) - } - - assert { - condition = opslevel_integration_azure_resources.this.ownership_tag_keys == var.default_ownership_tag_keys - error_message = format( - "expected '%v' but got '%v'", - var.default_ownership_tag_keys, - opslevel_integration_azure_resources.this.ownership_tag_keys, - ) - } - - assert { - condition = opslevel_integration_azure_resources.this.ownership_tag_overrides == var.default_ownership_tag_overrides - error_message = format( - "expected '%v' but got '%v'", - var.default_ownership_tag_overrides, - opslevel_integration_azure_resources.this.ownership_tag_overrides, - ) - } - - assert { - condition = opslevel_integration_azure_resources.this.subscription_id == var.subscription_id - error_message = format( - "expected '%v' but got '%v'", - var.subscription_id, - opslevel_integration_azure_resources.this.subscription_id, - ) - } - - assert { - condition = opslevel_integration_azure_resources.this.tenant_id == var.tenant_id - error_message = format( - "expected '%v' but got '%v'", - var.tenant_id, - opslevel_integration_azure_resources.this.tenant_id, - ) - } - -} - -run "resource_integration_azure_set_ownership_tag_keys" { - - variables { - ownership_tag_keys = ["one", "two", "three", "four", "five"] - } - - module { - source = "./integration_azure_resources" - } - - assert { - condition = opslevel_integration_azure_resources.this.ownership_tag_keys == var.default_ownership_tag_keys - error_message = format( - "expected default '%v' but got '%v'", - var.default_ownership_tag_keys, - opslevel_integration_azure_resources.this.ownership_tag_keys, - ) - } - -} - -run "resource_integration_azure_set_ownership_tag_overrides" { - - variables { - ownership_tag_overrides = false - } - - module { - source = "./integration_azure_resources" - } - - assert { - condition = opslevel_integration_azure_resources.this.ownership_tag_overrides == var.default_ownership_tag_overrides - error_message = format( - "expected default '%v' but got '%v'", - var.default_ownership_tag_overrides, - opslevel_integration_azure_resources.this.ownership_tag_overrides, - ) - } - -} - diff --git a/tests/remote/integration_google_cloud/main.tf b/tests/remote/integration_google_cloud/main.tf deleted file mode 100644 index d204950c..00000000 --- a/tests/remote/integration_google_cloud/main.tf +++ /dev/null @@ -1,7 +0,0 @@ -resource "opslevel_integration_google_cloud" "this" { - client_email = var.client_email - name = var.name - ownership_tag_keys = var.ownership_tag_keys - ownership_tag_overrides = var.ownership_tag_overrides - private_key = var.private_key -} diff --git a/tests/remote/integration_google_cloud/outputs.tf b/tests/remote/integration_google_cloud/outputs.tf deleted file mode 100644 index 233b55b5..00000000 --- a/tests/remote/integration_google_cloud/outputs.tf +++ /dev/null @@ -1,5 +0,0 @@ -output "test" { - value = opslevel_integration_google_cloud.this - sensitive = true -} - diff --git a/tests/remote/integration_google_cloud/variables.tf b/tests/remote/integration_google_cloud/variables.tf deleted file mode 100644 index 9c16ee94..00000000 --- a/tests/remote/integration_google_cloud/variables.tf +++ /dev/null @@ -1,27 +0,0 @@ -variable "client_email" { - type = string - description = "The service account email OpsLevel uses to access the Google Cloud account." -} - -variable "name" { - type = string - description = "The name of the integration." -} - -variable "ownership_tag_keys" { - type = list(string) - description = "An Array of tag keys used to associate ownership from an integration. Max 5 (default = [\"owner\"])" - default = null -} - -variable "ownership_tag_overrides" { - type = bool - description = "Allow tags imported from Google Cloud to override ownership set in OpsLevel directly. (default = true)" - default = null -} - -variable "private_key" { - type = string - sensitive = true - description = "The private key for the service account that OpsLevel uses to access the Google Cloud account." -} diff --git a/tests/remote/integration_google_cloud_min.tftest.hcl b/tests/remote/integration_google_cloud_min.tftest.hcl deleted file mode 100644 index c63df3c9..00000000 --- a/tests/remote/integration_google_cloud_min.tftest.hcl +++ /dev/null @@ -1,112 +0,0 @@ -variables { - resource_name = "opslevel_integration_google_cloud" - - # required fields - client_email = "hello-world-tf@powerful-surf-427415-v1.iam.gserviceaccount.com" - name = "abc123" - private_key = "Xx_super_secret_xX" - - # optional fields - ownership_tag_keys = null - ownership_tag_overrides = null - - # default values - computed from API - default_ownership_tag_keys = tolist(["owner"]) - default_ownership_tag_overrides = true -} - -run "resource_integration_google_cloud_create_with_required_fields" { - - module { - source = "./integration_google_cloud" - } - - assert { - condition = opslevel_integration_google_cloud.this.client_email == var.client_email - error_message = format( - "expected '%v' but got '%v'", - var.client_email, - opslevel_integration_google_cloud.this.client_email, - ) - } - - assert { - condition = startswith(opslevel_integration_google_cloud.this.id, var.id_prefix) - error_message = replace(var.error_wrong_id, "TYPE", var.resource_name) - } - - assert { - condition = opslevel_integration_google_cloud.this.name == var.name - error_message = format( - "expected '%v' but got '%v'", - var.name, - opslevel_integration_google_cloud.this.name, - ) - } - - assert { - condition = opslevel_integration_google_cloud.this.ownership_tag_keys == var.default_ownership_tag_keys - error_message = format( - "expected default '%v' but got '%v'", - var.default_ownership_tag_keys, - opslevel_integration_google_cloud.this.ownership_tag_keys, - ) - } - - assert { - condition = opslevel_integration_google_cloud.this.ownership_tag_overrides == var.default_ownership_tag_overrides - error_message = format( - "expected default '%v' but got '%v'", - var.default_ownership_tag_overrides, - opslevel_integration_google_cloud.this.ownership_tag_overrides, - ) - } - - assert { - condition = opslevel_integration_google_cloud.this.private_key == var.private_key - error_message = "expected different private_key value, not printing sensitive value" - } - -} - -run "resource_integration_google_cloud_set_ownership_tag_keys" { - - variables { - ownership_tag_keys = ["owner", "team"] - } - - module { - source = "./integration_google_cloud" - } - - assert { - condition = opslevel_integration_google_cloud.this.ownership_tag_keys == var.ownership_tag_keys - error_message = format( - "expected '%v' but got '%v'", - var.ownership_tag_keys, - opslevel_integration_google_cloud.this.ownership_tag_keys, - ) - } - -} - -run "resource_integration_google_cloud_set_ownership_tag_overrides" { - - variables { - ownership_tag_overrides = false - } - - module { - source = "./integration_google_cloud" - } - - assert { - condition = opslevel_integration_google_cloud.this.ownership_tag_overrides == var.ownership_tag_overrides - error_message = format( - "expected '%v' but got '%v'", - var.ownership_tag_overrides, - opslevel_integration_google_cloud.this.ownership_tag_overrides, - ) - } - -}