Skip to content

Commit

Permalink
Use env vars to pass cf credentials in tests instead of janky echo mo…
Browse files Browse the repository at this point in the history
…dule
  • Loading branch information
rahearn committed Jun 18, 2024
1 parent 5ef63e1 commit 8ec0c9b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 30 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
11 changes: 2 additions & 9 deletions s3/tests/creation.tftest.hcl
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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))
Expand Down
13 changes: 0 additions & 13 deletions tf-cg-test-support/echo_cf_vars.tf

This file was deleted.

0 comments on commit 8ec0c9b

Please sign in to comment.