From 6d68b50bc84d494e399ab4d0d8965c6386f6dc02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wiktor=20Niesiob=C4=99dzki?= Date: Thu, 30 Nov 2023 17:08:49 +0000 Subject: [PATCH] Review fixes --- CONTRIBUTING.md | 19 +++++++++++++------ tests/examples_e2e/setup_module/variables.tf | 3 ++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6ba1682a..2f0f9b46 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1086,7 +1086,9 @@ Prepare following information: #### How does it work Each test case is provided by additional environment defined in [variables.tf](tests/examples/variables.tf). This simplifies writing the examples as this follows the same structure as for non-end-to-end tests, and allows multiple, independent and concurrent runs of tests. -The test environment can be provisioned automatically during the test run (which takes ~2 minutes) and destroyed at the end, when of the tests (option 1 below), which is targeting automated runs in CI/CD pipeline, or can be provisioned manually (option 2 below) to reduce test time, which might be typical use case for tests run locally. +The test environment can be provisioned automatically during the test run (which takes ~2 minutes) and destroyed at the end, when all tests finish (option 1 below), which is targeting automated runs in CI/CD pipeline, or it can be provisioned manually (option 2 below) to reduce test time, which might be typical use case for tests run locally. + +For development, to keep the feedback loop short, consider using [local sandbox](#creating-sandbox-environment-for-examples) and paste specific example in `main.tf` file. #### Option 1 - automatically provision and de-provision testing infrastructure @@ -1114,16 +1116,14 @@ pytest tests/examples_e2e #### Option 2 - Provision manually test environment and use it for tests ##### Provision manually test environment In `tests/examples_e2e/setup_module` create `terraform.tfvars` with following values: -```hcl +```tfvars billing_account = "123456-123456-123456" # billing account id to associate projects group_email = "group@example.org" # existing group within organization organization_id = "1234567890" # your organization id parent = "folders/1234567890" # folder under which test resources will be created prefix = "your-unique-prefix" # unique prefix for projects region = "europe-west4" # region to use -suffix = "1" # suffix, keep 1 for now -timestamp = "1696444185" # generate your own timestamp - will be used as a part of prefix -# tftest skip +timestamp = "1696444185" # generate your own timestamp - will be used as a part of prefix for globally unique resources ``` If you use service account impersonation, set `GOOGLE_IMPERSONATE_SERVICE_ACCOUNT` @@ -1141,9 +1141,16 @@ This will generate also `tests/examples_e2e/setup_module/e2e_tests.tfvars` for y ##### Setup your environment ```bash export TFTEST_E2E_TFVARS_PATH=`pwd`/tests/examples_e2e/setup_module/e2e_tests.tfvars # generated above -export TF_VAR_prefix="your-unique-prefix" # unique prefix for projects, no longer than 7 characters +export TFTEST_E2E_prefix="your-unique-prefix" # unique prefix for projects, no longer than 7 characters ``` +##### De-provision the environment +Once you are done with the tests, run: +```bash +(cd tests/examples_e2e/setup_module/ && terraform apply -destroy) +``` +To remove all resources created for testing and `tests/examples_e2e/setup_module/e2e_tests.tfvars` file. + #### Run tests Run tests using: ```bash diff --git a/tests/examples_e2e/setup_module/variables.tf b/tests/examples_e2e/setup_module/variables.tf index 16f110df..d5a74da9 100644 --- a/tests/examples_e2e/setup_module/variables.tf +++ b/tests/examples_e2e/setup_module/variables.tf @@ -31,7 +31,8 @@ variable "region" { type = string } variable "suffix" { - type = string + type = string + default = "0" } variable "timestamp" { type = string