From c035c9301cd084afb6a4186774fd8a1a77ea0a16 Mon Sep 17 00:00:00 2001 From: edulop Date: Wed, 3 Feb 2021 09:51:17 -0500 Subject: [PATCH 1/6] [fix] Fix Snowflake ALL modules on_future --- .github/workflows/ci.yml | 90 +++++++++---------- .gitignore | 1 + scripts/snowflake_generate_grant_all/main.go | 12 ++- .../test_generate.go | 82 +++++++++++++++-- snowflake-account-grant-all/module_test.go | 33 +++++-- snowflake-database-grant-all/main.tf.json | 2 +- snowflake-database-grant-all/module_test.go | 33 +++++-- .../main.tf.json | 2 +- .../module_test.go | 33 +++++-- .../module_test.go | 33 +++++-- snowflake-function-grant-all/main.tf.json | 2 +- snowflake-function-grant-all/module_test.go | 33 +++++-- .../module_test.go | 33 +++++-- .../main.tf.json | 2 +- .../module_test.go | 33 +++++-- snowflake-procedure-grant-all/main.tf.json | 2 +- snowflake-procedure-grant-all/module_test.go | 33 +++++-- .../module_test.go | 33 +++++-- snowflake-schema-grant-all/main.tf.json | 2 +- snowflake-schema-grant-all/module_test.go | 33 +++++-- snowflake-sequence-grant-all/module_test.go | 33 +++++-- snowflake-stage-grant-all/main.tf.json | 2 +- snowflake-stage-grant-all/module_test.go | 33 +++++-- snowflake-stream-grant-all/module_test.go | 33 +++++-- snowflake-table-grant-all/main.tf.json | 2 +- snowflake-table-grant-all/module_test.go | 33 +++++-- snowflake-view-grant-all/main.tf.json | 2 +- snowflake-view-grant-all/module_test.go | 33 +++++-- snowflake-warehouse-grant-all/module_test.go | 33 +++++-- 29 files changed, 549 insertions(+), 182 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 17019f41..9b79ac47 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,6 +26,49 @@ jobs: test: name: test ${{ matrix.module }} runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - id: filter + uses: dorny/paths-filter@v2 + with: + filters: | + module: + - '${{ matrix.module }}/**' + - if: github.event == 'push' || steps.filter.outputs.module == 'true' + uses: hashicorp/setup-terraform@v1 + with: + terraform_version: 0.12.30 + terraform_wrapper: "false" + - if: github.event == 'push' || steps.filter.outputs.module == 'true' + uses: actions/setup-go@v2 + with: + go-version: 1.14.3 + - if: github.event == 'push' || steps.filter.outputs.module == 'true' + name: Install bless provider + run: curl -s https://raw.githubusercontent.com/chanzuckerberg/terraform-provider-bless/main/download.sh | bash -s -- -b $HOME/.terraform.d/plugins/ -d + - if: github.event == 'push' || steps.filter.outputs.module == 'true' + name: Check bless provider + run: ls -al $HOME/.terraform.d/plugins/terraform-provider-bless* + - if: github.event == 'push' || steps.filter.outputs.module == 'true' + name: Install Snowflake provider + run: curl -s https://raw.githubusercontent.com/chanzuckerberg/terraform-provider-snowflake/main/download.sh | bash -s -- -b $HOME/.terraform.d/plugins/ -d + - if: github.event == 'push' || steps.filter.outputs.module == 'true' + name: Check Snowflake provider + run: ls -al $HOME/.terraform.d/plugins/terraform-provider-snowflake* + - if: github.event == 'push' || steps.filter.outputs.module == 'true' + run: aws configure set aws_access_key_id ${{ secrets.CI1_AWS_ACCESS_KEY_ID }} --profile cztack-ci-1 + - if: github.event == 'push' || steps.filter.outputs.module == 'true' + run: aws configure set aws_secret_access_key ${{ secrets.CI1_AWS_SECRET_ACCESS_KEY }} --profile cztack-ci-1 + - if: github.event == 'push' || steps.filter.outputs.module == 'true' + run: aws --profile cztack-ci-1 sts get-caller-identity + - if: github.event == 'push' || steps.filter.outputs.module == 'true' + run: aws configure set aws_access_key_id ${{ secrets.CI2_AWS_ACCESS_KEY_ID }} --profile cztack-ci-2 + - if: github.event == 'push' || steps.filter.outputs.module == 'true' + run: aws configure set aws_secret_access_key ${{ secrets.CI2_AWS_SECRET_ACCESS_KEY }} --profile cztack-ci-2 + - if: github.event == 'push' || steps.filter.outputs.module == 'true' + run: aws --profile cztack-ci-2 sts get-caller-identity + - if: github.event == 'push' || steps.filter.outputs.module == 'true' + run: make test-ci TEST=./${{ matrix.module }} strategy: fail-fast: false matrix: @@ -76,7 +119,6 @@ jobs: - aws-sns-lambda - aws-ssm-params - aws-ssm-params-writer - # - bless-ca/test - github-webhooks-to-s3 - module-template - snowflake-account-grant-all @@ -95,54 +137,10 @@ jobs: - snowflake-table-grant-all - snowflake-view-grant-all - snowflake-warehouse-grant-all - steps: - - uses: actions/checkout@v2 - - id: filter - uses: dorny/paths-filter@v2 - with: - filters: | - module: - - '${{ matrix.module }}/**' - - if: github.event == 'push' || steps.filter.outputs.module == 'true' - uses: hashicorp/setup-terraform@v1 - with: - terraform_version: 0.12.30 - terraform_wrapper: "false" - - if: github.event == 'push' || steps.filter.outputs.module == 'true' - uses: actions/setup-go@v2 - with: - go-version: 1.14.3 - - if: github.event == 'push' || steps.filter.outputs.module == 'true' - name: Install bless provider - run: curl -s https://raw.githubusercontent.com/chanzuckerberg/terraform-provider-bless/main/download.sh | bash -s -- -b $HOME/.terraform.d/plugins/ -d - - if: github.event == 'push' || steps.filter.outputs.module == 'true' - name: Check bless provider - run: ls -al $HOME/.terraform.d/plugins/terraform-provider-bless* - - if: github.event == 'push' || steps.filter.outputs.module == 'true' - name: Install Snowflake provider - run: curl -s https://raw.githubusercontent.com/chanzuckerberg/terraform-provider-snowflake/main/download.sh | bash -s -- -b $HOME/.terraform.d/plugins/ -d - - if: github.event == 'push' || steps.filter.outputs.module == 'true' - name: Check Snowflake provider - run: ls -al $HOME/.terraform.d/plugins/terraform-provider-snowflake* - - if: github.event == 'push' || steps.filter.outputs.module == 'true' - run: aws configure set aws_access_key_id ${{ secrets.CI1_AWS_ACCESS_KEY_ID }} --profile cztack-ci-1 - - if: github.event == 'push' || steps.filter.outputs.module == 'true' - run: aws configure set aws_secret_access_key ${{ secrets.CI1_AWS_SECRET_ACCESS_KEY }} --profile cztack-ci-1 - - if: github.event == 'push' || steps.filter.outputs.module == 'true' - run: aws --profile cztack-ci-1 sts get-caller-identity - - if: github.event == 'push' || steps.filter.outputs.module == 'true' - run: aws configure set aws_access_key_id ${{ secrets.CI2_AWS_ACCESS_KEY_ID }} --profile cztack-ci-2 - - if: github.event == 'push' || steps.filter.outputs.module == 'true' - run: aws configure set aws_secret_access_key ${{ secrets.CI2_AWS_SECRET_ACCESS_KEY }} --profile cztack-ci-2 - - if: github.event == 'push' || steps.filter.outputs.module == 'true' - run: aws --profile cztack-ci-2 sts get-caller-identity - - if: github.event == 'push' || steps.filter.outputs.module == 'true' - run: make test-ci TEST=./${{ matrix.module }} - timeout-minutes: 45 name: CI "on": - pull_request: + pull_request: null push: branches: - main diff --git a/.gitignore b/.gitignore index fae1f491..c81e01eb 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ bin .idea .test-data +.terraform.lock.hcl diff --git a/scripts/snowflake_generate_grant_all/main.go b/scripts/snowflake_generate_grant_all/main.go index 50808075..37696030 100644 --- a/scripts/snowflake_generate_grant_all/main.go +++ b/scripts/snowflake_generate_grant_all/main.go @@ -192,9 +192,11 @@ func generateModule(name string, grant *resources.TerraformGrantResource) ([]byt lookup(var.per_privilege_grants, each.value, %s).roles, )}`, defaultPrivType) case "shares": - resourceAll["shares"] = fmt.Sprintf(`${setunion( - var.shares, - lookup(var.per_privilege_grants, each.value, %s).shares, + resourceAll["shares"] = fmt.Sprintf(`${ + var.shares == null ? null : + setunion( + var.shares, + lookup(var.per_privilege_grants, each.value, %s).shares, )}`, defaultPrivType) default: resourceAll[elementName] = fmt.Sprintf("${var.%s}", elementName) @@ -240,7 +242,3 @@ func reverseType(s *schema.Schema) (string, error) { return "", errors.Newf("Unrecognized type %s", t.String()) } } - -func optString(s string) *string { - return &s -} diff --git a/scripts/snowflake_generate_grant_all/test_generate.go b/scripts/snowflake_generate_grant_all/test_generate.go index 8f1d08c8..892dfcc1 100644 --- a/scripts/snowflake_generate_grant_all/test_generate.go +++ b/scripts/snowflake_generate_grant_all/test_generate.go @@ -5,6 +5,7 @@ import ( "fmt" "strings" + "github.com/chanzuckerberg/go-misc/sets" "github.com/chanzuckerberg/terraform-provider-snowflake/pkg/resources" ) @@ -26,19 +27,38 @@ import ( ) const vars string = %q +const onFutureVars string = %q func TestModule(t *testing.T) { test := tftest.Test{ - // just run init, swtich to Plan or Apply when you can - Mode: tftest.Init, + Mode: tftest.Plan, Setup: func(t *testing.T) *terraform.Options { - opts := tftest.Options( - tftest.DefaultRegion, - mustJson(vars), - ) - opts.TerraformDir = "." + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(vars), + } + return opts + }, + Validate: func(t *testing.T, options *terraform.Options) {}, + } + + test.Run(t) +} +func TestModule_onFuture(t *testing.T) { + if onFutureVars == "" { + return // nothing to test, no future vars + } + test := tftest.Test{ + Mode: tftest.Plan, + Setup: func(t *testing.T) *terraform.Options { + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(onFutureVars), + } return opts }, Validate: func(t *testing.T, options *terraform.Options) {}, @@ -59,6 +79,43 @@ func mustJson(jsonData string) map[string]interface{} { ` ) +func hasOnFutureProperty(grant *resources.TerraformGrantResource) bool { + _, ok := grant.Resource.Schema["on_future"] + return ok +} + +// generateFutureVars generates vars for on_future=true tests +func generateFutureTestVars(grant *resources.TerraformGrantResource) map[string]interface{} { + vars := map[string]interface{}{} + + // no on-future so nothing to test here + if !hasOnFutureProperty(grant) { + return vars + } + + conflictsWith := sets.NewStringSet().Add(grant.Resource.Schema["on_future"].ConflictsWith...) + + vars["on_future"] = true + + for name := range grant.Resource.Schema { + // conflicts, skip + if conflictsWith.ContainsElement(name) { + continue + } + + if strings.HasSuffix(name, "_name") { + vars[name] = strings.TrimSuffix(name, "_name") + continue + } + + if name == "roles" { + vars[name] = []string{"role_a", "role_b", "role_c"} + continue + } + } + return vars +} + // generateVars currently generates vars for a basic integration test // many input variable combinations are currently missing func generateTestVars(grant *resources.TerraformGrantResource) map[string]interface{} { @@ -91,5 +148,14 @@ func generateTest(grant *resources.TerraformGrantResource) (string, error) { return "", err } - return fmt.Sprintf(testTemplate, string(data)), nil + futureData := []byte("") + if hasOnFutureProperty(grant) { + futureVars := generateFutureTestVars(grant) + futureData, err = json.Marshal(futureVars) + if err != nil { + return "", err + } + } + + return fmt.Sprintf(testTemplate, string(data), string(futureData)), nil } diff --git a/snowflake-account-grant-all/module_test.go b/snowflake-account-grant-all/module_test.go index 3ab93438..580f9dfb 100644 --- a/snowflake-account-grant-all/module_test.go +++ b/snowflake-account-grant-all/module_test.go @@ -15,19 +15,38 @@ import ( ) const vars string = "{\"roles\":[\"role_a\",\"role_b\",\"role_c\"]}" +const onFutureVars string = "" func TestModule(t *testing.T) { test := tftest.Test{ - // just run init, swtich to Plan or Apply when you can - Mode: tftest.Init, + Mode: tftest.Plan, Setup: func(t *testing.T) *terraform.Options { - opts := tftest.Options( - tftest.DefaultRegion, - mustJson(vars), - ) - opts.TerraformDir = "." + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(vars), + } + return opts + }, + Validate: func(t *testing.T, options *terraform.Options) {}, + } + + test.Run(t) +} +func TestModule_onFuture(t *testing.T) { + if onFutureVars == "" { + return // nothing to test, no future vars + } + test := tftest.Test{ + Mode: tftest.Plan, + Setup: func(t *testing.T) *terraform.Options { + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(onFutureVars), + } return opts }, Validate: func(t *testing.T, options *terraform.Options) {}, diff --git a/snowflake-database-grant-all/main.tf.json b/snowflake-database-grant-all/main.tf.json index 1634d896..c5e5a3c2 100644 --- a/snowflake-database-grant-all/main.tf.json +++ b/snowflake-database-grant-all/main.tf.json @@ -45,7 +45,7 @@ "for_each": "${toset(local.privileges)}", "privilege": "${each.value}", "roles": "${setunion(\n\t\t\t\tvar.roles,\n\t\t\t\tlookup(var.per_privilege_grants, each.value, { shares = [], roles = [] }).roles,\n\t\t\t\t)}", - "shares": "${setunion(\n\t\t\t\tvar.shares,\n\t\t\t\tlookup(var.per_privilege_grants, each.value, { shares = [], roles = [] }).shares,\n\t\t\t\t)}", + "shares": "${\n\t\t\t\tvar.shares == null ? null :\n\t\t\t\tsetunion(\n\t\t\t\t\tvar.shares,\n\t\t\t\t\tlookup(var.per_privilege_grants, each.value, { shares = [], roles = [] }).shares,\n\t\t\t\t)}", "with_grant_option": "${var.with_grant_option}" } } diff --git a/snowflake-database-grant-all/module_test.go b/snowflake-database-grant-all/module_test.go index 85bdebf6..a34c4515 100644 --- a/snowflake-database-grant-all/module_test.go +++ b/snowflake-database-grant-all/module_test.go @@ -15,19 +15,38 @@ import ( ) const vars string = "{\"database_name\":\"database\",\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"shares\":[\"share_a\",\"share_b\",\"share_c\"]}" +const onFutureVars string = "" func TestModule(t *testing.T) { test := tftest.Test{ - // just run init, swtich to Plan or Apply when you can - Mode: tftest.Init, + Mode: tftest.Plan, Setup: func(t *testing.T) *terraform.Options { - opts := tftest.Options( - tftest.DefaultRegion, - mustJson(vars), - ) - opts.TerraformDir = "." + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(vars), + } + return opts + }, + Validate: func(t *testing.T, options *terraform.Options) {}, + } + + test.Run(t) +} +func TestModule_onFuture(t *testing.T) { + if onFutureVars == "" { + return // nothing to test, no future vars + } + test := tftest.Test{ + Mode: tftest.Plan, + Setup: func(t *testing.T) *terraform.Options { + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(onFutureVars), + } return opts }, Validate: func(t *testing.T, options *terraform.Options) {}, diff --git a/snowflake-external-table-grant-all/main.tf.json b/snowflake-external-table-grant-all/main.tf.json index fae07946..6e526a29 100644 --- a/snowflake-external-table-grant-all/main.tf.json +++ b/snowflake-external-table-grant-all/main.tf.json @@ -58,7 +58,7 @@ "privilege": "${each.value}", "roles": "${setunion(\n\t\t\t\tvar.roles,\n\t\t\t\tlookup(var.per_privilege_grants, each.value, { shares = [], roles = [] }).roles,\n\t\t\t\t)}", "schema_name": "${var.schema_name}", - "shares": "${setunion(\n\t\t\t\tvar.shares,\n\t\t\t\tlookup(var.per_privilege_grants, each.value, { shares = [], roles = [] }).shares,\n\t\t\t\t)}", + "shares": "${\n\t\t\t\tvar.shares == null ? null :\n\t\t\t\tsetunion(\n\t\t\t\t\tvar.shares,\n\t\t\t\t\tlookup(var.per_privilege_grants, each.value, { shares = [], roles = [] }).shares,\n\t\t\t\t)}", "with_grant_option": "${var.with_grant_option}" } } diff --git a/snowflake-external-table-grant-all/module_test.go b/snowflake-external-table-grant-all/module_test.go index d3f888ad..9c2eb79b 100644 --- a/snowflake-external-table-grant-all/module_test.go +++ b/snowflake-external-table-grant-all/module_test.go @@ -15,19 +15,38 @@ import ( ) const vars string = "{\"database_name\":\"database\",\"external_table_name\":\"external_table\",\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"schema_name\":\"schema\",\"shares\":[\"share_a\",\"share_b\",\"share_c\"]}" +const onFutureVars string = "{\"database_name\":\"database\",\"external_table_name\":\"external_table\",\"on_future\":true,\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"schema_name\":\"schema\"}" func TestModule(t *testing.T) { test := tftest.Test{ - // just run init, swtich to Plan or Apply when you can - Mode: tftest.Init, + Mode: tftest.Plan, Setup: func(t *testing.T) *terraform.Options { - opts := tftest.Options( - tftest.DefaultRegion, - mustJson(vars), - ) - opts.TerraformDir = "." + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(vars), + } + return opts + }, + Validate: func(t *testing.T, options *terraform.Options) {}, + } + + test.Run(t) +} +func TestModule_onFuture(t *testing.T) { + if onFutureVars == "" { + return // nothing to test, no future vars + } + test := tftest.Test{ + Mode: tftest.Plan, + Setup: func(t *testing.T) *terraform.Options { + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(onFutureVars), + } return opts }, Validate: func(t *testing.T, options *terraform.Options) {}, diff --git a/snowflake-file-format-grant-all/module_test.go b/snowflake-file-format-grant-all/module_test.go index 636c998f..54bd7e2c 100644 --- a/snowflake-file-format-grant-all/module_test.go +++ b/snowflake-file-format-grant-all/module_test.go @@ -15,19 +15,38 @@ import ( ) const vars string = "{\"database_name\":\"database\",\"file_format_name\":\"file_format\",\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"schema_name\":\"schema\"}" +const onFutureVars string = "{\"database_name\":\"database\",\"file_format_name\":\"file_format\",\"on_future\":true,\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"schema_name\":\"schema\"}" func TestModule(t *testing.T) { test := tftest.Test{ - // just run init, swtich to Plan or Apply when you can - Mode: tftest.Init, + Mode: tftest.Plan, Setup: func(t *testing.T) *terraform.Options { - opts := tftest.Options( - tftest.DefaultRegion, - mustJson(vars), - ) - opts.TerraformDir = "." + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(vars), + } + return opts + }, + Validate: func(t *testing.T, options *terraform.Options) {}, + } + + test.Run(t) +} +func TestModule_onFuture(t *testing.T) { + if onFutureVars == "" { + return // nothing to test, no future vars + } + test := tftest.Test{ + Mode: tftest.Plan, + Setup: func(t *testing.T) *terraform.Options { + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(onFutureVars), + } return opts }, Validate: func(t *testing.T, options *terraform.Options) {}, diff --git a/snowflake-function-grant-all/main.tf.json b/snowflake-function-grant-all/main.tf.json index 0d8bef43..4a34dced 100644 --- a/snowflake-function-grant-all/main.tf.json +++ b/snowflake-function-grant-all/main.tf.json @@ -70,7 +70,7 @@ "return_type": "${var.return_type}", "roles": "${setunion(\n\t\t\t\tvar.roles,\n\t\t\t\tlookup(var.per_privilege_grants, each.value, { shares = [], roles = [] }).roles,\n\t\t\t\t)}", "schema_name": "${var.schema_name}", - "shares": "${setunion(\n\t\t\t\tvar.shares,\n\t\t\t\tlookup(var.per_privilege_grants, each.value, { shares = [], roles = [] }).shares,\n\t\t\t\t)}", + "shares": "${\n\t\t\t\tvar.shares == null ? null :\n\t\t\t\tsetunion(\n\t\t\t\t\tvar.shares,\n\t\t\t\t\tlookup(var.per_privilege_grants, each.value, { shares = [], roles = [] }).shares,\n\t\t\t\t)}", "with_grant_option": "${var.with_grant_option}" } } diff --git a/snowflake-function-grant-all/module_test.go b/snowflake-function-grant-all/module_test.go index 3ce17cc7..73df2331 100644 --- a/snowflake-function-grant-all/module_test.go +++ b/snowflake-function-grant-all/module_test.go @@ -15,19 +15,38 @@ import ( ) const vars string = "{\"database_name\":\"database\",\"function_name\":\"function\",\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"schema_name\":\"schema\",\"shares\":[\"share_a\",\"share_b\",\"share_c\"]}" +const onFutureVars string = "{\"database_name\":\"database\",\"function_name\":\"function\",\"on_future\":true,\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"schema_name\":\"schema\"}" func TestModule(t *testing.T) { test := tftest.Test{ - // just run init, swtich to Plan or Apply when you can - Mode: tftest.Init, + Mode: tftest.Plan, Setup: func(t *testing.T) *terraform.Options { - opts := tftest.Options( - tftest.DefaultRegion, - mustJson(vars), - ) - opts.TerraformDir = "." + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(vars), + } + return opts + }, + Validate: func(t *testing.T, options *terraform.Options) {}, + } + + test.Run(t) +} +func TestModule_onFuture(t *testing.T) { + if onFutureVars == "" { + return // nothing to test, no future vars + } + test := tftest.Test{ + Mode: tftest.Plan, + Setup: func(t *testing.T) *terraform.Options { + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(onFutureVars), + } return opts }, Validate: func(t *testing.T, options *terraform.Options) {}, diff --git a/snowflake-integration-grant-all/module_test.go b/snowflake-integration-grant-all/module_test.go index 3209722c..586edb45 100644 --- a/snowflake-integration-grant-all/module_test.go +++ b/snowflake-integration-grant-all/module_test.go @@ -15,19 +15,38 @@ import ( ) const vars string = "{\"integration_name\":\"integration\",\"roles\":[\"role_a\",\"role_b\",\"role_c\"]}" +const onFutureVars string = "" func TestModule(t *testing.T) { test := tftest.Test{ - // just run init, swtich to Plan or Apply when you can - Mode: tftest.Init, + Mode: tftest.Plan, Setup: func(t *testing.T) *terraform.Options { - opts := tftest.Options( - tftest.DefaultRegion, - mustJson(vars), - ) - opts.TerraformDir = "." + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(vars), + } + return opts + }, + Validate: func(t *testing.T, options *terraform.Options) {}, + } + + test.Run(t) +} +func TestModule_onFuture(t *testing.T) { + if onFutureVars == "" { + return // nothing to test, no future vars + } + test := tftest.Test{ + Mode: tftest.Plan, + Setup: func(t *testing.T) *terraform.Options { + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(onFutureVars), + } return opts }, Validate: func(t *testing.T, options *terraform.Options) {}, diff --git a/snowflake-materialized-view-grant-all/main.tf.json b/snowflake-materialized-view-grant-all/main.tf.json index da5acf8a..747511c1 100644 --- a/snowflake-materialized-view-grant-all/main.tf.json +++ b/snowflake-materialized-view-grant-all/main.tf.json @@ -58,7 +58,7 @@ "privilege": "${each.value}", "roles": "${setunion(\n\t\t\t\tvar.roles,\n\t\t\t\tlookup(var.per_privilege_grants, each.value, { shares = [], roles = [] }).roles,\n\t\t\t\t)}", "schema_name": "${var.schema_name}", - "shares": "${setunion(\n\t\t\t\tvar.shares,\n\t\t\t\tlookup(var.per_privilege_grants, each.value, { shares = [], roles = [] }).shares,\n\t\t\t\t)}", + "shares": "${\n\t\t\t\tvar.shares == null ? null :\n\t\t\t\tsetunion(\n\t\t\t\t\tvar.shares,\n\t\t\t\t\tlookup(var.per_privilege_grants, each.value, { shares = [], roles = [] }).shares,\n\t\t\t\t)}", "with_grant_option": "${var.with_grant_option}" } } diff --git a/snowflake-materialized-view-grant-all/module_test.go b/snowflake-materialized-view-grant-all/module_test.go index 49c81e7d..27796d4c 100644 --- a/snowflake-materialized-view-grant-all/module_test.go +++ b/snowflake-materialized-view-grant-all/module_test.go @@ -15,19 +15,38 @@ import ( ) const vars string = "{\"database_name\":\"database\",\"materialized_view_name\":\"materialized_view\",\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"schema_name\":\"schema\",\"shares\":[\"share_a\",\"share_b\",\"share_c\"]}" +const onFutureVars string = "{\"database_name\":\"database\",\"materialized_view_name\":\"materialized_view\",\"on_future\":true,\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"schema_name\":\"schema\"}" func TestModule(t *testing.T) { test := tftest.Test{ - // just run init, swtich to Plan or Apply when you can - Mode: tftest.Init, + Mode: tftest.Plan, Setup: func(t *testing.T) *terraform.Options { - opts := tftest.Options( - tftest.DefaultRegion, - mustJson(vars), - ) - opts.TerraformDir = "." + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(vars), + } + return opts + }, + Validate: func(t *testing.T, options *terraform.Options) {}, + } + + test.Run(t) +} +func TestModule_onFuture(t *testing.T) { + if onFutureVars == "" { + return // nothing to test, no future vars + } + test := tftest.Test{ + Mode: tftest.Plan, + Setup: func(t *testing.T) *terraform.Options { + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(onFutureVars), + } return opts }, Validate: func(t *testing.T, options *terraform.Options) {}, diff --git a/snowflake-procedure-grant-all/main.tf.json b/snowflake-procedure-grant-all/main.tf.json index 62d077ec..9d2e5f64 100644 --- a/snowflake-procedure-grant-all/main.tf.json +++ b/snowflake-procedure-grant-all/main.tf.json @@ -70,7 +70,7 @@ "return_type": "${var.return_type}", "roles": "${setunion(\n\t\t\t\tvar.roles,\n\t\t\t\tlookup(var.per_privilege_grants, each.value, { shares = [], roles = [] }).roles,\n\t\t\t\t)}", "schema_name": "${var.schema_name}", - "shares": "${setunion(\n\t\t\t\tvar.shares,\n\t\t\t\tlookup(var.per_privilege_grants, each.value, { shares = [], roles = [] }).shares,\n\t\t\t\t)}", + "shares": "${\n\t\t\t\tvar.shares == null ? null :\n\t\t\t\tsetunion(\n\t\t\t\t\tvar.shares,\n\t\t\t\t\tlookup(var.per_privilege_grants, each.value, { shares = [], roles = [] }).shares,\n\t\t\t\t)}", "with_grant_option": "${var.with_grant_option}" } } diff --git a/snowflake-procedure-grant-all/module_test.go b/snowflake-procedure-grant-all/module_test.go index 572614b4..b239b05d 100644 --- a/snowflake-procedure-grant-all/module_test.go +++ b/snowflake-procedure-grant-all/module_test.go @@ -15,19 +15,38 @@ import ( ) const vars string = "{\"database_name\":\"database\",\"procedure_name\":\"procedure\",\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"schema_name\":\"schema\",\"shares\":[\"share_a\",\"share_b\",\"share_c\"]}" +const onFutureVars string = "{\"database_name\":\"database\",\"on_future\":true,\"procedure_name\":\"procedure\",\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"schema_name\":\"schema\"}" func TestModule(t *testing.T) { test := tftest.Test{ - // just run init, swtich to Plan or Apply when you can - Mode: tftest.Init, + Mode: tftest.Plan, Setup: func(t *testing.T) *terraform.Options { - opts := tftest.Options( - tftest.DefaultRegion, - mustJson(vars), - ) - opts.TerraformDir = "." + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(vars), + } + return opts + }, + Validate: func(t *testing.T, options *terraform.Options) {}, + } + + test.Run(t) +} +func TestModule_onFuture(t *testing.T) { + if onFutureVars == "" { + return // nothing to test, no future vars + } + test := tftest.Test{ + Mode: tftest.Plan, + Setup: func(t *testing.T) *terraform.Options { + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(onFutureVars), + } return opts }, Validate: func(t *testing.T, options *terraform.Options) {}, diff --git a/snowflake-resource-monitor-grant-all/module_test.go b/snowflake-resource-monitor-grant-all/module_test.go index 6453a212..b4a7feb1 100644 --- a/snowflake-resource-monitor-grant-all/module_test.go +++ b/snowflake-resource-monitor-grant-all/module_test.go @@ -15,19 +15,38 @@ import ( ) const vars string = "{\"monitor_name\":\"monitor\",\"roles\":[\"role_a\",\"role_b\",\"role_c\"]}" +const onFutureVars string = "" func TestModule(t *testing.T) { test := tftest.Test{ - // just run init, swtich to Plan or Apply when you can - Mode: tftest.Init, + Mode: tftest.Plan, Setup: func(t *testing.T) *terraform.Options { - opts := tftest.Options( - tftest.DefaultRegion, - mustJson(vars), - ) - opts.TerraformDir = "." + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(vars), + } + return opts + }, + Validate: func(t *testing.T, options *terraform.Options) {}, + } + + test.Run(t) +} +func TestModule_onFuture(t *testing.T) { + if onFutureVars == "" { + return // nothing to test, no future vars + } + test := tftest.Test{ + Mode: tftest.Plan, + Setup: func(t *testing.T) *terraform.Options { + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(onFutureVars), + } return opts }, Validate: func(t *testing.T, options *terraform.Options) {}, diff --git a/snowflake-schema-grant-all/main.tf.json b/snowflake-schema-grant-all/main.tf.json index e61d3bc8..bd7865b9 100644 --- a/snowflake-schema-grant-all/main.tf.json +++ b/snowflake-schema-grant-all/main.tf.json @@ -69,7 +69,7 @@ "privilege": "${each.value}", "roles": "${setunion(\n\t\t\t\tvar.roles,\n\t\t\t\tlookup(var.per_privilege_grants, each.value, { shares = [], roles = [] }).roles,\n\t\t\t\t)}", "schema_name": "${var.schema_name}", - "shares": "${setunion(\n\t\t\t\tvar.shares,\n\t\t\t\tlookup(var.per_privilege_grants, each.value, { shares = [], roles = [] }).shares,\n\t\t\t\t)}", + "shares": "${\n\t\t\t\tvar.shares == null ? null :\n\t\t\t\tsetunion(\n\t\t\t\t\tvar.shares,\n\t\t\t\t\tlookup(var.per_privilege_grants, each.value, { shares = [], roles = [] }).shares,\n\t\t\t\t)}", "with_grant_option": "${var.with_grant_option}" } } diff --git a/snowflake-schema-grant-all/module_test.go b/snowflake-schema-grant-all/module_test.go index c6fc0f55..3c5c2ad3 100644 --- a/snowflake-schema-grant-all/module_test.go +++ b/snowflake-schema-grant-all/module_test.go @@ -15,19 +15,38 @@ import ( ) const vars string = "{\"database_name\":\"database\",\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"schema_name\":\"schema\",\"shares\":[\"share_a\",\"share_b\",\"share_c\"]}" +const onFutureVars string = "{\"database_name\":\"database\",\"on_future\":true,\"roles\":[\"role_a\",\"role_b\",\"role_c\"]}" func TestModule(t *testing.T) { test := tftest.Test{ - // just run init, swtich to Plan or Apply when you can - Mode: tftest.Init, + Mode: tftest.Plan, Setup: func(t *testing.T) *terraform.Options { - opts := tftest.Options( - tftest.DefaultRegion, - mustJson(vars), - ) - opts.TerraformDir = "." + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(vars), + } + return opts + }, + Validate: func(t *testing.T, options *terraform.Options) {}, + } + + test.Run(t) +} +func TestModule_onFuture(t *testing.T) { + if onFutureVars == "" { + return // nothing to test, no future vars + } + test := tftest.Test{ + Mode: tftest.Plan, + Setup: func(t *testing.T) *terraform.Options { + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(onFutureVars), + } return opts }, Validate: func(t *testing.T, options *terraform.Options) {}, diff --git a/snowflake-sequence-grant-all/module_test.go b/snowflake-sequence-grant-all/module_test.go index 1b5e043b..71462fe9 100644 --- a/snowflake-sequence-grant-all/module_test.go +++ b/snowflake-sequence-grant-all/module_test.go @@ -15,19 +15,38 @@ import ( ) const vars string = "{\"database_name\":\"database\",\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"schema_name\":\"schema\",\"sequence_name\":\"sequence\"}" +const onFutureVars string = "{\"database_name\":\"database\",\"on_future\":true,\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"schema_name\":\"schema\",\"sequence_name\":\"sequence\"}" func TestModule(t *testing.T) { test := tftest.Test{ - // just run init, swtich to Plan or Apply when you can - Mode: tftest.Init, + Mode: tftest.Plan, Setup: func(t *testing.T) *terraform.Options { - opts := tftest.Options( - tftest.DefaultRegion, - mustJson(vars), - ) - opts.TerraformDir = "." + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(vars), + } + return opts + }, + Validate: func(t *testing.T, options *terraform.Options) {}, + } + + test.Run(t) +} +func TestModule_onFuture(t *testing.T) { + if onFutureVars == "" { + return // nothing to test, no future vars + } + test := tftest.Test{ + Mode: tftest.Plan, + Setup: func(t *testing.T) *terraform.Options { + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(onFutureVars), + } return opts }, Validate: func(t *testing.T, options *terraform.Options) {}, diff --git a/snowflake-stage-grant-all/main.tf.json b/snowflake-stage-grant-all/main.tf.json index 3d91875d..d75f168e 100644 --- a/snowflake-stage-grant-all/main.tf.json +++ b/snowflake-stage-grant-all/main.tf.json @@ -59,7 +59,7 @@ "privilege": "${each.value}", "roles": "${setunion(\n\t\t\t\tvar.roles,\n\t\t\t\tlookup(var.per_privilege_grants, each.value, { shares = [], roles = [] }).roles,\n\t\t\t\t)}", "schema_name": "${var.schema_name}", - "shares": "${setunion(\n\t\t\t\tvar.shares,\n\t\t\t\tlookup(var.per_privilege_grants, each.value, { shares = [], roles = [] }).shares,\n\t\t\t\t)}", + "shares": "${\n\t\t\t\tvar.shares == null ? null :\n\t\t\t\tsetunion(\n\t\t\t\t\tvar.shares,\n\t\t\t\t\tlookup(var.per_privilege_grants, each.value, { shares = [], roles = [] }).shares,\n\t\t\t\t)}", "stage_name": "${var.stage_name}", "with_grant_option": "${var.with_grant_option}" } diff --git a/snowflake-stage-grant-all/module_test.go b/snowflake-stage-grant-all/module_test.go index fbc82c36..015d9582 100644 --- a/snowflake-stage-grant-all/module_test.go +++ b/snowflake-stage-grant-all/module_test.go @@ -15,19 +15,38 @@ import ( ) const vars string = "{\"database_name\":\"database\",\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"schema_name\":\"schema\",\"shares\":[\"share_a\",\"share_b\",\"share_c\"],\"stage_name\":\"stage\"}" +const onFutureVars string = "{\"database_name\":\"database\",\"on_future\":true,\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"schema_name\":\"schema\"}" func TestModule(t *testing.T) { test := tftest.Test{ - // just run init, swtich to Plan or Apply when you can - Mode: tftest.Init, + Mode: tftest.Plan, Setup: func(t *testing.T) *terraform.Options { - opts := tftest.Options( - tftest.DefaultRegion, - mustJson(vars), - ) - opts.TerraformDir = "." + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(vars), + } + return opts + }, + Validate: func(t *testing.T, options *terraform.Options) {}, + } + + test.Run(t) +} +func TestModule_onFuture(t *testing.T) { + if onFutureVars == "" { + return // nothing to test, no future vars + } + test := tftest.Test{ + Mode: tftest.Plan, + Setup: func(t *testing.T) *terraform.Options { + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(onFutureVars), + } return opts }, Validate: func(t *testing.T, options *terraform.Options) {}, diff --git a/snowflake-stream-grant-all/module_test.go b/snowflake-stream-grant-all/module_test.go index 2140875b..6277ae63 100644 --- a/snowflake-stream-grant-all/module_test.go +++ b/snowflake-stream-grant-all/module_test.go @@ -15,19 +15,38 @@ import ( ) const vars string = "{\"database_name\":\"database\",\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"schema_name\":\"schema\",\"stream_name\":\"stream\"}" +const onFutureVars string = "{\"database_name\":\"database\",\"on_future\":true,\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"schema_name\":\"schema\",\"stream_name\":\"stream\"}" func TestModule(t *testing.T) { test := tftest.Test{ - // just run init, swtich to Plan or Apply when you can - Mode: tftest.Init, + Mode: tftest.Plan, Setup: func(t *testing.T) *terraform.Options { - opts := tftest.Options( - tftest.DefaultRegion, - mustJson(vars), - ) - opts.TerraformDir = "." + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(vars), + } + return opts + }, + Validate: func(t *testing.T, options *terraform.Options) {}, + } + + test.Run(t) +} +func TestModule_onFuture(t *testing.T) { + if onFutureVars == "" { + return // nothing to test, no future vars + } + test := tftest.Test{ + Mode: tftest.Plan, + Setup: func(t *testing.T) *terraform.Options { + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(onFutureVars), + } return opts }, Validate: func(t *testing.T, options *terraform.Options) {}, diff --git a/snowflake-table-grant-all/main.tf.json b/snowflake-table-grant-all/main.tf.json index 3157a6f6..b2d8e08a 100644 --- a/snowflake-table-grant-all/main.tf.json +++ b/snowflake-table-grant-all/main.tf.json @@ -62,7 +62,7 @@ "privilege": "${each.value}", "roles": "${setunion(\n\t\t\t\tvar.roles,\n\t\t\t\tlookup(var.per_privilege_grants, each.value, { shares = [], roles = [] }).roles,\n\t\t\t\t)}", "schema_name": "${var.schema_name}", - "shares": "${setunion(\n\t\t\t\tvar.shares,\n\t\t\t\tlookup(var.per_privilege_grants, each.value, { shares = [], roles = [] }).shares,\n\t\t\t\t)}", + "shares": "${\n\t\t\t\tvar.shares == null ? null :\n\t\t\t\tsetunion(\n\t\t\t\t\tvar.shares,\n\t\t\t\t\tlookup(var.per_privilege_grants, each.value, { shares = [], roles = [] }).shares,\n\t\t\t\t)}", "table_name": "${var.table_name}", "with_grant_option": "${var.with_grant_option}" } diff --git a/snowflake-table-grant-all/module_test.go b/snowflake-table-grant-all/module_test.go index c9997669..7cd3f294 100644 --- a/snowflake-table-grant-all/module_test.go +++ b/snowflake-table-grant-all/module_test.go @@ -15,19 +15,38 @@ import ( ) const vars string = "{\"database_name\":\"database\",\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"schema_name\":\"schema\",\"shares\":[\"share_a\",\"share_b\",\"share_c\"],\"table_name\":\"table\"}" +const onFutureVars string = "{\"database_name\":\"database\",\"on_future\":true,\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"schema_name\":\"schema\"}" func TestModule(t *testing.T) { test := tftest.Test{ - // just run init, swtich to Plan or Apply when you can - Mode: tftest.Init, + Mode: tftest.Plan, Setup: func(t *testing.T) *terraform.Options { - opts := tftest.Options( - tftest.DefaultRegion, - mustJson(vars), - ) - opts.TerraformDir = "." + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(vars), + } + return opts + }, + Validate: func(t *testing.T, options *terraform.Options) {}, + } + + test.Run(t) +} +func TestModule_onFuture(t *testing.T) { + if onFutureVars == "" { + return // nothing to test, no future vars + } + test := tftest.Test{ + Mode: tftest.Plan, + Setup: func(t *testing.T) *terraform.Options { + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(onFutureVars), + } return opts }, Validate: func(t *testing.T, options *terraform.Options) {}, diff --git a/snowflake-view-grant-all/main.tf.json b/snowflake-view-grant-all/main.tf.json index 4dc8c888..766f6a96 100644 --- a/snowflake-view-grant-all/main.tf.json +++ b/snowflake-view-grant-all/main.tf.json @@ -57,7 +57,7 @@ "privilege": "${each.value}", "roles": "${setunion(\n\t\t\t\tvar.roles,\n\t\t\t\tlookup(var.per_privilege_grants, each.value, { shares = [], roles = [] }).roles,\n\t\t\t\t)}", "schema_name": "${var.schema_name}", - "shares": "${setunion(\n\t\t\t\tvar.shares,\n\t\t\t\tlookup(var.per_privilege_grants, each.value, { shares = [], roles = [] }).shares,\n\t\t\t\t)}", + "shares": "${\n\t\t\t\tvar.shares == null ? null :\n\t\t\t\tsetunion(\n\t\t\t\t\tvar.shares,\n\t\t\t\t\tlookup(var.per_privilege_grants, each.value, { shares = [], roles = [] }).shares,\n\t\t\t\t)}", "view_name": "${var.view_name}", "with_grant_option": "${var.with_grant_option}" } diff --git a/snowflake-view-grant-all/module_test.go b/snowflake-view-grant-all/module_test.go index 851c9642..3a952d5f 100644 --- a/snowflake-view-grant-all/module_test.go +++ b/snowflake-view-grant-all/module_test.go @@ -15,19 +15,38 @@ import ( ) const vars string = "{\"database_name\":\"database\",\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"schema_name\":\"schema\",\"shares\":[\"share_a\",\"share_b\",\"share_c\"],\"view_name\":\"view\"}" +const onFutureVars string = "{\"database_name\":\"database\",\"on_future\":true,\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"schema_name\":\"schema\"}" func TestModule(t *testing.T) { test := tftest.Test{ - // just run init, swtich to Plan or Apply when you can - Mode: tftest.Init, + Mode: tftest.Plan, Setup: func(t *testing.T) *terraform.Options { - opts := tftest.Options( - tftest.DefaultRegion, - mustJson(vars), - ) - opts.TerraformDir = "." + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(vars), + } + return opts + }, + Validate: func(t *testing.T, options *terraform.Options) {}, + } + + test.Run(t) +} +func TestModule_onFuture(t *testing.T) { + if onFutureVars == "" { + return // nothing to test, no future vars + } + test := tftest.Test{ + Mode: tftest.Plan, + Setup: func(t *testing.T) *terraform.Options { + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(onFutureVars), + } return opts }, Validate: func(t *testing.T, options *terraform.Options) {}, diff --git a/snowflake-warehouse-grant-all/module_test.go b/snowflake-warehouse-grant-all/module_test.go index ef7293a3..5320bb09 100644 --- a/snowflake-warehouse-grant-all/module_test.go +++ b/snowflake-warehouse-grant-all/module_test.go @@ -15,19 +15,38 @@ import ( ) const vars string = "{\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"warehouse_name\":\"warehouse\"}" +const onFutureVars string = "" func TestModule(t *testing.T) { test := tftest.Test{ - // just run init, swtich to Plan or Apply when you can - Mode: tftest.Init, + Mode: tftest.Plan, Setup: func(t *testing.T) *terraform.Options { - opts := tftest.Options( - tftest.DefaultRegion, - mustJson(vars), - ) - opts.TerraformDir = "." + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(vars), + } + return opts + }, + Validate: func(t *testing.T, options *terraform.Options) {}, + } + + test.Run(t) +} +func TestModule_onFuture(t *testing.T) { + if onFutureVars == "" { + return // nothing to test, no future vars + } + test := tftest.Test{ + Mode: tftest.Plan, + Setup: func(t *testing.T) *terraform.Options { + opts := &terraform.Options{ + TerraformDir: ".", + EnvVars: map[string]string{}, + Vars: mustJson(onFutureVars), + } return opts }, Validate: func(t *testing.T, options *terraform.Options) {}, From 0379719a433e1973dc1ad8b6f812120d1551676a Mon Sep 17 00:00:00 2001 From: edulop Date: Wed, 3 Feb 2021 10:30:06 -0500 Subject: [PATCH 2/6] fmt --- scripts/snowflake_generate_grant_all/Makefile | 1 + scripts/snowflake_generate_grant_all/test_generate.go | 8 ++++---- snowflake-account-grant-all/module_test.go | 8 ++++---- snowflake-database-grant-all/module_test.go | 8 ++++---- snowflake-external-table-grant-all/module_test.go | 8 ++++---- snowflake-file-format-grant-all/module_test.go | 8 ++++---- snowflake-function-grant-all/module_test.go | 8 ++++---- snowflake-integration-grant-all/module_test.go | 8 ++++---- snowflake-materialized-view-grant-all/module_test.go | 8 ++++---- snowflake-procedure-grant-all/module_test.go | 8 ++++---- snowflake-resource-monitor-grant-all/module_test.go | 8 ++++---- snowflake-schema-grant-all/module_test.go | 8 ++++---- snowflake-sequence-grant-all/module_test.go | 8 ++++---- snowflake-stage-grant-all/module_test.go | 8 ++++---- snowflake-stream-grant-all/module_test.go | 8 ++++---- snowflake-table-grant-all/module_test.go | 8 ++++---- snowflake-view-grant-all/module_test.go | 8 ++++---- snowflake-warehouse-grant-all/module_test.go | 8 ++++---- 18 files changed, 69 insertions(+), 68 deletions(-) diff --git a/scripts/snowflake_generate_grant_all/Makefile b/scripts/snowflake_generate_grant_all/Makefile index 5b5f2852..73a07e5b 100644 --- a/scripts/snowflake_generate_grant_all/Makefile +++ b/scripts/snowflake_generate_grant_all/Makefile @@ -1,6 +1,7 @@ run: go run . $(MAKE) -C ../.. docs + $(MAKE) -C ../.. fmt .PHONY: run update-deps: diff --git a/scripts/snowflake_generate_grant_all/test_generate.go b/scripts/snowflake_generate_grant_all/test_generate.go index 892dfcc1..17ac8356 100644 --- a/scripts/snowflake_generate_grant_all/test_generate.go +++ b/scripts/snowflake_generate_grant_all/test_generate.go @@ -36,8 +36,8 @@ func TestModule(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(vars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, @@ -56,8 +56,8 @@ func TestModule_onFuture(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(onFutureVars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, diff --git a/snowflake-account-grant-all/module_test.go b/snowflake-account-grant-all/module_test.go index 580f9dfb..71b3a373 100644 --- a/snowflake-account-grant-all/module_test.go +++ b/snowflake-account-grant-all/module_test.go @@ -24,8 +24,8 @@ func TestModule(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(vars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, @@ -44,8 +44,8 @@ func TestModule_onFuture(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(onFutureVars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, diff --git a/snowflake-database-grant-all/module_test.go b/snowflake-database-grant-all/module_test.go index a34c4515..01440c71 100644 --- a/snowflake-database-grant-all/module_test.go +++ b/snowflake-database-grant-all/module_test.go @@ -24,8 +24,8 @@ func TestModule(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(vars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, @@ -44,8 +44,8 @@ func TestModule_onFuture(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(onFutureVars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, diff --git a/snowflake-external-table-grant-all/module_test.go b/snowflake-external-table-grant-all/module_test.go index 9c2eb79b..3c36f34e 100644 --- a/snowflake-external-table-grant-all/module_test.go +++ b/snowflake-external-table-grant-all/module_test.go @@ -24,8 +24,8 @@ func TestModule(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(vars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, @@ -44,8 +44,8 @@ func TestModule_onFuture(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(onFutureVars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, diff --git a/snowflake-file-format-grant-all/module_test.go b/snowflake-file-format-grant-all/module_test.go index 54bd7e2c..c7d47760 100644 --- a/snowflake-file-format-grant-all/module_test.go +++ b/snowflake-file-format-grant-all/module_test.go @@ -24,8 +24,8 @@ func TestModule(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(vars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, @@ -44,8 +44,8 @@ func TestModule_onFuture(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(onFutureVars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, diff --git a/snowflake-function-grant-all/module_test.go b/snowflake-function-grant-all/module_test.go index 73df2331..3bf1442a 100644 --- a/snowflake-function-grant-all/module_test.go +++ b/snowflake-function-grant-all/module_test.go @@ -24,8 +24,8 @@ func TestModule(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(vars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, @@ -44,8 +44,8 @@ func TestModule_onFuture(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(onFutureVars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, diff --git a/snowflake-integration-grant-all/module_test.go b/snowflake-integration-grant-all/module_test.go index 586edb45..ddfb3c6a 100644 --- a/snowflake-integration-grant-all/module_test.go +++ b/snowflake-integration-grant-all/module_test.go @@ -24,8 +24,8 @@ func TestModule(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(vars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, @@ -44,8 +44,8 @@ func TestModule_onFuture(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(onFutureVars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, diff --git a/snowflake-materialized-view-grant-all/module_test.go b/snowflake-materialized-view-grant-all/module_test.go index 27796d4c..726a6891 100644 --- a/snowflake-materialized-view-grant-all/module_test.go +++ b/snowflake-materialized-view-grant-all/module_test.go @@ -24,8 +24,8 @@ func TestModule(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(vars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, @@ -44,8 +44,8 @@ func TestModule_onFuture(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(onFutureVars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, diff --git a/snowflake-procedure-grant-all/module_test.go b/snowflake-procedure-grant-all/module_test.go index b239b05d..3f500dd2 100644 --- a/snowflake-procedure-grant-all/module_test.go +++ b/snowflake-procedure-grant-all/module_test.go @@ -24,8 +24,8 @@ func TestModule(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(vars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, @@ -44,8 +44,8 @@ func TestModule_onFuture(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(onFutureVars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, diff --git a/snowflake-resource-monitor-grant-all/module_test.go b/snowflake-resource-monitor-grant-all/module_test.go index b4a7feb1..e7598edc 100644 --- a/snowflake-resource-monitor-grant-all/module_test.go +++ b/snowflake-resource-monitor-grant-all/module_test.go @@ -24,8 +24,8 @@ func TestModule(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(vars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, @@ -44,8 +44,8 @@ func TestModule_onFuture(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(onFutureVars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, diff --git a/snowflake-schema-grant-all/module_test.go b/snowflake-schema-grant-all/module_test.go index 3c5c2ad3..04282b82 100644 --- a/snowflake-schema-grant-all/module_test.go +++ b/snowflake-schema-grant-all/module_test.go @@ -24,8 +24,8 @@ func TestModule(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(vars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, @@ -44,8 +44,8 @@ func TestModule_onFuture(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(onFutureVars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, diff --git a/snowflake-sequence-grant-all/module_test.go b/snowflake-sequence-grant-all/module_test.go index 71462fe9..1515efe8 100644 --- a/snowflake-sequence-grant-all/module_test.go +++ b/snowflake-sequence-grant-all/module_test.go @@ -24,8 +24,8 @@ func TestModule(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(vars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, @@ -44,8 +44,8 @@ func TestModule_onFuture(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(onFutureVars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, diff --git a/snowflake-stage-grant-all/module_test.go b/snowflake-stage-grant-all/module_test.go index 015d9582..5d99fc82 100644 --- a/snowflake-stage-grant-all/module_test.go +++ b/snowflake-stage-grant-all/module_test.go @@ -24,8 +24,8 @@ func TestModule(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(vars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, @@ -44,8 +44,8 @@ func TestModule_onFuture(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(onFutureVars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, diff --git a/snowflake-stream-grant-all/module_test.go b/snowflake-stream-grant-all/module_test.go index 6277ae63..a346942c 100644 --- a/snowflake-stream-grant-all/module_test.go +++ b/snowflake-stream-grant-all/module_test.go @@ -24,8 +24,8 @@ func TestModule(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(vars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, @@ -44,8 +44,8 @@ func TestModule_onFuture(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(onFutureVars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, diff --git a/snowflake-table-grant-all/module_test.go b/snowflake-table-grant-all/module_test.go index 7cd3f294..3e2d2ad0 100644 --- a/snowflake-table-grant-all/module_test.go +++ b/snowflake-table-grant-all/module_test.go @@ -24,8 +24,8 @@ func TestModule(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(vars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, @@ -44,8 +44,8 @@ func TestModule_onFuture(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(onFutureVars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, diff --git a/snowflake-view-grant-all/module_test.go b/snowflake-view-grant-all/module_test.go index 3a952d5f..769b689e 100644 --- a/snowflake-view-grant-all/module_test.go +++ b/snowflake-view-grant-all/module_test.go @@ -24,8 +24,8 @@ func TestModule(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(vars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, @@ -44,8 +44,8 @@ func TestModule_onFuture(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(onFutureVars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, diff --git a/snowflake-warehouse-grant-all/module_test.go b/snowflake-warehouse-grant-all/module_test.go index 5320bb09..8bf4ad55 100644 --- a/snowflake-warehouse-grant-all/module_test.go +++ b/snowflake-warehouse-grant-all/module_test.go @@ -24,8 +24,8 @@ func TestModule(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(vars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, @@ -44,8 +44,8 @@ func TestModule_onFuture(t *testing.T) { Setup: func(t *testing.T) *terraform.Options { opts := &terraform.Options{ TerraformDir: ".", - EnvVars: map[string]string{}, - Vars: mustJson(onFutureVars), + EnvVars: map[string]string{}, + Vars: mustJson(vars), } return opts }, From 2bca5381d2ccd0496a0f5ee3421607e0c5b6e3af Mon Sep 17 00:00:00 2001 From: edulop Date: Wed, 3 Feb 2021 10:31:03 -0500 Subject: [PATCH 3/6] trigger TFE build From a6a37abf44c26da12d83c33a52958f12530d8c98 Mon Sep 17 00:00:00 2001 From: edulop Date: Wed, 3 Feb 2021 11:17:17 -0500 Subject: [PATCH 4/6] bump ci TF to 0.13.6 --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9b79ac47..8b8cb54d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v2 - uses: hashicorp/setup-terraform@v1 with: - terraform_version: 0.12.30 + terraform_version: 0.13.6 terraform_wrapper: "false" - name: setup run: make setup @@ -37,7 +37,7 @@ jobs: - if: github.event == 'push' || steps.filter.outputs.module == 'true' uses: hashicorp/setup-terraform@v1 with: - terraform_version: 0.12.30 + terraform_version: 0.13.6 terraform_wrapper: "false" - if: github.event == 'push' || steps.filter.outputs.module == 'true' uses: actions/setup-go@v2 From 162e35d893094c3962ce89d799dd475926a43ccc Mon Sep 17 00:00:00 2001 From: edulop Date: Wed, 3 Feb 2021 13:18:11 -0500 Subject: [PATCH 5/6] Enable Snowflake Env Vars --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8b8cb54d..6665587b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,6 +24,10 @@ jobs: name: linters run: make lint-ci test: + env: + SNOWFLAKE_ACCOUNT: ${{ secrets.SNOWFLAKE_ACCOUNT }} + SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }} + SNOWFLAKE_USER: ${{ secrets.SNOWFLAKE_USER }} name: test ${{ matrix.module }} runs-on: ubuntu-latest steps: From 4e9777cd1e156108a39a2d6630034fb4dc9bcfc2 Mon Sep 17 00:00:00 2001 From: edulop Date: Fri, 2 Apr 2021 14:01:25 -0400 Subject: [PATCH 6/6] something --- scripts/snowflake_generate_grant_all/test_generate.go | 10 ++++++++++ snowflake-function-grant-all/module_test.go | 2 +- snowflake-procedure-grant-all/module_test.go | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/snowflake_generate_grant_all/test_generate.go b/scripts/snowflake_generate_grant_all/test_generate.go index 17ac8356..03946c5f 100644 --- a/scripts/snowflake_generate_grant_all/test_generate.go +++ b/scripts/snowflake_generate_grant_all/test_generate.go @@ -112,6 +112,16 @@ func generateFutureTestVars(grant *resources.TerraformGrantResource) map[string] vars[name] = []string{"role_a", "role_b", "role_c"} continue } + + if name == "arguments" { + vars[name] = []map[string]string{ + { + "name": "foo", + "type": "STRING", + }, + } + continue + } } return vars } diff --git a/snowflake-function-grant-all/module_test.go b/snowflake-function-grant-all/module_test.go index 3bf1442a..071cdf73 100644 --- a/snowflake-function-grant-all/module_test.go +++ b/snowflake-function-grant-all/module_test.go @@ -15,7 +15,7 @@ import ( ) const vars string = "{\"database_name\":\"database\",\"function_name\":\"function\",\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"schema_name\":\"schema\",\"shares\":[\"share_a\",\"share_b\",\"share_c\"]}" -const onFutureVars string = "{\"database_name\":\"database\",\"function_name\":\"function\",\"on_future\":true,\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"schema_name\":\"schema\"}" +const onFutureVars string = "{\"arguments\":[{\"name\":\"foo\",\"type\":\"STRING\"}],\"database_name\":\"database\",\"function_name\":\"function\",\"on_future\":true,\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"schema_name\":\"schema\"}" func TestModule(t *testing.T) { test := tftest.Test{ diff --git a/snowflake-procedure-grant-all/module_test.go b/snowflake-procedure-grant-all/module_test.go index 3f500dd2..b4de7ee2 100644 --- a/snowflake-procedure-grant-all/module_test.go +++ b/snowflake-procedure-grant-all/module_test.go @@ -15,7 +15,7 @@ import ( ) const vars string = "{\"database_name\":\"database\",\"procedure_name\":\"procedure\",\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"schema_name\":\"schema\",\"shares\":[\"share_a\",\"share_b\",\"share_c\"]}" -const onFutureVars string = "{\"database_name\":\"database\",\"on_future\":true,\"procedure_name\":\"procedure\",\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"schema_name\":\"schema\"}" +const onFutureVars string = "{\"arguments\":[{\"name\":\"foo\",\"type\":\"STRING\"}],\"database_name\":\"database\",\"on_future\":true,\"procedure_name\":\"procedure\",\"roles\":[\"role_a\",\"role_b\",\"role_c\"],\"schema_name\":\"schema\"}" func TestModule(t *testing.T) { test := tftest.Test{