diff --git a/test/integration/scripts/assert-tf-generate-files-exist.sh b/test/integration/scripts/assert-tf-generate-files-exist.sh new file mode 100755 index 000000000..d56ff2ba6 --- /dev/null +++ b/test/integration/scripts/assert-tf-generate-files-exist.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +if [[ $1 == *partial_success* ]]; then + files=( + "tmp-tf-gen/auth0_import.tf" + "tmp-tf-gen/auth0_main.tf" + ) +else + files=( + "tmp-tf-gen/auth0_generated.tf" + "tmp-tf-gen/auth0_import.tf" + "tmp-tf-gen/auth0_main.tf" + "tmp-tf-gen/terraform" + "tmp-tf-gen/.terraform.lock.hcl" + ) +fi + +has_error=false + +for file in "${files[@]}"; do + if [ -e "$file" ]; then + if ! [ -s "$file" ]; then + echo "$file exists but is empty" + has_error=true + fi + else + echo "$file does not exist" + has_error=true + fi +done + +if [ "$has_error" = true ]; then + exit 1 +fi \ No newline at end of file diff --git a/test/integration/scripts/test-cleanup.sh b/test/integration/scripts/test-cleanup.sh index 3c024b34f..da5a09913 100755 --- a/test/integration/scripts/test-cleanup.sh +++ b/test/integration/scripts/test-cleanup.sh @@ -147,3 +147,5 @@ auth0 ul update --accent "#2A2E35" --background "#FF4F40" --logo "https://exampl rm -rf integration-test-app-qs rm -rf test/integration/identifiers + +rm -rdf tmp-tf-gen diff --git a/test/integration/terraform-test-cases.yaml b/test/integration/terraform-test-cases.yaml new file mode 100644 index 000000000..9eb475867 --- /dev/null +++ b/test/integration/terraform-test-cases.yaml @@ -0,0 +1,66 @@ +config: + inherit-env: true + retries: 1 + env: + AUTH0_DOMAIN: $AUTH0_CLI_CLIENT_DOMAIN + AUTH0_CLIENT_ID: $AUTH0_CLI_CLIENT_ID + AUTH0_CLIENT_SECRET: $AUTH0_CLI_CLIENT_SECRET +tests: + 001.0 - setup: + command: rm -rdf tmp-tf-gen + exit-code: 0 + 001.1 - it successfully runs for a single resource: + command: auth0 tf generate --output-dir tmp-tf-gen -r auth0_tenant + exit-code: 0 + stderr: + contains: + - "Terraform resource config files generated successfully in: tmp-tf-gen" + - Review the config and generate the terraform state by running + - cd tmp-tf-gen && ./terraform apply + - Once Terraform files are auto-generated, the terraform binary and auth0_import.tf files can be deleted. + 001.2 - it successfully generates the expected files for a single resource: + command: ./test/integration/scripts/assert-tf-generate-files-exist.sh + exit-code: 0 + 001.3 - cleanup: + command: rm -rdf tmp-tf-gen + + 002.0 - setup: + command: rm -rdf tmp-tf-gen + exit-code: 0 + 002.1 - it successfully runs for all default resources: + command: auth0 tf generate --output-dir tmp-tf-gen + exit-code: 0 + stderr: + contains: + - "Terraform resource config files generated successfully in: tmp-tf-gen" + - Review the config and generate the terraform state by running + - cd tmp-tf-gen && ./terraform apply + - Once Terraform files are auto-generated, the terraform binary and auth0_import.tf files can be deleted. + 002.2 - it successfully generates the expected files for all default resources: + command: ./test/integration/scripts/assert-tf-generate-files-exist.sh + exit-code: 0 + 002.3 - cleanup: + command: rm -rdf tmp-tf-gen + + 003.1 - it partially succeeds if Terraform credentials not provided: + command: unset AUTH0_DOMAIN && auth0 tf generate --output-dir tmp-tf-gen + exit-code: 0 + stderr: + contains: + - "Terraform provider credentials not detected" + - "Refer to following guide on how to create a dedicated Auth0 client and configure credentials: https://registry.terraform.io/providers/auth0/auth0/latest/docs/guides/quickstart" + - "After provider credentials are set, run:" + - "cd tmp-tf-gen && terraform init && terraform plan -generate-config-out=auth0_generated.tf && terraform apply" + - "Once the Terraform file is auto-generated, the auth0_import.tf file can be deleted." + 003.2 - it successfully generates the expected files for a partial success: + command: ./test/integration/scripts/assert-tf-generate-files-exist.sh partial_success + exit-code: 0 + 003.3 - cleanup: + command: rm -rdf tmp-tf-gen + + 004 - it does not run if invalid resource provided: + command: auth0 tf generate -r auth0_computer + exit-code: 1 + stderr: + contains: + - "unsupported resource type: auth0_computer"