From 016ab4c9efb58dbd6816ca09b4a2bf864c9debf2 Mon Sep 17 00:00:00 2001 From: Tomer Heber Date: Wed, 19 Apr 2023 07:46:34 -0500 Subject: [PATCH] Fix: terratag inconsistent behaviour with the google-beta provider (#173) * Fix: terratag inconsistent behaviour with the google-beta provider * added test and fixed bug * additional fixes * fixed 0.12.x issues * change order to remove warnings * change order to remove warnings --- .github/workflows/ci.yml | 30 ++------ .github/workflows/release.yml | 10 +-- internal/tfschema/tfschema.go | 38 +++++++++- test/fixture/terraform_12/config.yaml | 2 +- test/fixture/terraform_13_14/config.yaml | 3 +- test/fixture/terraform_15/config.yaml | 3 +- test/fixture/terraform_latest/config.yaml | 3 +- .../aws_tags_map_11/expected/main.terratag.tf | 31 -------- .../aws_tags_map_11/expected/main.tf.bak | 39 ---------- test/tests/aws_tags_map_11/input/main.tf | 39 ---------- .../expected/main.terratag.tf | 73 ------------------- .../expected/main.tf.bak | 68 ----------------- .../input/main.tf | 68 ----------------- .../expected/main.terratag.tf | 21 ------ .../azurerm_tags_map_11/expected/main.tf.bak | 17 ----- test/tests/azurerm_tags_map_11/input/main.tf | 18 ----- .../expected/main.terratag.tf | 29 -------- .../expected/main.tf.bak | 25 ------- .../azurestack_tags_map_11/input/main.tf | 25 ------- .../expected/main.terratag.tf | 66 ----------------- .../expected/main.tf.bak | 62 ---------------- .../google_container_cluster_11/input/main.tf | 62 ---------------- .../expected/main.terratag.tf | 26 ------- .../google_labels_map_11/expected/main.tf.bak | 23 ------ test/tests/google_labels_map_11/input/main.tf | 23 ------ .../google_vs_google_beta/expected/main.tf | 49 +++++++++++++ .../tests/google_vs_google_beta/input/main.tf | 43 +++++++++++ 27 files changed, 143 insertions(+), 753 deletions(-) delete mode 100644 test/tests/aws_tags_map_11/expected/main.terratag.tf delete mode 100644 test/tests/aws_tags_map_11/expected/main.tf.bak delete mode 100644 test/tests/aws_tags_map_11/input/main.tf delete mode 100644 test/tests/azurerm_kubernetes_cluster_11/expected/main.terratag.tf delete mode 100644 test/tests/azurerm_kubernetes_cluster_11/expected/main.tf.bak delete mode 100644 test/tests/azurerm_kubernetes_cluster_11/input/main.tf delete mode 100644 test/tests/azurerm_tags_map_11/expected/main.terratag.tf delete mode 100644 test/tests/azurerm_tags_map_11/expected/main.tf.bak delete mode 100644 test/tests/azurerm_tags_map_11/input/main.tf delete mode 100644 test/tests/azurestack_tags_map_11/expected/main.terratag.tf delete mode 100644 test/tests/azurestack_tags_map_11/expected/main.tf.bak delete mode 100644 test/tests/azurestack_tags_map_11/input/main.tf delete mode 100644 test/tests/google_container_cluster_11/expected/main.terratag.tf delete mode 100644 test/tests/google_container_cluster_11/expected/main.tf.bak delete mode 100644 test/tests/google_container_cluster_11/input/main.tf delete mode 100644 test/tests/google_labels_map_11/expected/main.terratag.tf delete mode 100644 test/tests/google_labels_map_11/expected/main.tf.bak delete mode 100644 test/tests/google_labels_map_11/input/main.tf create mode 100644 test/tests/google_vs_google_beta/expected/main.tf create mode 100644 test/tests/google_vs_google_beta/input/main.tf diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d62fd24b..4f7b39ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,12 +10,12 @@ jobs: timeout-minutes: 10 runs-on: ubuntu-20.04 steps: + - name: Checkout code + uses: actions/checkout@v3 - name: Install Go uses: actions/setup-go@v4 with: go-version: 1.19 - - name: Checkout code - uses: actions/checkout@v3 - name: Go fmt run: | ! go fmt ./... | read @@ -23,9 +23,9 @@ jobs: run: | ! go vet ./... | read - name: Go staticcheck - uses: dominikh/staticcheck-action@v1.2.0 + uses: dominikh/staticcheck-action@v1.3.0 with: - version: "2022.1" + version: "2023.1.3" install-go: false - name: Go Test run: SKIP_INTEGRATION_TESTS=1 go test -v ./... @@ -39,34 +39,28 @@ jobs: terraform_version: ['12','13','14','15','latest'] steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v3 - name: Set up Go uses: actions/setup-go@v4 with: go-version: 1.19 id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v3 - - name: Get dependencies run: | go mod tidy - - name: Install tfenv run: | git clone https://github.com/tfutils/tfenv.git $GITHUB_WORKSPACE/.tfenv echo "$GITHUB_WORKSPACE/.tfenv/bin" >> $GITHUB_PATH - - name: Install terraform working-directory: test/tfenvconf/terraform_${{ matrix.terraform_version }} run: | tfenv install tfenv use - - name: Print Terraform version run: | terraform --version - - name: Set Test-Suite id: test-suite env: @@ -87,39 +81,31 @@ jobs: terragrunt-integration-tests: name: Terragrunt Integration Tests runs-on: ubuntu-latest - steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v3 - name: Set up Go uses: actions/setup-go@v4 with: go-version: 1.19 id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v3 - - name: Get dependencies run: | go mod tidy - - name: Install Terraform uses: hashicorp/setup-terraform@v2 with: terraform_version: 1.2.5 - - name: Print Terraform version run: | terraform --version - - name: Install Terragrunt uses: autero1/action-terragrunt@v1.3.1 with: terragrunt_version: 0.38.5 - - name: Print Terragrunt version run: | terragrunt --version - - name: Test run: | go test -v -run ^TestTerragruntWithCache$ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 797de51d..6a044665 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,24 +32,20 @@ jobs: runs-on: ubuntu-latest needs: goreleaser steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v3 - name: Set up Go 1.19 uses: actions/setup-go@v4 with: go-version: 1.19 id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v3 - - name: Get dependencies run: | go get -v -t -d ./... - - name: Build project run: | mkdir out CGO_ENABLED=0 go build -ldflags "-X main.version=${{github.ref_name}}" -a -installsuffix cgo -o ./out/terratag/terratag ./cmd/terratag - # Setup .npmrc file to publish to GitHub Packages - name: Setup Node uses: actions/setup-node@v3 @@ -57,14 +53,12 @@ jobs: node-version: '12.x' registry-url: 'https://registry.npmjs.org' scope: '@env0' - - run: | npm init --yes --scope @env0 ref=${{ github.ref }} tag=\"${ref#"refs/tags/v"}\" echo "`jq .version="${tag}" package.json`" > package.json working-directory: ./out/terratag - - run: npm publish --access public ./out/terratag env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/internal/tfschema/tfschema.go b/internal/tfschema/tfschema.go index 820d5d51..c99b3d99 100644 --- a/internal/tfschema/tfschema.go +++ b/internal/tfschema/tfschema.go @@ -17,6 +17,7 @@ import ( "github.com/env0/terratag/internal/providers" "github.com/env0/terratag/internal/tagging" "github.com/env0/terratag/internal/terraform" + "github.com/thoas/go-funk" "github.com/hashicorp/hcl/v2/hclwrite" "github.com/zclconf/go-cty/cty" @@ -27,7 +28,7 @@ var ErrResourceTypeNotFound = errors.New("resource type not found") var providerSchemasMap map[string]*ProviderSchemas = map[string]*ProviderSchemas{} var providerSchemasMapLock sync.Mutex -//var customSupportedProviderNames = [...]string{"google-beta"} +var customSupportedProviderNames = [...]string{"google-beta"} type Attribute struct { Type cty.Type `json:"type"` @@ -58,7 +59,7 @@ func IsTaggable(dir string, iacType common.IACType, resource hclwrite.Block) (bo resourceType := terraform.GetResourceType(resource) if providers.IsSupportedResource(resourceType) { - resourceSchema, err := getResourceSchema(resourceType, dir, iacType) + resourceSchema, err := getResourceSchema(resourceType, resource, dir, iacType) if err != nil { if err == ErrResourceTypeNotFound { log.Print("[WARN] Skipped ", resourceType, " as it is not YET supported") @@ -109,7 +110,29 @@ func getTerragruntPluginPath(dir string) string { return ret } -func getResourceSchema(resourceType string, dir string, iacType common.IACType) (*ResourceSchema, error) { +func extractProviderNameFromResourceType(resourceType string) (string, error) { + s := strings.SplitN(resourceType, "_", 2) + if len(s) < 2 { + return "", fmt.Errorf("failed to detect a provider name: %s", resourceType) + } + return s[0], nil +} + +func detectProviderName(resource hclwrite.Block) (string, error) { + providerAttribute := resource.Body().GetAttribute("provider") + + if providerAttribute != nil { + providerTokens := providerAttribute.Expr().BuildTokens(hclwrite.Tokens{}) + providerName := strings.Trim(string(providerTokens.Bytes()), "\" ") + if funk.Contains(customSupportedProviderNames, providerName) { + return providerName, nil + } + } + + return extractProviderNameFromResourceType(terraform.GetResourceType(resource)) +} + +func getResourceSchema(resourceType string, resource hclwrite.Block, dir string, iacType common.IACType) (*ResourceSchema, error) { if iacType == common.Terragrunt { // which mode of terragrunt it is (with or without cache folder). if _, err := os.Stat(dir + "/.terragrunt-cache"); err == nil { @@ -150,7 +173,14 @@ func getResourceSchema(resourceType string, dir string, iacType common.IACType) providerSchemasMap[dir] = providerSchemas } - for _, providerSchema := range providerSchemas.ProviderSchemas { + detectedProviderName, _ := detectProviderName(resource) + // Search through all providers. + for providerName, providerSchema := range providerSchemas.ProviderSchemas { + if len(detectedProviderName) > 0 && providerName != detectedProviderName && !strings.HasSuffix(providerName, "/"+detectedProviderName) { + // Not the correct provider (based on name). Skip. + continue + } + resourceSchema, ok := providerSchema.ResourceSchemas[resourceType] if ok { return resourceSchema, nil diff --git a/test/fixture/terraform_12/config.yaml b/test/fixture/terraform_12/config.yaml index 890eed3a..27427e35 100644 --- a/test/fixture/terraform_12/config.yaml +++ b/test/fixture/terraform_12/config.yaml @@ -11,4 +11,4 @@ suites: - git_issue_66_aws_aliased_provider - git_issue_88__corrupt_hcl_file - google_beta_resource_skip - \ No newline at end of file + - google_vs_google_beta \ No newline at end of file diff --git a/test/fixture/terraform_13_14/config.yaml b/test/fixture/terraform_13_14/config.yaml index 11e24dea..3579a674 100644 --- a/test/fixture/terraform_13_14/config.yaml +++ b/test/fixture/terraform_13_14/config.yaml @@ -13,4 +13,5 @@ suites: - git_issue_88__corrupt_hcl_file - google_beta_resource_skip - google_container_cluster - - google_labels_map \ No newline at end of file + - google_labels_map + - google_vs_google_beta \ No newline at end of file diff --git a/test/fixture/terraform_15/config.yaml b/test/fixture/terraform_15/config.yaml index 0f691617..818259a5 100644 --- a/test/fixture/terraform_15/config.yaml +++ b/test/fixture/terraform_15/config.yaml @@ -14,4 +14,5 @@ suites: - git_issue_88__corrupt_hcl_file - google_beta_resource_skip - google_container_cluster - - google_labels_map \ No newline at end of file + - google_labels_map + - google_vs_google_beta \ No newline at end of file diff --git a/test/fixture/terraform_latest/config.yaml b/test/fixture/terraform_latest/config.yaml index 0f691617..818259a5 100644 --- a/test/fixture/terraform_latest/config.yaml +++ b/test/fixture/terraform_latest/config.yaml @@ -14,4 +14,5 @@ suites: - git_issue_88__corrupt_hcl_file - google_beta_resource_skip - google_container_cluster - - google_labels_map \ No newline at end of file + - google_labels_map + - google_vs_google_beta \ No newline at end of file diff --git a/test/tests/aws_tags_map_11/expected/main.terratag.tf b/test/tests/aws_tags_map_11/expected/main.terratag.tf deleted file mode 100644 index 0cfbf328..00000000 --- a/test/tests/aws_tags_map_11/expected/main.terratag.tf +++ /dev/null @@ -1,31 +0,0 @@ -provider "aws" { - version = "~> 2.0" - region = "us-east-1" -} - -resource "aws_s3_bucket" "b" { - bucket = "my-tf-test-bucket" - acl = "private" - - tags = "${merge(map("Name", "Mybucket", "Unquoted1", "Iwannabequoted", "AnotherName", "Yo", "Unquoted2", "Ireallywannabequoted", "Unquoted3", "IreallyreallywannabequotedandIgotacomma", "${max(1, 2)}", "Testfunction", "${local.localTagKey}", "Testexpression", "${local.localTagKey2}", "Testvariableaskey", "Yo-${local.localTagKey}", "Testvariableinsidekey", "Testvariableasvalue", "${local.localTagKey}", "Testvariableinsidevalue", "Yo-${local.localTagKey}"), local.terratag_added_main)}" -} - -resource "aws_s3_bucket" "a" { - bucket = "my-another-tf-test-bucket" - acl = "private" - - tags = "${merge("${local.localMap}", local.terratag_added_main)}" -} - - -locals { - localTagKey = "localTagKey" - localTagKey2 = "localTagKey2" - localMap = { - key = "value" - } -} -locals { - terratag_added_main = {"env0_environment_id"="40907eff-cf7c-419a-8694-e1c6bf1d1168","env0_project_id"="43fd4ff1-8d37-4d9d-ac97-295bd850bf94"} -} - diff --git a/test/tests/aws_tags_map_11/expected/main.tf.bak b/test/tests/aws_tags_map_11/expected/main.tf.bak deleted file mode 100644 index a824d9d3..00000000 --- a/test/tests/aws_tags_map_11/expected/main.tf.bak +++ /dev/null @@ -1,39 +0,0 @@ -provider "aws" { - version = "~> 2.0" - region = "us-east-1" -} - -resource "aws_s3_bucket" "b" { - bucket = "my-tf-test-bucket" - acl = "private" - - tags = { - "Name" = "My bucket" - Unquoted1 = "I wanna be quoted" - "AnotherName" = "Yo" - Unquoted2 = "I really wanna be quoted" - Unquoted3 = "I really really wanna be quoted and I got a comma", - "${max(1, 2)}" = "Test function" - "${local.localTagKey}" = "Test expression" - "${local.localTagKey2}" = "Test variable as key" - "Yo-${local.localTagKey}" = "Test variable inside key" - "Test variable as value" = "${local.localTagKey}" - "Test variable inside value" = "Yo-${local.localTagKey}" - } -} - -resource "aws_s3_bucket" "a" { - bucket = "my-another-tf-test-bucket" - acl = "private" - - tags = "${local.localMap}" -} - - -locals { - localTagKey = "localTagKey" - localTagKey2 = "localTagKey2" - localMap = { - key = "value" - } -} \ No newline at end of file diff --git a/test/tests/aws_tags_map_11/input/main.tf b/test/tests/aws_tags_map_11/input/main.tf deleted file mode 100644 index a824d9d3..00000000 --- a/test/tests/aws_tags_map_11/input/main.tf +++ /dev/null @@ -1,39 +0,0 @@ -provider "aws" { - version = "~> 2.0" - region = "us-east-1" -} - -resource "aws_s3_bucket" "b" { - bucket = "my-tf-test-bucket" - acl = "private" - - tags = { - "Name" = "My bucket" - Unquoted1 = "I wanna be quoted" - "AnotherName" = "Yo" - Unquoted2 = "I really wanna be quoted" - Unquoted3 = "I really really wanna be quoted and I got a comma", - "${max(1, 2)}" = "Test function" - "${local.localTagKey}" = "Test expression" - "${local.localTagKey2}" = "Test variable as key" - "Yo-${local.localTagKey}" = "Test variable inside key" - "Test variable as value" = "${local.localTagKey}" - "Test variable inside value" = "Yo-${local.localTagKey}" - } -} - -resource "aws_s3_bucket" "a" { - bucket = "my-another-tf-test-bucket" - acl = "private" - - tags = "${local.localMap}" -} - - -locals { - localTagKey = "localTagKey" - localTagKey2 = "localTagKey2" - localMap = { - key = "value" - } -} \ No newline at end of file diff --git a/test/tests/azurerm_kubernetes_cluster_11/expected/main.terratag.tf b/test/tests/azurerm_kubernetes_cluster_11/expected/main.terratag.tf deleted file mode 100644 index 2de4b975..00000000 --- a/test/tests/azurerm_kubernetes_cluster_11/expected/main.terratag.tf +++ /dev/null @@ -1,73 +0,0 @@ -provider "azurerm" { - version = "~>2.0" - features {} -} - -resource "azurerm_resource_group" "non_existing_tags_rg" { - name = "non_existing_tags_rg" - location = "northeurope" - tags = "${local.terratag_added_main}" -} - -resource "azurerm_kubernetes_cluster" "non_existing_tags_cluster" { - name = "non_existing_tags_cluster" - location = "${azurerm_resource_group.non_existing_tags_rg.location}" - resource_group_name = "${azurerm_resource_group.non_existing_tags_rg.name}" - dns_prefix = "test" - - service_principal { - client_id = "id" - client_secret = "secret" - } - - default_node_pool { - name = "pool" - node_count = 2 - vm_size = "Standard_D2_v2" - tags = "${local.terratag_added_main}" - } - - network_profile { - load_balancer_sku = "Standard" - network_plugin = "kubenet" - } - - tags = "${local.terratag_added_main}" -} - -resource "azurerm_resource_group" "existing_tags_rg" { - name = "existing_tags_rg" - location = "northeurope" - tags = "${local.terratag_added_main}" -} - -resource "azurerm_kubernetes_cluster" "existing_tags_cluster" { - name = "existing_tags_cluster" - location = "${azurerm_resource_group.existing_tags_rg.location}" - resource_group_name = "${azurerm_resource_group.existing_tags_rg.name}" - dns_prefix = "test" - - service_principal { - client_id = "id" - client_secret = "secret" - } - - default_node_pool { - name = "pool" - node_count = 2 - vm_size = "Standard_D2_v2" - tags = "${merge(map("existing", "tag"), local.terratag_added_main)}" - } - - network_profile { - load_balancer_sku = "Standard" - network_plugin = "kubenet" - } - - tags = "${merge(map("existing", "tag"), local.terratag_added_main)}" -} - -locals { - terratag_added_main = {"env0_environment_id"="40907eff-cf7c-419a-8694-e1c6bf1d1168","env0_project_id"="43fd4ff1-8d37-4d9d-ac97-295bd850bf94"} -} - diff --git a/test/tests/azurerm_kubernetes_cluster_11/expected/main.tf.bak b/test/tests/azurerm_kubernetes_cluster_11/expected/main.tf.bak deleted file mode 100644 index f0b6a8de..00000000 --- a/test/tests/azurerm_kubernetes_cluster_11/expected/main.tf.bak +++ /dev/null @@ -1,68 +0,0 @@ -provider "azurerm" { - version = "~>2.0" - features {} -} - -resource "azurerm_resource_group" "non_existing_tags_rg" { - name = "non_existing_tags_rg" - location = "northeurope" -} - -resource "azurerm_kubernetes_cluster" "non_existing_tags_cluster" { - name = "non_existing_tags_cluster" - location = "${azurerm_resource_group.non_existing_tags_rg.location}" - resource_group_name = "${azurerm_resource_group.non_existing_tags_rg.name}" - dns_prefix = "test" - - service_principal { - client_id = "id" - client_secret = "secret" - } - - default_node_pool { - name = "pool" - node_count = 2 - vm_size = "Standard_D2_v2" - } - - network_profile { - load_balancer_sku = "Standard" - network_plugin = "kubenet" - } - -} - -resource "azurerm_resource_group" "existing_tags_rg" { - name = "existing_tags_rg" - location = "northeurope" -} - -resource "azurerm_kubernetes_cluster" "existing_tags_cluster" { - name = "existing_tags_cluster" - location = "${azurerm_resource_group.existing_tags_rg.location}" - resource_group_name = "${azurerm_resource_group.existing_tags_rg.name}" - dns_prefix = "test" - - service_principal { - client_id = "id" - client_secret = "secret" - } - - default_node_pool { - name = "pool" - node_count = 2 - vm_size = "Standard_D2_v2" - tags = { - existing = "tag" - } - } - - network_profile { - load_balancer_sku = "Standard" - network_plugin = "kubenet" - } - - tags = { - existing = "tag" - } -} diff --git a/test/tests/azurerm_kubernetes_cluster_11/input/main.tf b/test/tests/azurerm_kubernetes_cluster_11/input/main.tf deleted file mode 100644 index f0b6a8de..00000000 --- a/test/tests/azurerm_kubernetes_cluster_11/input/main.tf +++ /dev/null @@ -1,68 +0,0 @@ -provider "azurerm" { - version = "~>2.0" - features {} -} - -resource "azurerm_resource_group" "non_existing_tags_rg" { - name = "non_existing_tags_rg" - location = "northeurope" -} - -resource "azurerm_kubernetes_cluster" "non_existing_tags_cluster" { - name = "non_existing_tags_cluster" - location = "${azurerm_resource_group.non_existing_tags_rg.location}" - resource_group_name = "${azurerm_resource_group.non_existing_tags_rg.name}" - dns_prefix = "test" - - service_principal { - client_id = "id" - client_secret = "secret" - } - - default_node_pool { - name = "pool" - node_count = 2 - vm_size = "Standard_D2_v2" - } - - network_profile { - load_balancer_sku = "Standard" - network_plugin = "kubenet" - } - -} - -resource "azurerm_resource_group" "existing_tags_rg" { - name = "existing_tags_rg" - location = "northeurope" -} - -resource "azurerm_kubernetes_cluster" "existing_tags_cluster" { - name = "existing_tags_cluster" - location = "${azurerm_resource_group.existing_tags_rg.location}" - resource_group_name = "${azurerm_resource_group.existing_tags_rg.name}" - dns_prefix = "test" - - service_principal { - client_id = "id" - client_secret = "secret" - } - - default_node_pool { - name = "pool" - node_count = 2 - vm_size = "Standard_D2_v2" - tags = { - existing = "tag" - } - } - - network_profile { - load_balancer_sku = "Standard" - network_plugin = "kubenet" - } - - tags = { - existing = "tag" - } -} diff --git a/test/tests/azurerm_tags_map_11/expected/main.terratag.tf b/test/tests/azurerm_tags_map_11/expected/main.terratag.tf deleted file mode 100644 index c00e0c83..00000000 --- a/test/tests/azurerm_tags_map_11/expected/main.terratag.tf +++ /dev/null @@ -1,21 +0,0 @@ -provider "azurerm" { - features {} -} - -resource "azurerm_resource_group" "example" { - name = "example-resources" - location = "West Europe" - tags = "${merge(map("oh", "my"), local.terratag_added_main)}" -} - -resource "azurerm_virtual_network" "example" { - name = "example-network" - resource_group_name = "${azurerm_resource_group.example.name}" - location = "${azurerm_resource_group.example.location}" - address_space = ["10.0.0.0/16"] - tags = "${local.terratag_added_main}" -} -locals { - terratag_added_main = {"env0_environment_id"="40907eff-cf7c-419a-8694-e1c6bf1d1168","env0_project_id"="43fd4ff1-8d37-4d9d-ac97-295bd850bf94"} -} - diff --git a/test/tests/azurerm_tags_map_11/expected/main.tf.bak b/test/tests/azurerm_tags_map_11/expected/main.tf.bak deleted file mode 100644 index 3ef693f9..00000000 --- a/test/tests/azurerm_tags_map_11/expected/main.tf.bak +++ /dev/null @@ -1,17 +0,0 @@ -provider "azurerm" { -} - -resource "azurerm_resource_group" "example" { - name = "example-resources" - location = "West Europe" - tags = { - "oh" = "my" - } -} - -resource "azurerm_virtual_network" "example" { - name = "example-network" - resource_group_name = "${azurerm_resource_group.example.name}" - location = "${azurerm_resource_group.example.location}" - address_space = ["10.0.0.0/16"] -} \ No newline at end of file diff --git a/test/tests/azurerm_tags_map_11/input/main.tf b/test/tests/azurerm_tags_map_11/input/main.tf deleted file mode 100644 index 780e78c2..00000000 --- a/test/tests/azurerm_tags_map_11/input/main.tf +++ /dev/null @@ -1,18 +0,0 @@ -provider "azurerm" { - features {} -} - -resource "azurerm_resource_group" "example" { - name = "example-resources" - location = "West Europe" - tags = { - "oh" = "my" - } -} - -resource "azurerm_virtual_network" "example" { - name = "example-network" - resource_group_name = "${azurerm_resource_group.example.name}" - location = "${azurerm_resource_group.example.location}" - address_space = ["10.0.0.0/16"] -} \ No newline at end of file diff --git a/test/tests/azurestack_tags_map_11/expected/main.terratag.tf b/test/tests/azurestack_tags_map_11/expected/main.terratag.tf deleted file mode 100644 index f149783c..00000000 --- a/test/tests/azurestack_tags_map_11/expected/main.terratag.tf +++ /dev/null @@ -1,29 +0,0 @@ -provider "azurestack" { -} - -resource "azurestack_resource_group" "test" { - name = "production" - location = "West US" - tags = "${local.terratag_added_main}" -} - -resource "azurestack_virtual_network" "test" { - name = "production-network" - address_space = ["10.0.0.0/16"] - location = "${azurestack_resource_group.test.location}" - resource_group_name = "${azurestack_resource_group.test.name}" - - tags = "${local.terratag_added_main}" -} - -resource "azurestack_virtual_network" "test2" { - name = "production-network" - address_space = ["10.0.0.0/16"] - location = "${azurestack_resource_group.test.location}" - resource_group_name = "${azurestack_resource_group.test.name}" - tags = "${merge(map("yo", "ho"), local.terratag_added_main)}" -} -locals { - terratag_added_main = {"env0_environment_id"="40907eff-cf7c-419a-8694-e1c6bf1d1168","env0_project_id"="43fd4ff1-8d37-4d9d-ac97-295bd850bf94"} -} - diff --git a/test/tests/azurestack_tags_map_11/expected/main.tf.bak b/test/tests/azurestack_tags_map_11/expected/main.tf.bak deleted file mode 100644 index 0bb677d7..00000000 --- a/test/tests/azurestack_tags_map_11/expected/main.tf.bak +++ /dev/null @@ -1,25 +0,0 @@ -provider "azurestack" { -} - -resource "azurestack_resource_group" "test" { - name = "production" - location = "West US" -} - -resource "azurestack_virtual_network" "test" { - name = "production-network" - address_space = ["10.0.0.0/16"] - location = "${azurestack_resource_group.test.location}" - resource_group_name = "${azurestack_resource_group.test.name}" - -} - -resource "azurestack_virtual_network" "test2" { - name = "production-network" - address_space = ["10.0.0.0/16"] - location = "${azurestack_resource_group.test.location}" - resource_group_name = "${azurestack_resource_group.test.name}" - tags = { - "yo" = "ho" - } -} \ No newline at end of file diff --git a/test/tests/azurestack_tags_map_11/input/main.tf b/test/tests/azurestack_tags_map_11/input/main.tf deleted file mode 100644 index 0bb677d7..00000000 --- a/test/tests/azurestack_tags_map_11/input/main.tf +++ /dev/null @@ -1,25 +0,0 @@ -provider "azurestack" { -} - -resource "azurestack_resource_group" "test" { - name = "production" - location = "West US" -} - -resource "azurestack_virtual_network" "test" { - name = "production-network" - address_space = ["10.0.0.0/16"] - location = "${azurestack_resource_group.test.location}" - resource_group_name = "${azurestack_resource_group.test.name}" - -} - -resource "azurestack_virtual_network" "test2" { - name = "production-network" - address_space = ["10.0.0.0/16"] - location = "${azurestack_resource_group.test.location}" - resource_group_name = "${azurestack_resource_group.test.name}" - tags = { - "yo" = "ho" - } -} \ No newline at end of file diff --git a/test/tests/google_container_cluster_11/expected/main.terratag.tf b/test/tests/google_container_cluster_11/expected/main.terratag.tf deleted file mode 100644 index 9f4eb3b2..00000000 --- a/test/tests/google_container_cluster_11/expected/main.terratag.tf +++ /dev/null @@ -1,66 +0,0 @@ -provider "google" { - version = "2.20.3" -} - -resource "google_container_cluster" "no-labels-cluster" { - name = "cluster" - location = "us-central1" - - node_config { - machine_type = "n1-standard-1" - } - - node_pool { - node_config { - machine_type = "n1-standard-1" - } - } - resource_labels = "${local.terratag_added_main}" -} - -resource "google_container_node_pool" "no-labels-pool" { - cluster = "${google_container_cluster.no-labels-cluster.name}" - - node_config { - machine_type = "n1-standard-1" - } -} - -resource "google_container_cluster" "existing-labels-cluster" { - name = "cluster2" - location = "us-central1" - - resource_labels = "${merge(map("foo", "bar"), local.terratag_added_main)}" - - node_config { - machine_type = "n1-standard-1" - labels = { - foo = "bar" - } - } - - node_pool { - node_config { - machine_type = "n1-standard-1" - labels = { - foo = "bar" - } - } - } -} - -resource "google_container_node_pool" "existing-labels-pool" { - cluster = "${google_container_cluster.existing-labels-cluster.name}" - - node_config { - machine_type = "n1-standard-1" - labels = { - foo = "bar" - } - } -} - -locals { - terratag_added_main = {"env0_environment_id"="40907eff-cf7c-419a-8694-e1c6bf1d1168","env0_project_id"="43fd4ff1-8d37-4d9d-ac97-295bd850bf94"} -} - diff --git a/test/tests/google_container_cluster_11/expected/main.tf.bak b/test/tests/google_container_cluster_11/expected/main.tf.bak deleted file mode 100644 index 1aad2104..00000000 --- a/test/tests/google_container_cluster_11/expected/main.tf.bak +++ /dev/null @@ -1,62 +0,0 @@ -provider "google" { - version = "2.20.3" -} - -resource "google_container_cluster" "no-labels-cluster" { - name = "cluster" - location = "us-central1" - - node_config { - machine_type = "n1-standard-1" - } - - node_pool { - node_config { - machine_type = "n1-standard-1" - } - } -} - -resource "google_container_node_pool" "no-labels-pool" { - cluster = "${google_container_cluster.no-labels-cluster.name}" - - node_config { - machine_type = "n1-standard-1" - } -} - -resource "google_container_cluster" "existing-labels-cluster" { - name = "cluster2" - location = "us-central1" - - resource_labels = { - foo = "bar" - } - - node_config { - machine_type = "n1-standard-1" - labels = { - foo = "bar" - } - } - - node_pool { - node_config { - machine_type = "n1-standard-1" - labels = { - foo = "bar" - } - } - } -} - -resource "google_container_node_pool" "existing-labels-pool" { - cluster = "${google_container_cluster.existing-labels-cluster.name}" - - node_config { - machine_type = "n1-standard-1" - labels = { - foo = "bar" - } - } -} diff --git a/test/tests/google_container_cluster_11/input/main.tf b/test/tests/google_container_cluster_11/input/main.tf deleted file mode 100644 index 1aad2104..00000000 --- a/test/tests/google_container_cluster_11/input/main.tf +++ /dev/null @@ -1,62 +0,0 @@ -provider "google" { - version = "2.20.3" -} - -resource "google_container_cluster" "no-labels-cluster" { - name = "cluster" - location = "us-central1" - - node_config { - machine_type = "n1-standard-1" - } - - node_pool { - node_config { - machine_type = "n1-standard-1" - } - } -} - -resource "google_container_node_pool" "no-labels-pool" { - cluster = "${google_container_cluster.no-labels-cluster.name}" - - node_config { - machine_type = "n1-standard-1" - } -} - -resource "google_container_cluster" "existing-labels-cluster" { - name = "cluster2" - location = "us-central1" - - resource_labels = { - foo = "bar" - } - - node_config { - machine_type = "n1-standard-1" - labels = { - foo = "bar" - } - } - - node_pool { - node_config { - machine_type = "n1-standard-1" - labels = { - foo = "bar" - } - } - } -} - -resource "google_container_node_pool" "existing-labels-pool" { - cluster = "${google_container_cluster.existing-labels-cluster.name}" - - node_config { - machine_type = "n1-standard-1" - labels = { - foo = "bar" - } - } -} diff --git a/test/tests/google_labels_map_11/expected/main.terratag.tf b/test/tests/google_labels_map_11/expected/main.terratag.tf deleted file mode 100644 index 0cfbdfe3..00000000 --- a/test/tests/google_labels_map_11/expected/main.terratag.tf +++ /dev/null @@ -1,26 +0,0 @@ -provider "google" { - version = "2.20.3" -} - -resource "google_storage_bucket" "static-site" { - name = "image-store.com" - location = "EU" - force_destroy = true - - website { - main_page_suffix = "index.html" - not_found_page = "404.html" - } - cors { - origin = ["http://image-store.com"] - method = ["GET", "HEAD", "PUT", "POST", "DELETE"] - response_header = ["*"] - max_age_seconds = 3600 - } - labels = "${merge(map("foo", "bar"), local.terratag_added_main)}" -} - -locals { - terratag_added_main = {"env0_environment_id"="40907eff-cf7c-419a-8694-e1c6bf1d1168","env0_project_id"="43fd4ff1-8d37-4d9d-ac97-295bd850bf94"} -} - diff --git a/test/tests/google_labels_map_11/expected/main.tf.bak b/test/tests/google_labels_map_11/expected/main.tf.bak deleted file mode 100644 index f15493b6..00000000 --- a/test/tests/google_labels_map_11/expected/main.tf.bak +++ /dev/null @@ -1,23 +0,0 @@ -provider "google" { - version = "2.20.3" -} - -resource "google_storage_bucket" "static-site" { - name = "image-store.com" - location = "EU" - force_destroy = true - - website { - main_page_suffix = "index.html" - not_found_page = "404.html" - } - cors { - origin = ["http://image-store.com"] - method = ["GET", "HEAD", "PUT", "POST", "DELETE"] - response_header = ["*"] - max_age_seconds = 3600 - } - labels = { - "foo" = "bar" - } -} diff --git a/test/tests/google_labels_map_11/input/main.tf b/test/tests/google_labels_map_11/input/main.tf deleted file mode 100644 index f15493b6..00000000 --- a/test/tests/google_labels_map_11/input/main.tf +++ /dev/null @@ -1,23 +0,0 @@ -provider "google" { - version = "2.20.3" -} - -resource "google_storage_bucket" "static-site" { - name = "image-store.com" - location = "EU" - force_destroy = true - - website { - main_page_suffix = "index.html" - not_found_page = "404.html" - } - cors { - origin = ["http://image-store.com"] - method = ["GET", "HEAD", "PUT", "POST", "DELETE"] - response_header = ["*"] - max_age_seconds = 3600 - } - labels = { - "foo" = "bar" - } -} diff --git a/test/tests/google_vs_google_beta/expected/main.tf b/test/tests/google_vs_google_beta/expected/main.tf new file mode 100644 index 00000000..7a74132b --- /dev/null +++ b/test/tests/google_vs_google_beta/expected/main.tf @@ -0,0 +1,49 @@ +// Google beta should be tagged. However, regular google should not be tagged. + +terraform { + required_providers { + google = { + source = "hashicorp/google" + } + google-beta = { + source = "hashicorp/google-beta" + } + } +} + +provider "google" { + project = "my-project-id" + region = "us-central1" +} + +provider "google-beta" { + project = "my-project-id" + region = "us-central1" +} + +resource "google_compute_global_address" "global_ip" { + name = "test" + address_type = "EXTERNAL" + address = "1.2.3.4" + network = null + purpose = null + prefix_length = 2 + ip_version = "IPV4" +} + +resource "google_compute_global_address" "global_ip2" { + provider = google-beta + name = "test" + address_type = "EXTERNAL" + address = "1.2.3.4" + network = null + purpose = null + prefix_length = 2 + ip_version = "IPV4" + labels = local.terratag_added_main +} + +locals { + terratag_added_main = {"env0_environment_id"="40907eff-cf7c-419a-8694-e1c6bf1d1168","env0_project_id"="43fd4ff1-8d37-4d9d-ac97-295bd850bf94"} +} + diff --git a/test/tests/google_vs_google_beta/input/main.tf b/test/tests/google_vs_google_beta/input/main.tf new file mode 100644 index 00000000..526c6c7c --- /dev/null +++ b/test/tests/google_vs_google_beta/input/main.tf @@ -0,0 +1,43 @@ +// Google beta should be tagged. However, regular google should not be tagged. + +terraform { + required_providers { + google = { + source = "hashicorp/google" + } + google-beta = { + source = "hashicorp/google-beta" + } + } +} + +provider "google" { + project = "my-project-id" + region = "us-central1" +} + +provider "google-beta" { + project = "my-project-id" + region = "us-central1" +} + +resource "google_compute_global_address" "global_ip" { + name = "test" + address_type = "EXTERNAL" + address = "1.2.3.4" + network = null + purpose = null + prefix_length = 2 + ip_version = "IPV4" +} + +resource "google_compute_global_address" "global_ip2" { + provider = google-beta + name = "test" + address_type = "EXTERNAL" + address = "1.2.3.4" + network = null + purpose = null + prefix_length = 2 + ip_version = "IPV4" +}