From d76cd0db374c3e7454e15e323578c6d5dc2fd783 Mon Sep 17 00:00:00 2001 From: Sam Levenick Date: Thu, 17 Oct 2019 10:07:40 -0700 Subject: [PATCH 01/16] Clear members if iam_binding doesn't find a binding (#2481) Merged PR #2481. --- build/terraform | 2 +- build/terraform-beta | 2 +- third_party/terraform/resources/resource_iam_binding.go.erb | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/build/terraform b/build/terraform index f058c31cf97d..22f774c05d77 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit f058c31cf97df1f2dcb04306334668ff332e0c19 +Subproject commit 22f774c05d773cb254eb6e5c2d2f6d0e5432c7a5 diff --git a/build/terraform-beta b/build/terraform-beta index 2e8d2b2075f3..c21bc1e1d76e 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit 2e8d2b2075f307751114375e1def035c89e9db6c +Subproject commit c21bc1e1d76e7426f9d2167139ad028123563c45 diff --git a/third_party/terraform/resources/resource_iam_binding.go.erb b/third_party/terraform/resources/resource_iam_binding.go.erb index b76e027f4cb0..14fb00e6f516 100644 --- a/third_party/terraform/resources/resource_iam_binding.go.erb +++ b/third_party/terraform/resources/resource_iam_binding.go.erb @@ -107,6 +107,7 @@ func resourceIamBindingRead(newUpdaterFunc newResourceIamUpdaterFunc) schema.Rea if binding == nil { log.Printf("[DEBUG]: Binding for role %q not found in policy for %s, assuming it has no members.", eBinding.Role, updater.DescribeResource()) d.Set("role", eBinding.Role) + d.Set("members", nil) return nil } else { d.Set("role", binding.Role) From ac212c3b948a080cdc1e4e709143d205a1e0ef78 Mon Sep 17 00:00:00 2001 From: Riley Karson Date: Thu, 17 Oct 2019 16:59:23 -0700 Subject: [PATCH 02/16] Correct a bad assumption about versions made in instance template (#2487) Merged PR #2487. --- build/terraform | 2 +- build/terraform-beta | 2 +- build/terraform-mapper | 2 +- .../resource_compute_instance_template.go | 12 +++----- third_party/terraform/utils/image.go | 28 ++++++++++--------- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/build/terraform b/build/terraform index 22f774c05d77..7ba8fef5fc0e 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit 22f774c05d773cb254eb6e5c2d2f6d0e5432c7a5 +Subproject commit 7ba8fef5fc0e41b9442a263d2c7716a51ef1dc20 diff --git a/build/terraform-beta b/build/terraform-beta index c21bc1e1d76e..f9c2705788ec 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit c21bc1e1d76e7426f9d2167139ad028123563c45 +Subproject commit f9c2705788ec0273a269fb149a676ca9077229e3 diff --git a/build/terraform-mapper b/build/terraform-mapper index a5b16ba9fbb0..af8ba4e287cf 160000 --- a/build/terraform-mapper +++ b/build/terraform-mapper @@ -1 +1 @@ -Subproject commit a5b16ba9fbb0853df76e12bece176aa93df56f61 +Subproject commit af8ba4e287cf4b1f5b631dc16ed7b74fb4aff136 diff --git a/third_party/terraform/resources/resource_compute_instance_template.go b/third_party/terraform/resources/resource_compute_instance_template.go index 65e8018c85f6..07607e05c143 100644 --- a/third_party/terraform/resources/resource_compute_instance_template.go +++ b/third_party/terraform/resources/resource_compute_instance_template.go @@ -514,7 +514,7 @@ func resourceComputeInstanceTemplateSourceImageCustomizeDiff(diff *schema.Resour if err != nil { return err } - oldResolved, err = resolvedImageSelfLink(project, oldResolved) + oldResolved, err = resolveImageRefToRelativeURI(project, oldResolved) if err != nil { return err } @@ -522,7 +522,7 @@ func resourceComputeInstanceTemplateSourceImageCustomizeDiff(diff *schema.Resour if err != nil { return err } - newResolved, err = resolvedImageSelfLink(project, newResolved) + newResolved, err = resolveImageRefToRelativeURI(project, newResolved) if err != nil { return err } @@ -781,13 +781,9 @@ func flattenDisk(disk *computeBeta.AttachedDisk, defaultProject string) (map[str diskMap := make(map[string]interface{}) if disk.InitializeParams != nil { if disk.InitializeParams.SourceImage != "" { - selfLink, err := resolvedImageSelfLink(defaultProject, disk.InitializeParams.SourceImage) + path, err := resolveImageRefToRelativeURI(defaultProject, disk.InitializeParams.SourceImage) if err != nil { - return nil, errwrap.Wrapf("Error expanding source image input to self_link: {{err}}", err) - } - path, err := getRelativePath(selfLink) - if err != nil { - return nil, errwrap.Wrapf("Error getting relative path for source image: {{err}}", err) + return nil, errwrap.Wrapf("Error expanding source image input to relative URI: {{err}}", err) } diskMap["source_image"] = path } else { diff --git a/third_party/terraform/utils/image.go b/third_party/terraform/utils/image.go index 6ea945c199d6..920edcbcf731 100644 --- a/third_party/terraform/utils/image.go +++ b/third_party/terraform/utils/image.go @@ -197,38 +197,40 @@ func resolveImage(c *Config, project, name string) (string, error) { return "", fmt.Errorf("Could not find image or family %s", name) } -// resolvedImageSelfLink takes the output of resolveImage and coerces it into a self_link. -// In the event that a global/images/IMAGE or global/images/family/FAMILY reference is -// returned from resolveImage, providerProject will be used as the project for the self_link. -func resolvedImageSelfLink(providerProject, name string) (string, error) { +// resolveImageRefToRelativeURI takes the output of resolveImage and coerces it +// into a relative URI. In the event that a global/images/IMAGE or +// global/images/family/FAMILY reference is returned from resolveImage, +// providerProject will be used as the project for the self_link. +func resolveImageRefToRelativeURI(providerProject, name string) (string, error) { switch { case resolveImageLink.MatchString(name): // https://www.googleapis.com/compute/v1/projects/xyz/global/images/xyz - return name, nil - case resolveImageProjectImage.MatchString(name): // projects/xyz/global/images/xyz - res := resolveImageProjectImage.FindStringSubmatch(name) - if err := sanityTestRegexMatches(2, res, "project image", name); err != nil { + namePath, err := getRelativePath(name) + if err != nil { return "", err } - return fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/global/images/%s", res[1], res[2]), nil + + return namePath, nil + case resolveImageProjectImage.MatchString(name): // projects/xyz/global/images/xyz + return name, nil case resolveImageProjectFamily.MatchString(name): // projects/xyz/global/images/family/xyz res := resolveImageProjectFamily.FindStringSubmatch(name) if err := sanityTestRegexMatches(2, res, "project family", name); err != nil { return "", err } - return fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/global/images/family/%s", res[1], res[2]), nil + return fmt.Sprintf("projects/%s/global/images/family/%s", res[1], res[2]), nil case resolveImageGlobalImage.MatchString(name): // global/images/xyz res := resolveImageGlobalImage.FindStringSubmatch(name) if err := sanityTestRegexMatches(1, res, "global image", name); err != nil { return "", err } - return fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/global/images/%s", providerProject, res[1]), nil + return fmt.Sprintf("projects/%s/global/images/%s", providerProject, res[1]), nil case resolveImageGlobalFamily.MatchString(name): // global/images/family/xyz res := resolveImageGlobalFamily.FindStringSubmatch(name) if err := sanityTestRegexMatches(1, res, "global family", name); err != nil { return "", err } - return fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/global/images/family/%s", providerProject, res[1]), nil + return fmt.Sprintf("projects/%s/global/images/family/%s", providerProject, res[1]), nil } - return "", fmt.Errorf("Could not expand image or family %q into a self_link", name) + return "", fmt.Errorf("Could not expand image or family %q into a relative URI", name) } From a85456787163e8879a32c6fa0e60864d1145a0c0 Mon Sep 17 00:00:00 2001 From: Experience Coder Date: Fri, 18 Oct 2019 13:15:53 -0400 Subject: [PATCH 03/16] Terraform AppEngine Dispatch Resource (#2466) * Dispatch URL change * Dispatch URL change * Update third_party/terraform/website-compiled/google.erb Co-Authored-By: Riley Karson * Update third_party/terraform/website-compiled/google.erb Co-Authored-By: Riley Karson * Added Sync and tested * Dispatch URL change * Update third_party/terraform/website-compiled/google.erb Co-Authored-By: Riley Karson * Update third_party/terraform/website-compiled/google.erb Co-Authored-By: Riley Karson * Added Sync and tested * Added Mutex * changed mutex and also added depend_on * Added failing Destroy one * Added failing Destroy one * Added failing Destroy one * updated custome delete * Removed custome delete * Update products/appengine/terraform.yaml Co-Authored-By: Riley Karson * Update products/appengine/api.yaml Co-Authored-By: Riley Karson * Update products/appengine/api.yaml Co-Authored-By: Riley Karson * Update templates/terraform/examples/app_engine_application_url_dispatch_rules_basic.tf.erb Co-Authored-By: Riley Karson * Update templates/terraform/examples/app_engine_application_url_dispatch_rules_basic.tf.erb Co-Authored-By: Riley Karson * Fixed custom-check-distroy file name * Update products/appengine/api.yaml Co-Authored-By: Riley Karson --- products/appengine/ansible.yaml | 2 + products/appengine/api.yaml | 57 +++++++++++++++++++ products/appengine/inspec.yaml | 2 + products/appengine/terraform.yaml | 17 +++++- ...engine_version.go.erb => appengine.go.erb} | 0 ...pplication_url_dispatch_rules_basic.tf.erb | 43 ++++++++++++++ .../terraform/website-compiled/google.erb | 3 + 7 files changed, 122 insertions(+), 2 deletions(-) rename templates/terraform/custom_check_destroy/{appengine_version.go.erb => appengine.go.erb} (100%) create mode 100644 templates/terraform/examples/app_engine_application_url_dispatch_rules_basic.tf.erb diff --git a/products/appengine/ansible.yaml b/products/appengine/ansible.yaml index 5f4928d134d7..c540de908491 100644 --- a/products/appengine/ansible.yaml +++ b/products/appengine/ansible.yaml @@ -20,6 +20,8 @@ datasources: !ruby/object:Overrides::ResourceOverrides DomainMapping: !ruby/object:Overrides::Ansible::ResourceOverride exclude: true overrides: !ruby/object:Overrides::ResourceOverrides + ApplicationUrlDispatchRules: !ruby/object:Overrides::Ansible::ResourceOverride + exclude: true FirewallRule: !ruby/object:Overrides::Ansible::ResourceOverride # Because of lack of state, Ansible treats identity # differently than Terraform. diff --git a/products/appengine/api.yaml b/products/appengine/api.yaml index 347e7819b4fb..d33bfd8087bc 100644 --- a/products/appengine/api.yaml +++ b/products/appengine/api.yaml @@ -446,3 +446,60 @@ objects: Instance class that is used to run this version. Valid values are AutomaticScaling F1, F2, F4, F4_1G (Only AutomaticScaling is supported at the moment) + - !ruby/object:Api::Resource + name: 'ApplicationUrlDispatchRules' + description: | + Rules to match an HTTP request and dispatch that request to a service. + base_url: 'apps/{{project}}' + create_url: 'apps/{{project}}?updateMask=dispatch_rules' + create_verb: :PATCH + delete_url: 'apps/{{project}}?updateMask=dispatch_rules' + delete_verb: :PATCH + update_url: 'apps/{{project}}?updateMask=dispatch_rules' + update_verb: :PATCH + references: !ruby/object:Api::Resource::ReferenceLinks + api: 'https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps#UrlDispatchRule' + async: !ruby/object:Api::Async + operation: !ruby/object:Api::Async::Operation + path: 'name' + base_url: '{{op_id}}' + wait_ms: 1000 + result: !ruby/object:Api::Async::Result + path: 'response' + status: !ruby/object:Api::Async::Status + path: 'status' + complete: 'DONE' + allowed: + - 'PENDING' + - 'RUNNING' + - 'DONE' + error: !ruby/object:Api::Async::Error + path: 'error/errors' + message: 'message' + properties: + - !ruby/object:Api::Type::Array + name: 'dispatchRules' + required: true + description: | + Rules to match an HTTP request and dispatch that request to a service. + item_type: !ruby/object:Api::Type::NestedObject + properties: + - !ruby/object:Api::Type::String + name: 'domain' + default_value: '*' + description: | + Domain name to match against. The wildcard "*" is supported if specified before a period: "*.". + Defaults to matching all domains: "*". + - !ruby/object:Api::Type::String + name: 'path' + description: | + Pathname within the host. Must start with a "/". A single "*" can be included at the end of the path. + The sum of the lengths of the domain and path may not exceed 100 characters. + required: true + - !ruby/object:Api::Type::String + name: 'service' + description: | + Pathname within the host. Must start with a "/". A single "*" can be included at the end of the path. + The sum of the lengths of the domain and path may not exceed 100 characters. + required: true + diff --git a/products/appengine/inspec.yaml b/products/appengine/inspec.yaml index 70f55cc33388..44be027a00e9 100644 --- a/products/appengine/inspec.yaml +++ b/products/appengine/inspec.yaml @@ -14,6 +14,8 @@ --- !ruby/object:Provider::Inspec::Config legacy_name: appengine overrides: !ruby/object:Overrides::ResourceOverrides + ApplicationUrlDispatchRules: !ruby/object:Overrides::Inspec::ResourceOverride + exclude: true DomainMapping: !ruby/object:Overrides::Inspec::ResourceOverride exclude: true FirewallRule: !ruby/object:Overrides::Inspec::ResourceOverride diff --git a/products/appengine/terraform.yaml b/products/appengine/terraform.yaml index 506900f045d9..2dcbb57e9843 100644 --- a/products/appengine/terraform.yaml +++ b/products/appengine/terraform.yaml @@ -27,7 +27,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides StandardAppVersion: !ruby/object:Overrides::Terraform::ResourceOverride id_format: "apps/{{project}}/services/{{service}}/versions/{{version_id}}" import_format: ["apps/{{project}}/services/{{service}}/versions/{{version_id}}"] - mutex: "apps/{{project}}/services/{{service}}" + mutex: "apps/{{project}}" parameters: service: !ruby/object:Overrides::Terraform::PropertyOverride default_from_api: true @@ -43,7 +43,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides If set to `true`, the service will be deleted if it is the last version. custom_code: !ruby/object:Provider::Terraform::CustomCode custom_delete: templates/terraform/custom_delete/appversion_delete.go.erb - test_check_destroy: templates/terraform/custom_check_destroy/appengine_version.go.erb + test_check_destroy: templates/terraform/custom_check_destroy/appengine.go.erb properties: id: !ruby/object:Overrides::Terraform::PropertyOverride name: 'version_id' @@ -93,6 +93,19 @@ overrides: !ruby/object:Overrides::ResourceOverrides update_mask_fields: - "ssl_settings.certificate_id" - "ssl_settings.ssl_management_type" + ApplicationUrlDispatchRules: !ruby/object:Overrides::Terraform::ResourceOverride + id_format: "{{project}}" + import_format: ["{{project}}"] + mutex: "apps/{{project}}" + custom_code: !ruby/object:Provider::Terraform::CustomCode + test_check_destroy: templates/terraform/custom_check_destroy/appengine.go.erb + examples: + - !ruby/object:Provider::Terraform::Examples + name: "app_engine_application_url_dispatch_rules_basic" + primary_resource_id: "service_rules" + vars: + project: "my-project" + bucket_name: "appengine-test-bucket" # This is for copying files over files: !ruby/object:Provider::Config::Files diff --git a/templates/terraform/custom_check_destroy/appengine_version.go.erb b/templates/terraform/custom_check_destroy/appengine.go.erb similarity index 100% rename from templates/terraform/custom_check_destroy/appengine_version.go.erb rename to templates/terraform/custom_check_destroy/appengine.go.erb diff --git a/templates/terraform/examples/app_engine_application_url_dispatch_rules_basic.tf.erb b/templates/terraform/examples/app_engine_application_url_dispatch_rules_basic.tf.erb new file mode 100644 index 000000000000..7fc7237b0b5c --- /dev/null +++ b/templates/terraform/examples/app_engine_application_url_dispatch_rules_basic.tf.erb @@ -0,0 +1,43 @@ +resource "google_storage_bucket" "bucket" { + name = "<%= ctx[:vars]['bucket_name'] %>" +} + +resource "google_storage_bucket_object" "object" { + name = "hello-world.zip" + bucket = "${google_storage_bucket.bucket.name}" + source = "./test-fixtures/appengine/hello-world.zip" +} + +resource "google_app_engine_standard_app_version" "myapp_v1" { + version_id = "v1" + service = "myapp" + runtime = "nodejs10" + noop_on_destroy = true + entrypoint { + shell = "node ./app.js" + } + deployment { + zip { + source_url = "https://storage.googleapis.com/${google_storage_bucket.bucket.name}/hello-world.zip" + } + } + env_variables = { + port = "8080" + } + depends_on = ["google_storage_bucket_object.object"] + +} + +resource "google_app_engine_application_url_dispatch_rules" "service_rules" { + # project = "my-project" + dispatch_rules { + domain = "*" + path = "/default/*" + service = "default" + } + dispatch_rules { + domain = "*" + path = "/myapp/*" + service = "${google_app_engine_standard_app_version.myapp_v1.service}" + } +} diff --git a/third_party/terraform/website-compiled/google.erb b/third_party/terraform/website-compiled/google.erb index b57105ae4d61..57728087c777 100644 --- a/third_party/terraform/website-compiled/google.erb +++ b/third_party/terraform/website-compiled/google.erb @@ -235,6 +235,9 @@ > google_app_engine_standard_app_version + > + google_app_engine_application_url_dispatch_rules + From 70348d62ba917201805678f4ed959e967935d501 Mon Sep 17 00:00:00 2001 From: Riley Karson Date: Fri, 18 Oct 2019 10:30:48 -0700 Subject: [PATCH 04/16] Compare relpath and not by version in compute ig (#2493) Merged PR #2493. --- build/terraform | 2 +- build/terraform-beta | 2 +- build/terraform-mapper | 2 +- .../terraform/resources/resource_compute_instance_group.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build/terraform b/build/terraform index 7ba8fef5fc0e..1ed9f43abe5a 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit 7ba8fef5fc0e41b9442a263d2c7716a51ef1dc20 +Subproject commit 1ed9f43abe5a1118143bc460594341338ffc598d diff --git a/build/terraform-beta b/build/terraform-beta index f9c2705788ec..0574383c5b92 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit f9c2705788ec0273a269fb149a676ca9077229e3 +Subproject commit 0574383c5b921b76b03bbb3a0791763f8e3155d6 diff --git a/build/terraform-mapper b/build/terraform-mapper index af8ba4e287cf..4700f1232f79 160000 --- a/build/terraform-mapper +++ b/build/terraform-mapper @@ -1 +1 @@ -Subproject commit af8ba4e287cf4b1f5b631dc16ed7b74fb4aff136 +Subproject commit 4700f1232f799d729d3422bb3e51055522ec4fb0 diff --git a/third_party/terraform/resources/resource_compute_instance_group.go b/third_party/terraform/resources/resource_compute_instance_group.go index d4f9ad3542a9..176a16a2518e 100644 --- a/third_party/terraform/resources/resource_compute_instance_group.go +++ b/third_party/terraform/resources/resource_compute_instance_group.go @@ -49,7 +49,7 @@ func resourceComputeInstanceGroup() *schema.Resource { Optional: true, Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, - Set: schema.HashString, + Set: selfLinkRelativePathHash, }, "named_port": { From 72c6dd8a5c9eb65ad769e7996f26c0b244cb4b84 Mon Sep 17 00:00:00 2001 From: Nathan McKinley Date: Fri, 18 Oct 2019 10:55:41 -0700 Subject: [PATCH 05/16] Fix some TF diff issues in MM 3.0.0 branch. (#2491) Merged PR #2491. --- .ci/ci.yml.tmpl | 4 ++-- .ci/magic-modules/diff-terraform.sh | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.ci/ci.yml.tmpl b/.ci/ci.yml.tmpl index 0c09f3c37a1f..de645d661533 100644 --- a/.ci/ci.yml.tmpl +++ b/.ci/ci.yml.tmpl @@ -192,7 +192,7 @@ jobs: - put: {{v.short_name}}-intermediate params: - repository: terraform-diff/new + repository: terraform-diff/{{k}}/new branch_file: magic-modules-branched/branchname force: true get_params: @@ -200,7 +200,7 @@ jobs: - put: {{v.short_name}}-intermediate params: - repository: terraform-diff/old + repository: terraform-diff/{{k}}/old branch_file: magic-modules-previous/branchname force: true get_params: diff --git a/.ci/magic-modules/diff-terraform.sh b/.ci/magic-modules/diff-terraform.sh index acc398f625ac..596ea881a016 100755 --- a/.ci/magic-modules/diff-terraform.sh +++ b/.ci/magic-modules/diff-terraform.sh @@ -82,5 +82,7 @@ for mm_dir in magic-modules-branched magic-modules-previous; do done -git clone "magic-modules-branched/build/$SHORT_NAME" "./terraform-diff/new" -git clone "magic-modules-previous/build/$SHORT_NAME" "./terraform-diff/old" +mkdir "./terraform-diff/$VERSION" + +git clone "magic-modules-branched/build/$SHORT_NAME" "./terraform-diff/$VERSION/new" +git clone "magic-modules-previous/build/$SHORT_NAME" "./terraform-diff/$VERSION/old" From d2093ddd5fc4b14909d180d600e28f07ab050c23 Mon Sep 17 00:00:00 2001 From: Sam Levenick Date: Mon, 21 Oct 2019 11:01:09 -0700 Subject: [PATCH 06/16] Add project to inspec terraform config where needed for CI (#2459) Merged PR #2459. --- build/inspec | 2 +- templates/inspec/tests/integration/build/gcp-mm.tf | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/build/inspec b/build/inspec index fcc076d77165..179cd115de4d 160000 --- a/build/inspec +++ b/build/inspec @@ -1 +1 @@ -Subproject commit fcc076d77165d672797a5063a4501e4fb733118d +Subproject commit 179cd115de4dc78342a1b10a6d278e0e4fd88d65 diff --git a/templates/inspec/tests/integration/build/gcp-mm.tf b/templates/inspec/tests/integration/build/gcp-mm.tf index 73c6e6791755..d03e10dce3b2 100644 --- a/templates/inspec/tests/integration/build/gcp-mm.tf +++ b/templates/inspec/tests/integration/build/gcp-mm.tf @@ -669,6 +669,7 @@ resource "google_ml_engine_model" "inspec-gcp-model" { } resource "google_compute_firewall" "dataproc" { + project = var.gcp_project_id name = "dataproc-firewall" network = "${google_compute_network.dataproc.name}" @@ -688,7 +689,8 @@ resource "google_compute_firewall" "dataproc" { } resource "google_compute_network" "dataproc" { - name = "dataproc-network" + project = var.gcp_project_id + name = "dataproc-network" } resource "google_dataproc_cluster" "mycluster" { From 4813be6a42030262cf69473a099d1c2d006902ff Mon Sep 17 00:00:00 2001 From: Nathan McKinley Date: Mon, 21 Oct 2019 11:24:36 -0700 Subject: [PATCH 07/16] Organization policies can insert entries into this field, causing a permadiff. (#2496) Merged PR #2496. --- build/terraform | 2 +- build/terraform-beta | 2 +- products/pubsub/terraform.yaml | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/build/terraform b/build/terraform index 1ed9f43abe5a..ac21aa97aa42 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit 1ed9f43abe5a1118143bc460594341338ffc598d +Subproject commit ac21aa97aa42ef58a31246f9ed7dab88320a5fe7 diff --git a/build/terraform-beta b/build/terraform-beta index 0574383c5b92..5f6c9236ddfd 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit 0574383c5b921b76b03bbb3a0791763f8e3155d6 +Subproject commit 5f6c9236ddfde90ef0d4b270998b3cde646a2932 diff --git a/products/pubsub/terraform.yaml b/products/pubsub/terraform.yaml index 771cf77e7323..57dec762fbe9 100644 --- a/products/pubsub/terraform.yaml +++ b/products/pubsub/terraform.yaml @@ -44,6 +44,8 @@ overrides: !ruby/object:Overrides::ResourceOverrides diff_suppress_func: 'compareSelfLinkOrResourceName' custom_expand: templates/terraform/custom_expand/resource_from_self_link.go.erb custom_flatten: templates/terraform/custom_flatten/name_from_self_link.erb + messageStoragePolicy: !ruby/object:Overrides::Terraform::PropertyOverride + default_from_api: true custom_code: !ruby/object:Provider::Terraform::CustomCode encoder: templates/terraform/encoders/no_send_name.go.erb update_encoder: templates/terraform/update_encoder/pubsub_topic.erb From 2e6058d04420db2dcfbe725de259947e1801db59 Mon Sep 17 00:00:00 2001 From: Dana Hoffman Date: Mon, 21 Oct 2019 15:19:07 -0700 Subject: [PATCH 08/16] Support setting 'location' in google_sql_database_instance backup_configuration (#2498) Merged PR #2498. --- build/terraform | 2 +- build/terraform-beta | 2 +- .../terraform/resources/resource_sql_database_instance.go | 6 ++++++ .../tests/resource_sql_database_instance_test.go.erb | 3 ++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/build/terraform b/build/terraform index ac21aa97aa42..dd8f51b0460d 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit ac21aa97aa42ef58a31246f9ed7dab88320a5fe7 +Subproject commit dd8f51b0460d5767c9241d8baf6c7e65c7a5d783 diff --git a/build/terraform-beta b/build/terraform-beta index 5f6c9236ddfd..c115c7ef5319 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit 5f6c9236ddfde90ef0d4b270998b3cde646a2932 +Subproject commit c115c7ef53198db5e043924d753ffe06d9a787d2 diff --git a/third_party/terraform/resources/resource_sql_database_instance.go b/third_party/terraform/resources/resource_sql_database_instance.go index e05bcd2d61ac..dbf55492eecd 100644 --- a/third_party/terraform/resources/resource_sql_database_instance.go +++ b/third_party/terraform/resources/resource_sql_database_instance.go @@ -118,6 +118,10 @@ func resourceSqlDatabaseInstance() *schema.Resource { // start_time is randomly assigned if not set Computed: true, }, + "location": { + Type: schema.TypeString, + Optional: true, + }, }, }, }, @@ -690,6 +694,7 @@ func expandBackupConfiguration(configured []interface{}) *sqladmin.BackupConfigu BinaryLogEnabled: _backupConfiguration["binary_log_enabled"].(bool), Enabled: _backupConfiguration["enabled"].(bool), StartTime: _backupConfiguration["start_time"].(string), + Location: _backupConfiguration["location"].(string), } } @@ -898,6 +903,7 @@ func flattenBackupConfiguration(backupConfiguration *sqladmin.BackupConfiguratio "binary_log_enabled": backupConfiguration.BinaryLogEnabled, "enabled": backupConfiguration.Enabled, "start_time": backupConfiguration.StartTime, + "location": backupConfiguration.Location, } return []map[string]interface{}{data} diff --git a/third_party/terraform/tests/resource_sql_database_instance_test.go.erb b/third_party/terraform/tests/resource_sql_database_instance_test.go.erb index a7810e1d22a3..7240fd3f0198 100644 --- a/third_party/terraform/tests/resource_sql_database_instance_test.go.erb +++ b/third_party/terraform/tests/resource_sql_database_instance_test.go.erb @@ -911,7 +911,8 @@ resource "google_sql_database_instance" "instance" { availability_type = "REGIONAL" backup_configuration { - enabled = true + enabled = true + location = "us" } } } From db73da4ba01b68c1b401bba78f0cdf3deca61c58 Mon Sep 17 00:00:00 2001 From: megan07 Date: Tue, 22 Oct 2019 16:14:38 +0200 Subject: [PATCH 09/16] deprecate kubernetes_dashboard for 2.X (#2447) Merged PR #2447. --- build/terraform | 2 +- build/terraform-beta | 2 +- .../terraform/resources/resource_container_cluster.go.erb | 7 ++++--- .../website/docs/r/container_cluster.html.markdown | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/build/terraform b/build/terraform index dd8f51b0460d..2961311885c3 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit dd8f51b0460d5767c9241d8baf6c7e65c7a5d783 +Subproject commit 2961311885c3a0f977683c116ca6d417a51ee742 diff --git a/build/terraform-beta b/build/terraform-beta index c115c7ef5319..43ac96a67263 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit c115c7ef53198db5e043924d753ffe06d9a787d2 +Subproject commit 43ac96a67263dd4175376b9eb7c62d226a24ad14 diff --git a/third_party/terraform/resources/resource_container_cluster.go.erb b/third_party/terraform/resources/resource_container_cluster.go.erb index 7a426b8e7250..3af8db7155a4 100644 --- a/third_party/terraform/resources/resource_container_cluster.go.erb +++ b/third_party/terraform/resources/resource_container_cluster.go.erb @@ -179,9 +179,10 @@ func resourceContainerCluster() *schema.Resource { }, }, "kubernetes_dashboard": { - Type: schema.TypeList, - Optional: true, - Computed: true, + Type: schema.TypeList, + Optional: true, + Computed: true, + Deprecated: "The Kubernetes Dashboard addon is deprecated for clusters on GKE.", MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ diff --git a/third_party/terraform/website/docs/r/container_cluster.html.markdown b/third_party/terraform/website/docs/r/container_cluster.html.markdown index 9f7b7ed14810..c95311f9eb21 100644 --- a/third_party/terraform/website/docs/r/container_cluster.html.markdown +++ b/third_party/terraform/website/docs/r/container_cluster.html.markdown @@ -332,7 +332,7 @@ The `addons_config` block supports: controller addon, which makes it easy to set up HTTP load balancers for services in a cluster. It is enabled by default; set `disabled = true` to disable. -* `kubernetes_dashboard` - (Optional) The status of the Kubernetes Dashboard +* `kubernetes_dashboard` - (Optional, Deprecated) The status of the Kubernetes Dashboard add-on, which controls whether the Kubernetes Dashboard is enabled for this cluster. It is disabled by default; set `disabled = false` to enable. From 49d3c3f68b7577bac1c2c75cebee2e0fcd20819b Mon Sep 17 00:00:00 2001 From: Riley Karson Date: Tue, 22 Oct 2019 08:56:41 -0700 Subject: [PATCH 10/16] Bump GKE node pool GPU disk to an appropriate size. (#2505) Merged PR #2505. --- build/terraform | 2 +- build/terraform-beta | 2 +- .../terraform/tests/resource_container_node_pool_test.go.erb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/terraform b/build/terraform index 2961311885c3..6a45d4c38beb 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit 2961311885c3a0f977683c116ca6d417a51ee742 +Subproject commit 6a45d4c38beb6883e844178353cf4be71943d97d diff --git a/build/terraform-beta b/build/terraform-beta index 43ac96a67263..c742433d97a2 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit 43ac96a67263dd4175376b9eb7c62d226a24ad14 +Subproject commit c742433d97a27b13b65a53f055fb0390e3c05f13 diff --git a/third_party/terraform/tests/resource_container_node_pool_test.go.erb b/third_party/terraform/tests/resource_container_node_pool_test.go.erb index 802e641a53ad..b82b5e88b2e9 100644 --- a/third_party/terraform/tests/resource_container_node_pool_test.go.erb +++ b/third_party/terraform/tests/resource_container_node_pool_test.go.erb @@ -1238,7 +1238,7 @@ resource "google_container_node_pool" "np_with_gpu" { node_config { machine_type = "n1-standard-1" - disk_size_gb = 10 + disk_size_gb = 32 oauth_scopes = [ "https://www.googleapis.com/auth/devstorage.read_only", From aa7ede44e0c59a5f6e9e1582b7aebf24a29c0bfd Mon Sep 17 00:00:00 2001 From: megan07 Date: Tue, 22 Oct 2019 11:46:44 -0500 Subject: [PATCH 11/16] add ip_configuration to dataflow_job (#2504) Merged PR #2504. --- build/terraform | 2 +- build/terraform-beta | 2 +- .../resources/resource_dataflow_job.go | 8 ++++ .../tests/resource_dataflow_job_test.go | 45 +++++++++++++++++++ .../website/docs/r/dataflow_job.html.markdown | 1 + 5 files changed, 56 insertions(+), 2 deletions(-) diff --git a/build/terraform b/build/terraform index 6a45d4c38beb..e053a9c5813c 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit 6a45d4c38beb6883e844178353cf4be71943d97d +Subproject commit e053a9c5813c86e3f49a2b1f66e2992da96deedf diff --git a/build/terraform-beta b/build/terraform-beta index c742433d97a2..5e77cae1b3f8 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit c742433d97a27b13b65a53f055fb0390e3c05f13 +Subproject commit 5e77cae1b3f87c2f3f3cc67b592a446abd83bc0b diff --git a/third_party/terraform/resources/resource_dataflow_job.go b/third_party/terraform/resources/resource_dataflow_job.go index ff4996b34194..1cf0a9eaee89 100644 --- a/third_party/terraform/resources/resource_dataflow_job.go +++ b/third_party/terraform/resources/resource_dataflow_job.go @@ -122,6 +122,13 @@ func resourceDataflowJob() *schema.Resource { Optional: true, ForceNew: true, }, + + "ip_configuration": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{"WORKER_IP_PUBLIC", "WORKER_IP_PRIVATE", ""}, false), + }, }, } } @@ -154,6 +161,7 @@ func resourceDataflowJobCreate(d *schema.ResourceData, meta interface{}) error { Subnetwork: d.Get("subnetwork").(string), TempLocation: d.Get("temp_gcs_location").(string), MachineType: d.Get("machine_type").(string), + IpConfiguration: d.Get("ip_configuration").(string), AdditionalUserLabels: labels, Zone: zone, } diff --git a/third_party/terraform/tests/resource_dataflow_job_test.go b/third_party/terraform/tests/resource_dataflow_job_test.go index 37ffc05f1809..ae38eeb8d63e 100644 --- a/third_party/terraform/tests/resource_dataflow_job_test.go +++ b/third_party/terraform/tests/resource_dataflow_job_test.go @@ -131,6 +131,24 @@ func TestAccDataflowJobCreateWithLabels(t *testing.T) { }) } +func TestAccDataflowJobCreateWithIpConfig(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckDataflowJobDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDataflowJobWithIpConfig, + Check: resource.ComposeTestCheckFunc( + testAccDataflowJobExists( + "google_dataflow_job.big_data"), + ), + }, + }, + }) +} + func testAccCheckDataflowJobDestroy(s *terraform.State) error { for _, rs := range s.RootModule().Resources { if rs.Type != "google_dataflow_job" { @@ -519,6 +537,33 @@ resource "google_dataflow_job" "big_data" { on_delete = "cancel" }`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10), getTestProjectFromEnv()) +var testAccDataflowJobWithIpConfig = fmt.Sprintf(` +resource "google_storage_bucket" "temp" { + name = "dfjob-test-%s-temp" + + force_destroy = true +} + +resource "google_dataflow_job" "big_data" { + name = "dfjob-test-%s" + + template_gcs_path = "gs://dataflow-templates/wordcount/template_file" + temp_gcs_location = "${google_storage_bucket.temp.url}" + machine_type = "n1-standard-2" + + parameters = { + inputFile = "gs://dataflow-samples/shakespeare/kinglear.txt" + output = "${google_storage_bucket.temp.url}/output" + } + + ip_configuration = "WORKER_IP_PRIVATE" + + zone = "us-central1-f" + project = "%s" + + on_delete = "cancel" +}`, acctest.RandString(10), acctest.RandString(10), getTestProjectFromEnv()) + func testAccDataflowJobWithLabels(key string) string { return fmt.Sprintf(` resource "google_storage_bucket" "temp" { diff --git a/third_party/terraform/website/docs/r/dataflow_job.html.markdown b/third_party/terraform/website/docs/r/dataflow_job.html.markdown index 9cc2e1e102f2..8b3901b4cf85 100644 --- a/third_party/terraform/website/docs/r/dataflow_job.html.markdown +++ b/third_party/terraform/website/docs/r/dataflow_job.html.markdown @@ -54,6 +54,7 @@ The following arguments are supported: * `network` - (Optional) The network to which VMs will be assigned. If it is not provided, "default" will be used. * `subnetwork` - (Optional) The subnetwork to which VMs will be assigned. Should be of the form "regions/REGION/subnetworks/SUBNETWORK". * `machine_type` - (Optional) The machine type to use for the job. +* `ip_configuration` - (Optional) The configuration for VM IPs. Options are `"WORKER_IP_PUBLIC"` or `"WORKER_IP_PUBLIC"`. ## Attributes Reference From 19a8a892c11558f04c0e6cf4b807aa3fc9151181 Mon Sep 17 00:00:00 2001 From: Cameron Thornton Date: Tue, 22 Oct 2019 10:06:27 -0700 Subject: [PATCH 12/16] Replace some unnecessary checks with import tests (#2500) Merged PR #2500. --- build/terraform | 2 +- build/terraform-beta | 2 +- .../tests/resource_cloudiot_registry_test.go | 40 +-- .../resource_compute_autoscaler_test.go.erb | 119 +------ ...source_compute_backend_service_test.go.erb | 319 ++++-------------- .../tests/resource_compute_disk_test.go.erb | 161 +++------ ...esource_compute_global_address_test.go.erb | 62 ---- ...esource_compute_https_health_check_test.go | 83 +---- 8 files changed, 148 insertions(+), 640 deletions(-) diff --git a/build/terraform b/build/terraform index e053a9c5813c..215cca14609f 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit e053a9c5813c86e3f49a2b1f66e2992da96deedf +Subproject commit 215cca14609fdd8dcd86624b6d5344dfeeaf9b05 diff --git a/build/terraform-beta b/build/terraform-beta index 5e77cae1b3f8..8d85b10b3fa6 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit 5e77cae1b3f87c2f3f3cc67b592a446abd83bc0b +Subproject commit 8d85b10b3fa61b0dd85f7ea2fadb54c5e80233b7 diff --git a/third_party/terraform/tests/resource_cloudiot_registry_test.go b/third_party/terraform/tests/resource_cloudiot_registry_test.go index f6bf7365b884..2468de141262 100644 --- a/third_party/terraform/tests/resource_cloudiot_registry_test.go +++ b/third_party/terraform/tests/resource_cloudiot_registry_test.go @@ -46,10 +46,6 @@ func TestAccCloudIoTRegistry_basic(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccCloudIoTRegistry_basic(registryName), - Check: resource.ComposeTestCheckFunc( - testAccCloudIoTRegistryExists( - "google_cloudiot_registry.foobar"), - ), }, { ResourceName: "google_cloudiot_registry.foobar", @@ -72,10 +68,6 @@ func TestAccCloudIoTRegistry_extended(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccCloudIoTRegistry_extended(registryName), - Check: resource.ComposeTestCheckFunc( - testAccCloudIoTRegistryExists( - "google_cloudiot_registry.foobar"), - ), }, { ResourceName: "google_cloudiot_registry.foobar", @@ -98,14 +90,20 @@ func TestAccCloudIoTRegistry_update(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccCloudIoTRegistry_basic(registryName), - Check: resource.ComposeTestCheckFunc( - testAccCloudIoTRegistryExists( - "google_cloudiot_registry.foobar"), - ), + }, + { + ResourceName: "google_cloudiot_registry.foobar", + ImportState: true, + ImportStateVerify: true, }, { Config: testAccCloudIoTRegistry_extended(registryName), }, + { + ResourceName: "google_cloudiot_registry.foobar", + ImportState: true, + ImportStateVerify: true, + }, { Config: testAccCloudIoTRegistry_basic(registryName), }, @@ -223,24 +221,6 @@ func testAccCheckCloudIoTRegistryDestroy(s *terraform.State) error { return nil } -func testAccCloudIoTRegistryExists(n string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - if rs.Primary.ID == "" { - return fmt.Errorf("No ID is set") - } - config := testAccProvider.Meta().(*Config) - _, err := config.clientCloudIoT.Projects.Locations.Registries.Get(rs.Primary.ID).Do() - if err != nil { - return fmt.Errorf("Registry does not exist") - } - return nil - } -} - func testAccCloudIoTRegistry_basic(registryName string) string { return fmt.Sprintf(` resource "google_cloudiot_registry" "foobar" { diff --git a/third_party/terraform/tests/resource_compute_autoscaler_test.go.erb b/third_party/terraform/tests/resource_compute_autoscaler_test.go.erb index b7c37b6b11e2..9b84b8158485 100644 --- a/third_party/terraform/tests/resource_compute_autoscaler_test.go.erb +++ b/third_party/terraform/tests/resource_compute_autoscaler_test.go.erb @@ -15,8 +15,6 @@ import ( func TestAccComputeAutoscaler_update(t *testing.T) { t.Parallel() - var ascaler compute.Autoscaler - var it_name = fmt.Sprintf("autoscaler-test-%s", acctest.RandString(10)) var tp_name = fmt.Sprintf("autoscaler-test-%s", acctest.RandString(10)) var igm_name = fmt.Sprintf("autoscaler-test-%s", acctest.RandString(10)) @@ -29,20 +27,21 @@ func TestAccComputeAutoscaler_update(t *testing.T) { Steps: []resource.TestStep{ resource.TestStep{ Config: testAccComputeAutoscaler_basic(it_name, tp_name, igm_name, autoscaler_name), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeAutoscalerExists( - "google_compute_autoscaler.foobar", &ascaler), - ), + }, + resource.TestStep{ + ResourceName: "google_compute_autoscaler.foobar", + ImportState: true, + ImportStateVerify: true, }, resource.TestStep{ Config: testAccComputeAutoscaler_update(it_name, tp_name, igm_name, autoscaler_name), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeAutoscalerExists( - "google_compute_autoscaler.foobar", &ascaler), - testAccCheckComputeAutoscalerUpdated( - "google_compute_autoscaler.foobar", 10), - ), }, + resource.TestStep{ + ResourceName: "google_compute_autoscaler.foobar", + ImportState: true, + ImportStateVerify: true, + }, + }, }) } @@ -62,7 +61,6 @@ func TestAccComputeAutoscaler_multicondition(t *testing.T) { Steps: []resource.TestStep{ resource.TestStep{ Config: testAccComputeAutoscaler_multicondition(it_name, tp_name, igm_name, autoscaler_name), - Check: testAccCheckComputeAutoscalerMultifunction("google_compute_autoscaler.foobar"), }, resource.TestStep{ ResourceName: "google_compute_autoscaler.foobar", @@ -73,101 +71,6 @@ func TestAccComputeAutoscaler_multicondition(t *testing.T) { }) } -func testAccCheckComputeAutoscalerExists(n string, ascaler *compute.Autoscaler) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No ID is set") - } - - config := testAccProvider.Meta().(*Config) - - idParts := strings.Split(rs.Primary.ID, "/") - zone, name := idParts[0], idParts[1] - found, err := config.clientCompute.Autoscalers.Get( - config.Project, zone, name).Do() - if err != nil { - return err - } - - if found.Name != name { - return fmt.Errorf("Autoscaler not found") - } - - *ascaler = *found - - return nil - } -} - -func testAccCheckComputeAutoscalerMultifunction(n string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No ID is set") - } - - config := testAccProvider.Meta().(*Config) - - idParts := strings.Split(rs.Primary.ID, "/") - zone, name := idParts[0], idParts[1] - found, err := config.clientCompute.Autoscalers.Get( - config.Project, zone, name).Do() - if err != nil { - return err - } - - if found.Name != name { - return fmt.Errorf("Autoscaler not found") - } - - if found.AutoscalingPolicy.CpuUtilization.UtilizationTarget == 0.5 && found.AutoscalingPolicy.LoadBalancingUtilization.UtilizationTarget == 0.5 { - return nil - } - return fmt.Errorf("Util target for CPU: %f, for LB: %f - should have been 0.5 for each.", - found.AutoscalingPolicy.CpuUtilization.UtilizationTarget, - found.AutoscalingPolicy.LoadBalancingUtilization.UtilizationTarget) - - } -} - -func testAccCheckComputeAutoscalerUpdated(n string, max int64) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No ID is set") - } - - config := testAccProvider.Meta().(*Config) - - idParts := strings.Split(rs.Primary.ID, "/") - zone, name := idParts[0], idParts[1] - ascaler, err := config.clientCompute.Autoscalers.Get( - config.Project, zone, name).Do() - if err != nil { - return err - } - - if ascaler.AutoscalingPolicy.MaxNumReplicas != max { - return fmt.Errorf("maximum replicas incorrect") - } - - return nil - } -} - func testAccComputeAutoscaler_scaffolding(it_name, tp_name, igm_name string) string { return fmt.Sprintf(` data "google_compute_image" "my_image" { diff --git a/third_party/terraform/tests/resource_compute_backend_service_test.go.erb b/third_party/terraform/tests/resource_compute_backend_service_test.go.erb index d28b241d1dfc..2dcf00869839 100644 --- a/third_party/terraform/tests/resource_compute_backend_service_test.go.erb +++ b/third_party/terraform/tests/resource_compute_backend_service_test.go.erb @@ -18,7 +18,6 @@ func TestAccComputeBackendService_basic(t *testing.T) { serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) extraCheckName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -27,18 +26,15 @@ func TestAccComputeBackendService_basic(t *testing.T) { Steps: []resource.TestStep{ resource.TestStep{ Config: testAccComputeBackendService_basic(serviceName, checkName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - ), + }, + resource.TestStep{ + ResourceName: "google_compute_backend_service.foobar", + ImportState: true, + ImportStateVerify: true, }, resource.TestStep{ Config: testAccComputeBackendService_basicModified( serviceName, checkName, extraCheckName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - ), }, resource.TestStep{ ResourceName: "google_compute_backend_service.foobar", @@ -56,7 +52,6 @@ func TestAccComputeBackendService_withBackend(t *testing.T) { igName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) itName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -65,18 +60,15 @@ func TestAccComputeBackendService_withBackend(t *testing.T) { resource.TestStep{ Config: testAccComputeBackendService_withBackend( serviceName, igName, itName, checkName, 10), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.lipsum", &svc), - ), + }, + resource.TestStep{ + ResourceName: "google_compute_backend_service.lipsum", + ImportState: true, + ImportStateVerify: true, }, resource.TestStep{ Config: testAccComputeBackendService_withBackend( serviceName, igName, itName, checkName, 20), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.lipsum", &svc), - ), }, resource.TestStep{ ResourceName: "google_compute_backend_service.lipsum", @@ -85,16 +77,6 @@ func TestAccComputeBackendService_withBackend(t *testing.T) { }, }, }) - - if svc.TimeoutSec != 20 { - t.Errorf("Expected TimeoutSec == 20, got %d", svc.TimeoutSec) - } - if svc.Protocol != "HTTP" { - t.Errorf("Expected Protocol to be HTTP, got %q", svc.Protocol) - } - if len(svc.Backends) != 1 { - t.Errorf("Expected 1 backend, got %d", len(svc.Backends)) - } } func TestAccComputeBackendService_withBackendAndIAP(t *testing.T) { @@ -102,7 +84,6 @@ func TestAccComputeBackendService_withBackendAndIAP(t *testing.T) { igName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) itName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -111,10 +92,6 @@ func TestAccComputeBackendService_withBackendAndIAP(t *testing.T) { resource.TestStep{ Config: testAccComputeBackendService_withBackendAndIAP( serviceName, igName, itName, checkName, 10), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExistsWithIAP("google_compute_backend_service.lipsum", &svc), - resource.TestCheckResourceAttr("google_compute_backend_service.lipsum", "iap.0.oauth2_client_secret", "test"), - ), }, resource.TestStep{ ResourceName: "google_compute_backend_service.lipsum", @@ -125,24 +102,14 @@ func TestAccComputeBackendService_withBackendAndIAP(t *testing.T) { resource.TestStep{ Config: testAccComputeBackendService_withBackend( serviceName, igName, itName, checkName, 10), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExistsWithoutIAP( - "google_compute_backend_service.lipsum", &svc), - ), + }, + resource.TestStep{ + ResourceName: "google_compute_backend_service.lipsum", + ImportState: true, + ImportStateVerify: true, }, }, }) - - if svc.TimeoutSec != 10 { - t.Errorf("Expected TimeoutSec == 10, got %d", svc.TimeoutSec) - } - if svc.Protocol != "HTTP" { - t.Errorf("Expected Protocol to be HTTP, got %q", svc.Protocol) - } - if len(svc.Backends) != 1 { - t.Errorf("Expected 1 backend, got %d", len(svc.Backends)) - } - } func TestAccComputeBackendService_updatePreservesOptionalParameters(t *testing.T) { @@ -150,7 +117,6 @@ func TestAccComputeBackendService_updatePreservesOptionalParameters(t *testing.T serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -160,25 +126,23 @@ func TestAccComputeBackendService_updatePreservesOptionalParameters(t *testing.T resource.TestStep{ Config: testAccComputeBackendService_withSessionAffinity( serviceName, checkName, "initial-description", "GENERATED_COOKIE"), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - ), + }, + resource.TestStep{ + ResourceName: "google_compute_backend_service.foobar", + ImportState: true, + ImportStateVerify: true, }, resource.TestStep{ Config: testAccComputeBackendService_withSessionAffinity( serviceName, checkName, "updated-description", "GENERATED_COOKIE"), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - ), + }, + resource.TestStep{ + ResourceName: "google_compute_backend_service.foobar", + ImportState: true, + ImportStateVerify: true, }, }, }) - - if svc.SessionAffinity != "GENERATED_COOKIE" { - t.Errorf("Expected SessionAffinity == \"GENERATED_COOKIE\", got %s", svc.SessionAffinity) - } } func TestAccComputeBackendService_withConnectionDraining(t *testing.T) { @@ -186,7 +150,6 @@ func TestAccComputeBackendService_withConnectionDraining(t *testing.T) { serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -195,10 +158,6 @@ func TestAccComputeBackendService_withConnectionDraining(t *testing.T) { Steps: []resource.TestStep{ resource.TestStep{ Config: testAccComputeBackendService_withConnectionDraining(serviceName, checkName, 10), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - ), }, resource.TestStep{ ResourceName: "google_compute_backend_service.foobar", @@ -207,10 +166,6 @@ func TestAccComputeBackendService_withConnectionDraining(t *testing.T) { }, }, }) - - if svc.ConnectionDraining.DrainingTimeoutSec != 10 { - t.Errorf("Expected ConnectionDraining.DrainingTimeoutSec == 10, got %d", svc.ConnectionDraining.DrainingTimeoutSec) - } } func TestAccComputeBackendService_withConnectionDrainingAndUpdate(t *testing.T) { @@ -218,7 +173,6 @@ func TestAccComputeBackendService_withConnectionDrainingAndUpdate(t *testing.T) serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -227,24 +181,22 @@ func TestAccComputeBackendService_withConnectionDrainingAndUpdate(t *testing.T) Steps: []resource.TestStep{ resource.TestStep{ Config: testAccComputeBackendService_withConnectionDraining(serviceName, checkName, 10), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - ), + }, + resource.TestStep{ + ResourceName: "google_compute_backend_service.foobar", + ImportState: true, + ImportStateVerify: true, }, resource.TestStep{ Config: testAccComputeBackendService_basic(serviceName, checkName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - ), + }, + resource.TestStep{ + ResourceName: "google_compute_backend_service.foobar", + ImportState: true, + ImportStateVerify: true, }, }, }) - - if svc.ConnectionDraining.DrainingTimeoutSec != 300 { - t.Errorf("Expected ConnectionDraining.DrainingTimeoutSec == 300, got %d", svc.ConnectionDraining.DrainingTimeoutSec) - } } func TestAccComputeBackendService_withHttpsHealthCheck(t *testing.T) { @@ -252,7 +204,6 @@ func TestAccComputeBackendService_withHttpsHealthCheck(t *testing.T) { serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -261,10 +212,6 @@ func TestAccComputeBackendService_withHttpsHealthCheck(t *testing.T) { Steps: []resource.TestStep{ resource.TestStep{ Config: testAccComputeBackendService_withHttpsHealthCheck(serviceName, checkName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - ), }, resource.TestStep{ ResourceName: "google_compute_backend_service.foobar", @@ -280,7 +227,6 @@ func TestAccComputeBackendService_withCdnPolicy(t *testing.T) { serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -289,10 +235,6 @@ func TestAccComputeBackendService_withCdnPolicy(t *testing.T) { Steps: []resource.TestStep{ resource.TestStep{ Config: testAccComputeBackendService_withCdnPolicy(serviceName, checkName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - ), }, resource.TestStep{ ResourceName: "google_compute_backend_service.foobar", @@ -309,7 +251,6 @@ func TestAccComputeBackendService_withSecurityPolicy(t *testing.T) { serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) polName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -318,11 +259,6 @@ func TestAccComputeBackendService_withSecurityPolicy(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccComputeBackendService_withSecurityPolicy(serviceName, checkName, polName, "${google_compute_security_policy.policy.self_link}"), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - resource.TestMatchResourceAttr("google_compute_backend_service.foobar", "security_policy", regexp.MustCompile(polName)), - ), }, { ResourceName: "google_compute_backend_service.foobar", @@ -341,106 +277,11 @@ func TestAccComputeBackendService_withSecurityPolicy(t *testing.T) { }) } -func testAccCheckComputeBackendServiceExists(n string, svc *compute.BackendService) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No ID is set") - } - - config := testAccProvider.Meta().(*Config) - - found, err := config.clientCompute.BackendServices.Get( - config.Project, rs.Primary.ID).Do() - if err != nil { - return err - } - - if found.Name != rs.Primary.ID { - return fmt.Errorf("Backend service %s not found", rs.Primary.ID) - } - - *svc = *found - - return nil - } -} - -func testAccCheckComputeBackendServiceExistsWithIAP(n string, svc *compute.BackendService) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No ID is set") - } - - config := testAccProvider.Meta().(*Config) - - found, err := config.clientCompute.BackendServices.Get( - config.Project, rs.Primary.ID).Do() - if err != nil { - return err - } - - if found.Name != rs.Primary.ID { - return fmt.Errorf("Backend service %s not found", rs.Primary.ID) - } - - if found.Iap == nil || found.Iap.Enabled == false { - return fmt.Errorf("IAP not found or not enabled. Saw %v", found.Iap) - } - - *svc = *found - - return nil - } -} - -func testAccCheckComputeBackendServiceExistsWithoutIAP(n string, svc *compute.BackendService) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No ID is set") - } - - config := testAccProvider.Meta().(*Config) - - found, err := config.clientCompute.BackendServices.Get( - config.Project, rs.Primary.ID).Do() - if err != nil { - return err - } - - if found.Name != rs.Primary.ID { - return fmt.Errorf("Backend service %s not found", rs.Primary.ID) - } - - if found.Iap != nil && found.Iap.Enabled == true { - return fmt.Errorf("IAP enabled when it should be disabled") - } - - *svc = *found - - return nil - } -} func TestAccComputeBackendService_withCDNEnabled(t *testing.T) { t.Parallel() serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -450,17 +291,14 @@ func TestAccComputeBackendService_withCDNEnabled(t *testing.T) { resource.TestStep{ Config: testAccComputeBackendService_withCDNEnabled( serviceName, checkName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - ), + }, + resource.TestStep{ + ResourceName: "google_compute_backend_service.foobar", + ImportState: true, + ImportStateVerify: true, }, }, }) - - if svc.EnableCDN != true { - t.Errorf("Expected EnableCDN == true, got %t", svc.EnableCDN) - } } func TestAccComputeBackendService_withSessionAffinity(t *testing.T) { @@ -468,7 +306,6 @@ func TestAccComputeBackendService_withSessionAffinity(t *testing.T) { serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -478,25 +315,23 @@ func TestAccComputeBackendService_withSessionAffinity(t *testing.T) { resource.TestStep{ Config: testAccComputeBackendService_withSessionAffinity( serviceName, checkName, "description", "CLIENT_IP"), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - ), + }, + resource.TestStep{ + ResourceName: "google_compute_backend_service.foobar", + ImportState: true, + ImportStateVerify: true, }, resource.TestStep{ Config: testAccComputeBackendService_withSessionAffinity( serviceName, checkName, "description", "GENERATED_COOKIE"), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - ), + }, + resource.TestStep{ + ResourceName: "google_compute_backend_service.foobar", + ImportState: true, + ImportStateVerify: true, }, }, }) - - if svc.SessionAffinity != "GENERATED_COOKIE" { - t.Errorf("Expected SessionAffinity == \"GENERATED_COOKIE\", got %s", svc.SessionAffinity) - } } func TestAccComputeBackendService_withAffinityCookieTtlSec(t *testing.T) { @@ -504,7 +339,6 @@ func TestAccComputeBackendService_withAffinityCookieTtlSec(t *testing.T) { serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -514,21 +348,14 @@ func TestAccComputeBackendService_withAffinityCookieTtlSec(t *testing.T) { resource.TestStep{ Config: testAccComputeBackendService_withAffinityCookieTtlSec( serviceName, checkName, "description", "GENERATED_COOKIE", 300), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.foobar", &svc), - ), + }, + resource.TestStep{ + ResourceName: "google_compute_backend_service.foobar", + ImportState: true, + ImportStateVerify: true, }, }, }) - - if svc.SessionAffinity != "GENERATED_COOKIE" { - t.Errorf("Expected SessionAffinity == \"GENERATED_COOKIE\", got %s", svc.SessionAffinity) - } - - if svc.AffinityCookieTtlSec != 300 { - t.Errorf("Expected AffinityCookieTtlSec == 300, got %v", svc.AffinityCookieTtlSec) - } } func TestAccComputeBackendService_withMaxConnections(t *testing.T) { @@ -539,7 +366,6 @@ func TestAccComputeBackendService_withMaxConnections(t *testing.T) { itName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -548,18 +374,15 @@ func TestAccComputeBackendService_withMaxConnections(t *testing.T) { resource.TestStep{ Config: testAccComputeBackendService_withMaxConnections( serviceName, igName, itName, checkName, 10), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.lipsum", &svc), - ), + }, + resource.TestStep{ + ResourceName: "google_compute_backend_service.lipsum", + ImportState: true, + ImportStateVerify: true, }, resource.TestStep{ Config: testAccComputeBackendService_withMaxConnections( serviceName, igName, itName, checkName, 20), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.lipsum", &svc), - ), }, resource.TestStep{ ResourceName: "google_compute_backend_service.lipsum", @@ -568,10 +391,6 @@ func TestAccComputeBackendService_withMaxConnections(t *testing.T) { }, }, }) - - if svc.Backends[0].MaxConnections != 20 { - t.Errorf("Expected MaxConnections == 20, got %d", svc.Backends[0].MaxConnections) - } } func TestAccComputeBackendService_withMaxConnectionsPerInstance(t *testing.T) { @@ -582,7 +401,6 @@ func TestAccComputeBackendService_withMaxConnectionsPerInstance(t *testing.T) { itName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var svc compute.BackendService resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -591,18 +409,15 @@ func TestAccComputeBackendService_withMaxConnectionsPerInstance(t *testing.T) { resource.TestStep{ Config: testAccComputeBackendService_withMaxConnectionsPerInstance( serviceName, igName, itName, checkName, 10), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.lipsum", &svc), - ), + }, + resource.TestStep{ + ResourceName: "google_compute_backend_service.lipsum", + ImportState: true, + ImportStateVerify: true, }, resource.TestStep{ Config: testAccComputeBackendService_withMaxConnectionsPerInstance( serviceName, igName, itName, checkName, 20), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeBackendServiceExists( - "google_compute_backend_service.lipsum", &svc), - ), }, resource.TestStep{ ResourceName: "google_compute_backend_service.lipsum", @@ -611,10 +426,6 @@ func TestAccComputeBackendService_withMaxConnectionsPerInstance(t *testing.T) { }, }, }) - - if svc.Backends[0].MaxConnectionsPerInstance != 20 { - t.Errorf("Expected MaxConnectionsPerInstance == 20, got %d", svc.Backends[0].MaxConnectionsPerInstance) - } } func TestAccComputeBackendService_withMaxRatePerEndpoint(t *testing.T) { diff --git a/third_party/terraform/tests/resource_compute_disk_test.go.erb b/third_party/terraform/tests/resource_compute_disk_test.go.erb index 7a980d3d3945..3d54d6d653be 100644 --- a/third_party/terraform/tests/resource_compute_disk_test.go.erb +++ b/third_party/terraform/tests/resource_compute_disk_test.go.erb @@ -226,7 +226,6 @@ func TestAccComputeDisk_update(t *testing.T) { t.Parallel() diskName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var disk compute.Disk resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -234,24 +233,19 @@ func TestAccComputeDisk_update(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccComputeDisk_basic(diskName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeDiskExists( - "google_compute_disk.foobar", getTestProjectFromEnv(), &disk), - resource.TestCheckResourceAttr("google_compute_disk.foobar", "size", "50"), - testAccCheckComputeDiskHasLabel(&disk, "my-label", "my-label-value"), - testAccCheckComputeDiskHasLabelFingerprint(&disk, "google_compute_disk.foobar"), - ), + }, + { + ResourceName: "google_compute_disk.foobar", + ImportState: true, + ImportStateVerify: true, }, { Config: testAccComputeDisk_updated(diskName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeDiskExists( - "google_compute_disk.foobar", getTestProjectFromEnv(), &disk), - resource.TestCheckResourceAttr("google_compute_disk.foobar", "size", "100"), - testAccCheckComputeDiskHasLabel(&disk, "my-label", "my-updated-label-value"), - testAccCheckComputeDiskHasLabel(&disk, "a-new-label", "a-new-label-value"), - testAccCheckComputeDiskHasLabelFingerprint(&disk, "google_compute_disk.foobar"), - ), + }, + { + ResourceName: "google_compute_disk.foobar", + ImportState: true, + ImportStateVerify: true, }, }, }) @@ -265,8 +259,6 @@ func TestAccComputeDisk_fromSnapshot(t *testing.T) { snapshotName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) projectName := getTestProjectFromEnv() - var disk compute.Disk - resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -274,17 +266,19 @@ func TestAccComputeDisk_fromSnapshot(t *testing.T) { Steps: []resource.TestStep{ resource.TestStep{ Config: testAccComputeDisk_fromSnapshot(projectName, firstDiskName, snapshotName, diskName, "self_link"), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeDiskExists( - "google_compute_disk.seconddisk", getTestProjectFromEnv(), &disk), - ), + }, + { + ResourceName: "google_compute_disk.seconddisk", + ImportState: true, + ImportStateVerify: true, }, resource.TestStep{ Config: testAccComputeDisk_fromSnapshot(projectName, firstDiskName, snapshotName, diskName, "name"), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeDiskExists( - "google_compute_disk.seconddisk", getTestProjectFromEnv(), &disk), - ), + }, + { + ResourceName: "google_compute_disk.seconddisk", + ImportState: true, + ImportStateVerify: true, }, }, }) @@ -352,7 +346,6 @@ func TestAccComputeDisk_deleteDetach(t *testing.T) { diskName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) instanceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var disk compute.Disk resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -361,10 +354,11 @@ func TestAccComputeDisk_deleteDetach(t *testing.T) { Steps: []resource.TestStep{ resource.TestStep{ Config: testAccComputeDisk_deleteDetach(instanceName, diskName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeDiskExists( - "google_compute_disk.foo", getTestProjectFromEnv(), &disk), - ), + }, + { + ResourceName: "google_compute_disk.foo", + ImportState: true, + ImportStateVerify: true, }, // this needs to be a second step so we refresh and see the instance // listed as attached to the disk; the instance is created after the @@ -372,12 +366,11 @@ func TestAccComputeDisk_deleteDetach(t *testing.T) { // another step resource.TestStep{ Config: testAccComputeDisk_deleteDetach(instanceName, diskName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeDiskExists( - "google_compute_disk.foo", getTestProjectFromEnv(), &disk), - testAccCheckComputeDiskInstances( - "google_compute_disk.foo", &disk), - ), + }, + { + ResourceName: "google_compute_disk.foo", + ImportState: true, + ImportStateVerify: true, }, }, }) @@ -389,7 +382,6 @@ func TestAccComputeDisk_deleteDetachIGM(t *testing.T) { diskName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) diskName2 := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) mgrName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) - var disk compute.Disk resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -398,10 +390,11 @@ func TestAccComputeDisk_deleteDetachIGM(t *testing.T) { Steps: []resource.TestStep{ resource.TestStep{ Config: testAccComputeDisk_deleteDetachIGM(diskName, mgrName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeDiskExists( - "google_compute_disk.foo", getTestProjectFromEnv(), &disk), - ), + }, + { + ResourceName: "google_compute_disk.foo", + ImportState: true, + ImportStateVerify: true, }, // this needs to be a second step so we refresh and see the instance // listed as attached to the disk; the instance is created after the @@ -409,30 +402,29 @@ func TestAccComputeDisk_deleteDetachIGM(t *testing.T) { // another step resource.TestStep{ Config: testAccComputeDisk_deleteDetachIGM(diskName, mgrName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeDiskExists( - "google_compute_disk.foo", getTestProjectFromEnv(), &disk), - testAccCheckComputeDiskInstances( - "google_compute_disk.foo", &disk), - ), + }, + { + ResourceName: "google_compute_disk.foo", + ImportState: true, + ImportStateVerify: true, }, // Change the disk name to recreate the instances resource.TestStep{ Config: testAccComputeDisk_deleteDetachIGM(diskName2, mgrName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeDiskExists( - "google_compute_disk.foo", getTestProjectFromEnv(), &disk), - ), + }, + { + ResourceName: "google_compute_disk.foo", + ImportState: true, + ImportStateVerify: true, }, // Add the extra step like before resource.TestStep{ Config: testAccComputeDisk_deleteDetachIGM(diskName2, mgrName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeDiskExists( - "google_compute_disk.foo", getTestProjectFromEnv(), &disk), - testAccCheckComputeDiskInstances( - "google_compute_disk.foo", &disk), - ), + }, + { + ResourceName: "google_compute_disk.foo", + ImportState: true, + ImportStateVerify: true, }, }, }) @@ -491,37 +483,6 @@ func testAccCheckComputeDiskExists(n, p string, disk *compute.Disk) resource.Tes } } -func testAccCheckComputeDiskHasLabel(disk *compute.Disk, key, value string) resource.TestCheckFunc { - return func(s *terraform.State) error { - val, ok := disk.Labels[key] - if !ok { - return fmt.Errorf("Label with key %s not found", key) - } - - if val != value { - return fmt.Errorf("Label value did not match for key %s: expected %s but found %s", key, value, val) - } - return nil - } -} - -func testAccCheckComputeDiskHasLabelFingerprint(disk *compute.Disk, resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - state := s.RootModule().Resources[resourceName] - if state == nil { - return fmt.Errorf("Unable to find resource named %s", resourceName) - } - - labelFingerprint := state.Primary.Attributes["label_fingerprint"] - if labelFingerprint != disk.LabelFingerprint { - return fmt.Errorf("Label fingerprints do not match: api returned %s but state has %s", - disk.LabelFingerprint, labelFingerprint) - } - - return nil - } -} - func testAccCheckEncryptionKey(n string, disk *compute.Disk) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -540,28 +501,6 @@ func testAccCheckEncryptionKey(n string, disk *compute.Disk) resource.TestCheckF } } -func testAccCheckComputeDiskInstances(n string, disk *compute.Disk) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - attr := rs.Primary.Attributes["users.#"] - if strconv.Itoa(len(disk.Users)) != attr { - return fmt.Errorf("Disk %s has mismatched users.\nTF State: %+v\nGCP State: %+v", n, rs.Primary.Attributes["users"], disk.Users) - } - - for pos, user := range disk.Users { - if rs.Primary.Attributes["users."+strconv.Itoa(pos)] != user { - return fmt.Errorf("Disk %s has mismatched users.\nTF State: %+v.\nGCP State: %+v", - n, rs.Primary.Attributes["users"], disk.Users) - } - } - return nil - } -} - func testAccComputeDisk_basic(diskName string) string { return fmt.Sprintf(` data "google_compute_image" "my_image" { diff --git a/third_party/terraform/tests/resource_compute_global_address_test.go.erb b/third_party/terraform/tests/resource_compute_global_address_test.go.erb index dfb5034cf12a..fe5c7743cad9 100644 --- a/third_party/terraform/tests/resource_compute_global_address_test.go.erb +++ b/third_party/terraform/tests/resource_compute_global_address_test.go.erb @@ -15,8 +15,6 @@ import ( func TestAccComputeGlobalAddress_ipv6(t *testing.T) { t.Parallel() - var addr compute.Address - resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -24,11 +22,6 @@ func TestAccComputeGlobalAddress_ipv6(t *testing.T) { Steps: []resource.TestStep{ resource.TestStep{ Config: testAccComputeGlobalAddress_ipv6(), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeGlobalAddressExists( - "google_compute_global_address.foobar", &addr), - testAccCheckComputeGlobalAddressIpVersion("google_compute_global_address.foobar", "IPV6"), - ), }, resource.TestStep{ ResourceName: "google_compute_global_address.foobar", @@ -59,61 +52,6 @@ func TestAccComputeGlobalAddress_internal(t *testing.T) { }) } -func testAccCheckComputeGlobalAddressExists(n string, addr *compute.Address) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No ID is set") - } - - config := testAccProvider.Meta().(*Config) - - found, err := config.clientCompute.GlobalAddresses.Get( - config.Project, rs.Primary.ID).Do() - if err != nil { - return err - } - - if found.Name != rs.Primary.ID { - return fmt.Errorf("Addr not found") - } - - *addr = *found - - return nil - } -} - -func testAccCheckComputeGlobalAddressIpVersion(n, version string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No ID is set") - } - - config := testAccProvider.Meta().(*Config) - - addr, err := config.clientCompute.GlobalAddresses.Get(config.Project, rs.Primary.ID).Do() - if err != nil { - return err - } - - if addr.IpVersion != version { - return fmt.Errorf("Expected IP version to be %s, got %s", version, addr.IpVersion) - } - - return nil - } -} - func testAccComputeGlobalAddress_ipv6() string { return fmt.Sprintf(` resource "google_compute_global_address" "foobar" { diff --git a/third_party/terraform/tests/resource_compute_https_health_check_test.go b/third_party/terraform/tests/resource_compute_https_health_check_test.go index 47edb4062fea..fbb3646ce7a9 100644 --- a/third_party/terraform/tests/resource_compute_https_health_check_test.go +++ b/third_party/terraform/tests/resource_compute_https_health_check_test.go @@ -6,15 +6,11 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - "google.golang.org/api/compute/v1" ) func TestAccComputeHttpsHealthCheck_update(t *testing.T) { t.Parallel() - var healthCheck compute.HttpsHealthCheck - hhckName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) resource.Test(t, resource.TestCase{ @@ -24,83 +20,24 @@ func TestAccComputeHttpsHealthCheck_update(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccComputeHttpsHealthCheck_update1(hhckName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeHttpsHealthCheckExists( - "google_compute_https_health_check.foobar", &healthCheck), - testAccCheckComputeHttpsHealthCheckRequestPath( - "/not_default", &healthCheck), - testAccCheckComputeHttpsHealthCheckThresholds( - 2, 2, &healthCheck), - ), + }, + { + ResourceName: "google_compute_https_health_check.foobar", + ImportState: true, + ImportStateVerify: true, }, { Config: testAccComputeHttpsHealthCheck_update2(hhckName), - Check: resource.ComposeTestCheckFunc( - testAccCheckComputeHttpsHealthCheckExists( - "google_compute_https_health_check.foobar", &healthCheck), - testAccCheckComputeHttpsHealthCheckRequestPath( - "/", &healthCheck), - testAccCheckComputeHttpsHealthCheckThresholds( - 10, 10, &healthCheck), - ), + }, + { + ResourceName: "google_compute_https_health_check.foobar", + ImportState: true, + ImportStateVerify: true, }, }, }) } -func testAccCheckComputeHttpsHealthCheckExists(n string, healthCheck *compute.HttpsHealthCheck) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No ID is set") - } - - config := testAccProvider.Meta().(*Config) - - found, err := config.clientCompute.HttpsHealthChecks.Get( - config.Project, rs.Primary.ID).Do() - if err != nil { - return err - } - - if found.Name != rs.Primary.ID { - return fmt.Errorf("HttpsHealthCheck not found") - } - - *healthCheck = *found - - return nil - } -} - -func testAccCheckComputeHttpsHealthCheckRequestPath(path string, healthCheck *compute.HttpsHealthCheck) resource.TestCheckFunc { - return func(s *terraform.State) error { - if healthCheck.RequestPath != path { - return fmt.Errorf("RequestPath doesn't match: expected %s, got %s", path, healthCheck.RequestPath) - } - - return nil - } -} - -func testAccCheckComputeHttpsHealthCheckThresholds(healthy, unhealthy int64, healthCheck *compute.HttpsHealthCheck) resource.TestCheckFunc { - return func(s *terraform.State) error { - if healthCheck.HealthyThreshold != healthy { - return fmt.Errorf("HealthyThreshold doesn't match: expected %d, got %d", healthy, healthCheck.HealthyThreshold) - } - - if healthCheck.UnhealthyThreshold != unhealthy { - return fmt.Errorf("UnhealthyThreshold doesn't match: expected %d, got %d", unhealthy, healthCheck.UnhealthyThreshold) - } - - return nil - } -} - func testAccComputeHttpsHealthCheck_update1(hhckName string) string { return fmt.Sprintf(` resource "google_compute_https_health_check" "foobar" { From 38796a4095d18f1c5da32f062500070cddd7ddd9 Mon Sep 17 00:00:00 2001 From: megan07 Date: Tue, 22 Oct 2019 13:56:36 -0500 Subject: [PATCH 13/16] add forcenew on shielded instance config (#2509) Merged PR #2509. --- build/terraform | 2 +- build/terraform-beta | 2 +- .../resource_container_node_pool_test.go.erb | 30 ------------------- .../terraform/utils/node_config.go.erb | 3 ++ 4 files changed, 5 insertions(+), 32 deletions(-) diff --git a/build/terraform b/build/terraform index 215cca14609f..e1b5947daaa5 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit 215cca14609fdd8dcd86624b6d5344dfeeaf9b05 +Subproject commit e1b5947daaa56cdffb3f26a0b0f0ff5f55822abd diff --git a/build/terraform-beta b/build/terraform-beta index 8d85b10b3fa6..dfa84059bdcc 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit 8d85b10b3fa61b0dd85f7ea2fadb54c5e80233b7 +Subproject commit dfa84059bdcc539ccb3d0640e27a4bf9aa4fcfda diff --git a/third_party/terraform/tests/resource_container_node_pool_test.go.erb b/third_party/terraform/tests/resource_container_node_pool_test.go.erb index b82b5e88b2e9..16cd9d0ab112 100644 --- a/third_party/terraform/tests/resource_container_node_pool_test.go.erb +++ b/third_party/terraform/tests/resource_container_node_pool_test.go.erb @@ -669,15 +669,6 @@ func TestAccContainerNodePool_shieldedInstanceConfig(t *testing.T) { ImportStateVerify: true, ImportStateVerifyIgnore: []string{"max_pods_per_node"}, }, - resource.TestStep{ - Config: testAccContainerNodePool_updateShieldedInstanceConfig(cluster, np), - }, - resource.TestStep{ - ResourceName: "google_container_node_pool.np", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"max_pods_per_node"}, - }, }, }) } @@ -1470,28 +1461,7 @@ resource "google_container_node_pool" "np" { node_config { shielded_instance_config { enable_integrity_monitoring = true - } - } -}`, cluster, np) -} - -func testAccContainerNodePool_updateShieldedInstanceConfig(cluster, np string) string { - return fmt.Sprintf(` -resource "google_container_cluster" "cluster" { - name = "%s" - location = "us-central1-a" - initial_node_count = 1 -} - -resource "google_container_node_pool" "np" { - name = "%s" - location = "us-central1-a" - cluster = "${google_container_cluster.cluster.name}" - initial_node_count = 2 - node_config { - shielded_instance_config { enable_secure_boot = true - enable_integrity_monitoring = true } } }`, cluster, np) diff --git a/third_party/terraform/utils/node_config.go.erb b/third_party/terraform/utils/node_config.go.erb index 10cead014348..b966d11d4ba6 100644 --- a/third_party/terraform/utils/node_config.go.erb +++ b/third_party/terraform/utils/node_config.go.erb @@ -152,17 +152,20 @@ var schemaNodeConfig = &schema.Schema{ Type: schema.TypeList, Optional: true, Computed: true, + ForceNew: true, MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "enable_secure_boot": { Type: schema.TypeBool, Optional: true, + ForceNew: true, Default: false, }, "enable_integrity_monitoring": { Type: schema.TypeBool, Optional: true, + ForceNew: true, Default: true, }, }, From 211fc75fea1cf228ce5d4a2064c2929466eefb44 Mon Sep 17 00:00:00 2001 From: Riley Karson Date: Tue, 22 Oct 2019 12:27:06 -0700 Subject: [PATCH 14/16] Fix version behaviour in `google_compute_instance_group` (#2506) Merged PR #2506. --- build/terraform-mapper | 2 +- .../resource_compute_instance_group.go | 9 ++--- .../resources/resource_compute_target_pool.go | 30 ----------------- third_party/terraform/utils/utils.go.erb | 33 +++++++++++++++++++ 4 files changed, 39 insertions(+), 35 deletions(-) diff --git a/build/terraform-mapper b/build/terraform-mapper index 4700f1232f79..0813eaf03ce9 160000 --- a/build/terraform-mapper +++ b/build/terraform-mapper @@ -1 +1 @@ -Subproject commit 4700f1232f799d729d3422bb3e51055522ec4fb0 +Subproject commit 0813eaf03ce98bc18dc20760956b59101044e98a diff --git a/third_party/terraform/resources/resource_compute_instance_group.go b/third_party/terraform/resources/resource_compute_instance_group.go index 176a16a2518e..4ff3a889e2ef 100644 --- a/third_party/terraform/resources/resource_compute_instance_group.go +++ b/third_party/terraform/resources/resource_compute_instance_group.go @@ -71,10 +71,11 @@ func resourceComputeInstanceGroup() *schema.Resource { }, "network": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + Computed: true, + DiffSuppressFunc: compareSelfLinkOrResourceName, + ForceNew: true, }, "project": { diff --git a/third_party/terraform/resources/resource_compute_target_pool.go b/third_party/terraform/resources/resource_compute_target_pool.go index cc25a52f21a8..9596bd944c16 100644 --- a/third_party/terraform/resources/resource_compute_target_pool.go +++ b/third_party/terraform/resources/resource_compute_target_pool.go @@ -216,36 +216,6 @@ func resourceComputeTargetPoolCreate(d *schema.ResourceData, meta interface{}) e return resourceComputeTargetPoolRead(d, meta) } -func calcAddRemove(from []string, to []string) ([]string, []string) { - add := make([]string, 0) - remove := make([]string, 0) - for _, u := range to { - found := false - for _, v := range from { - if u == v { - found = true - break - } - } - if !found { - add = append(add, u) - } - } - for _, u := range from { - found := false - for _, v := range to { - if u == v { - found = true - break - } - } - if !found { - remove = append(remove, u) - } - } - return add, remove -} - func resourceComputeTargetPoolUpdate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) diff --git a/third_party/terraform/utils/utils.go.erb b/third_party/terraform/utils/utils.go.erb index f8544ed0970f..1da2266b4d18 100644 --- a/third_party/terraform/utils/utils.go.erb +++ b/third_party/terraform/utils/utils.go.erb @@ -542,3 +542,36 @@ func getInterconnectAttachmentLink(config *Config, project, region, ic string) ( return ic, nil } + +// Given two sets of references (with "from" values in self link form), +// determine which need to be added or removed // during an update using +// addX/removeX APIs. +func calcAddRemove(from []string, to []string) (add, remove []string) { + add = make([]string, 0) + remove = make([]string, 0) + for _, u := range to { + found := false + for _, v := range from { + if compareSelfLinkOrResourceName("", v, u, nil) { + found = true + break + } + } + if !found { + add = append(add, u) + } + } + for _, u := range from { + found := false + for _, v := range to { + if compareSelfLinkOrResourceName("", u, v, nil) { + found = true + break + } + } + if !found { + remove = append(remove, u) + } + } + return add, remove +} From ab2fe78d8a3666cc42bd3038aecd424d1f22f21b Mon Sep 17 00:00:00 2001 From: Denis Date: Tue, 22 Oct 2019 21:44:31 +0200 Subject: [PATCH 15/16] Fix erronous lowercase c character (#2490) Merged PR #2490. --- build/ansible | 2 +- provider/ansible/documentation.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/ansible b/build/ansible index e0d101beccb2..86c26c93c9b2 160000 --- a/build/ansible +++ b/build/ansible @@ -1 +1 @@ -Subproject commit e0d101beccb2e021491ee749bde49dce1c5f0235 +Subproject commit 86c26c93c9b2a0ed3b181392fd5570696b047cf8 diff --git a/provider/ansible/documentation.rb b/provider/ansible/documentation.rb index 91dc59050a09..1232ec49eaae 100644 --- a/provider/ansible/documentation.rb +++ b/provider/ansible/documentation.rb @@ -168,8 +168,8 @@ def auth_docs # Notes related to authentication def auth_notes [ - 'for authentication, you can set service_account_file using the c(gcp_service_account_file) env variable.', - 'for authentication, you can set service_account_contents using the c(GCP_SERVICE_ACCOUNT_CONTENTS) env variable.', + 'for authentication, you can set service_account_file using the C(gcp_service_account_file) env variable.', + 'for authentication, you can set service_account_contents using the C(GCP_SERVICE_ACCOUNT_CONTENTS) env variable.', 'For authentication, you can set service_account_email using the C(GCP_SERVICE_ACCOUNT_EMAIL) env variable.', 'For authentication, you can set auth_kind using the C(GCP_AUTH_KIND) env variable.', 'For authentication, you can set scopes using the C(GCP_SCOPES) env variable.', From 28c2961f1345382d4359ad0ec6ed36bbfeadae53 Mon Sep 17 00:00:00 2001 From: Sam Levenick Date: Tue, 22 Oct 2019 13:30:04 -0700 Subject: [PATCH 16/16] Add support for compute_router_nat to inspec (#2510) Merged PR #2510. --- build/inspec | 2 +- products/compute/api.yaml | 1 + products/compute/inspec.yaml | 2 -- .../google_compute_router_nat.erb | 16 ++++++++++++++++ .../google_compute_router_nat_attributes.erb | 4 ++++ .../google_compute_router_nats.erb | 7 +++++++ .../inspec/tests/integration/build/gcp-mm.tf | 19 +++++++++++++++++++ .../configuration/mm-attributes.yml | 10 +++++++++- 8 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 templates/inspec/examples/google_compute_router_nat/google_compute_router_nat.erb create mode 100644 templates/inspec/examples/google_compute_router_nat/google_compute_router_nat_attributes.erb create mode 100644 templates/inspec/examples/google_compute_router_nat/google_compute_router_nats.erb diff --git a/build/inspec b/build/inspec index 179cd115de4d..3b9afb35284f 160000 --- a/build/inspec +++ b/build/inspec @@ -1 +1 @@ -Subproject commit 179cd115de4dc78342a1b10a6d278e0e4fd88d65 +Subproject commit 3b9afb35284fdc2a6be0c6e831a757d935fdca0d diff --git a/products/compute/api.yaml b/products/compute/api.yaml index 0582c47e414b..efcad11866a5 100644 --- a/products/compute/api.yaml +++ b/products/compute/api.yaml @@ -7720,6 +7720,7 @@ objects: delete_verb: :PATCH identity: - name + collection_url_key: nats nested_query: !ruby/object:Api::Resource::NestedQuery modify_by_patch: true keys: diff --git a/products/compute/inspec.yaml b/products/compute/inspec.yaml index 53b1e8839916..1a6b8c03d695 100644 --- a/products/compute/inspec.yaml +++ b/products/compute/inspec.yaml @@ -80,8 +80,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides exclude: true ResourcePolicy: !ruby/object:Overrides::Inspec::ResourceOverride exclude: true - RouterNat: !ruby/object:Overrides::Inspec::ResourceOverride - exclude: true Subnetwork: !ruby/object:Overrides::Inspec::ResourceOverride exclude_resource: true iam_policy: !ruby/object:Api::Resource::IamPolicy diff --git a/templates/inspec/examples/google_compute_router_nat/google_compute_router_nat.erb b/templates/inspec/examples/google_compute_router_nat/google_compute_router_nat.erb new file mode 100644 index 000000000000..89f3a5539cd6 --- /dev/null +++ b/templates/inspec/examples/google_compute_router_nat/google_compute_router_nat.erb @@ -0,0 +1,16 @@ +<% gcp_project_id = "#{external_attribute('gcp_project_id', doc_generation)}" -%> +<% gcp_location = "#{external_attribute('gcp_location', doc_generation)}" -%> +<% router = grab_attributes['router'] -%> +<% router_nat = grab_attributes['router_nat'] -%> +describe google_compute_router_nat(project: <%= gcp_project_id -%>, region: <%= gcp_location -%>, router: <%= doc_generation ? "'#{router['name']}'" : "router['name']" -%>, name: <%= doc_generation ? "'#{router_nat['name']}'" : "router_nat['name']" -%>) do + it { should exist } + its('nat_ip_allocate_option') { should cmp <%= doc_generation ? "'#{router_nat['nat_ip_allocate_option']}'" : "router_nat['nat_ip_allocate_option']" -%> } + its('source_subnetwork_ip_ranges_to_nat') { should cmp <%= doc_generation ? "'#{router_nat['source_subnetwork_ip_ranges_to_nat']}'" : "router_nat['source_subnetwork_ip_ranges_to_nat']" -%> } + its('min_ports_per_vm') { should cmp <%= doc_generation ? "'#{router_nat['min_ports_per_vm']}'" : "router_nat['min_ports_per_vm']" -%> } + its('log_config.enable') { should cmp <%= doc_generation ? "'#{router_nat['log_config_enable']}'" : "router_nat['log_config_enable']" -%> } + its('log_config.filter') { should cmp <%= doc_generation ? "'#{router_nat['log_config_filter']}'" : "router_nat['log_config_filter']" -%> } +end + +describe google_compute_router(project: <%= gcp_project_id -%>, region: <%= gcp_location -%>, router: 'nonexistent', name: 'nonexistent') do + it { should_not exist } +end \ No newline at end of file diff --git a/templates/inspec/examples/google_compute_router_nat/google_compute_router_nat_attributes.erb b/templates/inspec/examples/google_compute_router_nat/google_compute_router_nat_attributes.erb new file mode 100644 index 000000000000..bfada640e1dc --- /dev/null +++ b/templates/inspec/examples/google_compute_router_nat/google_compute_router_nat_attributes.erb @@ -0,0 +1,4 @@ +gcp_project_id = attribute(:gcp_project_id, default: '<%= external_attribute('gcp_project_id') -%>', description: 'The GCP project identifier.') +gcp_location = attribute(:gcp_location, default: '<%= external_attribute('gcp_location') -%>', description: 'The GCP project region.') +router = attribute('router', default: <%= JSON.pretty_generate(grab_attributes['router']) -%>, description: 'Compute router description') +router_nat = attribute('router_nat', default: <%= JSON.pretty_generate(grab_attributes['router_nat']) -%>, description: 'Compute router NAT description') diff --git a/templates/inspec/examples/google_compute_router_nat/google_compute_router_nats.erb b/templates/inspec/examples/google_compute_router_nat/google_compute_router_nats.erb new file mode 100644 index 000000000000..13e0e53ad843 --- /dev/null +++ b/templates/inspec/examples/google_compute_router_nat/google_compute_router_nats.erb @@ -0,0 +1,7 @@ +<% gcp_project_id = "#{external_attribute('gcp_project_id', doc_generation)}" -%> +<% gcp_location = "#{external_attribute('gcp_location', doc_generation)}" -%> +<% router = grab_attributes['router'] -%> +<% router_nat = grab_attributes['router_nat'] -%> +describe google_compute_router_nats(project: <%= gcp_project_id -%>, region: <%= gcp_location -%>, router: <%= doc_generation ? "'#{router['name']}'" : "router['name']" -%>) do + its('names') { should include <%= doc_generation ? "'#{router_nat['name']}'" : "router_nat['name']" -%> } +end \ No newline at end of file diff --git a/templates/inspec/tests/integration/build/gcp-mm.tf b/templates/inspec/tests/integration/build/gcp-mm.tf index d03e10dce3b2..4e9619e09d48 100644 --- a/templates/inspec/tests/integration/build/gcp-mm.tf +++ b/templates/inspec/tests/integration/build/gcp-mm.tf @@ -193,6 +193,10 @@ variable "node_group" { type = "map" } +variable "router_nat" { + type = "map" +} + resource "google_compute_ssl_policy" "custom-ssl-policy" { name = "${var.ssl_policy["name"]}" min_tls_version = "${var.ssl_policy["min_tls_version"]}" @@ -838,3 +842,18 @@ resource "google_compute_node_group" "inspec-node-group" { size = var.node_group["size"] node_template = "${google_compute_node_template.inspec-template.self_link}" } + +resource "google_compute_router_nat" "inspec-nat" { + project = var.gcp_project_id + name = var.router_nat["name"] + router = google_compute_router.gcp-inspec-router.name + region = google_compute_router.gcp-inspec-router.region + nat_ip_allocate_option = var.router_nat["nat_ip_allocate_option"] + source_subnetwork_ip_ranges_to_nat = var.router_nat["source_subnetwork_ip_ranges_to_nat"] + min_ports_per_vm = var.router_nat["min_ports_per_vm"] + + log_config { + enable = var.router_nat["log_config_enable"] + filter = var.router_nat["log_config_filter"] + } +} diff --git a/templates/inspec/tests/integration/configuration/mm-attributes.yml b/templates/inspec/tests/integration/configuration/mm-attributes.yml index 92b6cfdcba4d..89aabf593b47 100644 --- a/templates/inspec/tests/integration/configuration/mm-attributes.yml +++ b/templates/inspec/tests/integration/configuration/mm-attributes.yml @@ -315,4 +315,12 @@ node_template: node_group: name: inspec-node-group description: A description of the node group - size: 0 \ No newline at end of file + size: 0 + +router_nat: + name: inspec-router-nat + nat_ip_allocate_option: AUTO_ONLY + source_subnetwork_ip_ranges_to_nat: ALL_SUBNETWORKS_ALL_IP_RANGES + min_ports_per_vm: 2 + log_config_enable: true + log_config_filter: ERRORS_ONLY \ No newline at end of file