From 8ec0c9b27688d748386a02d952b5e146c9def84e Mon Sep 17 00:00:00 2001 From: Ryan Ahearn Date: Mon, 17 Jun 2024 22:34:33 -0400 Subject: [PATCH] Use env vars to pass cf credentials in tests instead of janky echo module --- .github/workflows/test.yml | 6 +++--- README.md | 7 ++----- s3/tests/creation.tftest.hcl | 11 ++--------- tf-cg-test-support/echo_cf_vars.tf | 13 ------------- 4 files changed, 7 insertions(+), 30 deletions(-) delete mode 100644 tf-cg-test-support/echo_cf_vars.tf diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4a746dc..e88fb02 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,8 +19,8 @@ jobs: - name: terraform test ${{ matrix.module }} uses: dflook/terraform-test@v1 + env: + CF_USER: ${{ secrets.CF_USER }} + CF_PASSWORD: ${{ secrets.CF_PASSWORD }} with: path: ${{ matrix.module }} - variables: | - cf_user = "${{ secrets.CF_USER }}" - cf_password = "${{ secrets.CF_PASSWORD }}" diff --git a/README.md b/README.md index 54950f4..376679f 100644 --- a/README.md +++ b/README.md @@ -145,10 +145,7 @@ module "egress_space" { [Terraform tests](https://developer.hashicorp.com/terraform/language/tests) are in progress of being written. To run for any module with a `tests` directory: +1. Set `CF_USER` and `CF_PASSWORD` env variables with SpaceDeployer credentials that can access the space(s) being used for tests 1. cd to module root. Example: `cd s3` 1. Run `terraform init` -1. Run `terraform test -var cf_user="SERVICE_DEPLOYER_USERNAME" -var cf_password="SERVICE_DEPLOYER_PASSWORD"` - -### tf-cg-test-support - -This module is used to help setup the cloudfoundry provider for each test. It is not a useful module on its own +1. Run `terraform test` diff --git a/s3/tests/creation.tftest.hcl b/s3/tests/creation.tftest.hcl index 0d339c3..3cc8dc0 100644 --- a/s3/tests/creation.tftest.hcl +++ b/s3/tests/creation.tftest.hcl @@ -1,7 +1,6 @@ provider "cloudfoundry" { - api_url = "https://api.fr.cloud.gov" - user = run.setup.cf_user - password = run.setup.cf_password + api_url = "https://api.fr.cloud.gov" + # cf_user and cf_password are passed in via CF_USER and CF_PASSWORD env vars } variables { @@ -11,12 +10,6 @@ variables { name = "terraform-cloudgov-s3-test" } -run "setup" { - module { - source = "../tf-cg-test-support" - } -} - run "test_creation" { assert { condition = can(regex("^\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12}$", output.bucket_id)) diff --git a/tf-cg-test-support/echo_cf_vars.tf b/tf-cg-test-support/echo_cf_vars.tf deleted file mode 100644 index 4066b28..0000000 --- a/tf-cg-test-support/echo_cf_vars.tf +++ /dev/null @@ -1,13 +0,0 @@ -variable "cf_user" {} -variable "cf_password" { - sensitive = true -} - -output "cf_user" { - value = var.cf_user -} - -output "cf_password" { - value = var.cf_password - sensitive = true -}