From 97a4f962a6038c4fefac1da63a54237b4eced038 Mon Sep 17 00:00:00 2001 From: Riley Karson Date: Mon, 4 Mar 2019 14:33:00 -0800 Subject: [PATCH] Versioned OiCS Examples / Generated tests (#1464) Merged PR #1464. --- build/terraform | 2 +- build/terraform-beta | 2 +- compiler.rb | 2 +- products/accesscontextmanager/terraform.yaml | 3 - products/appengine/terraform.yaml | 1 - products/cloudbuild/terraform.yaml | 1 - products/cloudscheduler/terraform.yaml | 3 - products/compute/terraform.yaml | 50 +++++------- products/containeranalysis/terraform.yaml | 1 - products/dns/terraform.yaml | 3 - products/filestore/terraform.yaml | 1 - products/monitoring/terraform.yaml | 6 -- products/pubsub/terraform.yaml | 4 - products/redis/terraform.yaml | 2 - products/resourcemanager/terraform.yaml | 1 - products/sourcerepo/terraform.yaml | 1 - products/spanner/terraform.yaml | 2 - provider/terraform.rb | 8 +- provider/terraform/custom_code.rb | 15 ++-- provider/terraform_example.rb | 5 +- .../examples/autoscaler_basic.tf.erb | 8 +- .../terraform/examples/autoscaler_beta.tf.erb | 76 +++++++++++++++++++ .../examples/base_configs/test_file.go.erb | 25 +++++- .../container_analysis_note_basic.tf.erb | 7 ++ .../examples/filestore_instance_basic.tf.erb | 7 ++ .../managed_ssl_certificate_basic.tf.erb | 21 +++++ .../examples/region_autoscaler_basic.tf.erb | 8 +- .../examples/region_autoscaler_beta.tf.erb | 76 +++++++++++++++++++ .../examples/scheduler_job_app_engine.tf.erb | 9 ++- .../examples/scheduler_job_http.tf.erb | 9 ++- .../examples/scheduler_job_pubsub.tf.erb | 9 +++ .../terraform/resource.html.markdown.erb | 2 + ...{provider_test.go => provider_test.go.erb} | 19 +++++ 33 files changed, 297 insertions(+), 92 deletions(-) create mode 100644 templates/terraform/examples/autoscaler_beta.tf.erb create mode 100644 templates/terraform/examples/region_autoscaler_beta.tf.erb rename third_party/terraform/utils/{provider_test.go => provider_test.go.erb} (89%) diff --git a/build/terraform b/build/terraform index 7bb50039187c..ca0866a1b690 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit 7bb50039187ce6dd7c9c28d9d6d946264931a9da +Subproject commit ca0866a1b690130386a235b7a24a7904beb98bb2 diff --git a/build/terraform-beta b/build/terraform-beta index b134997140b1..c34fa6de21b2 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit b134997140b196184cd0d746dbcedab7636d03cf +Subproject commit c34fa6de21b20a0f23307756336f9d2f67b89311 diff --git a/compiler.rb b/compiler.rb index 2d575addf817..71f497610fb3 100755 --- a/compiler.rb +++ b/compiler.rb @@ -111,7 +111,7 @@ raise "Output path '#{output_path}' does not exist or is not a directory" \ unless Dir.exist?(output_path) - Google::LOGGER.info "Compiling '#{product_name}' output to '#{output_path}'" + Google::LOGGER.info "Compiling '#{product_name}' (at #{version}) output to '#{output_path}'" Google::LOGGER.info \ "Generating types: #{types_to_generate.empty? ? 'ALL' : types_to_generate}" diff --git a/products/accesscontextmanager/terraform.yaml b/products/accesscontextmanager/terraform.yaml index 264893c62508..d5b9bf161222 100644 --- a/products/accesscontextmanager/terraform.yaml +++ b/products/accesscontextmanager/terraform.yaml @@ -20,7 +20,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides name: "access_context_manager_access_policy_basic" skip_test: true primary_resource_id: "access-policy" - version: <%= version_name %> properties: name: !ruby/object:Overrides::Terraform::PropertyOverride custom_flatten: templates/terraform/custom_flatten/name_from_self_link.erb @@ -36,7 +35,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides name: "access_context_manager_access_level_basic" skip_test: true primary_resource_id: "access-level" - version: <%= version_name %> vars: access_level_name: "ios_no_lock" properties: @@ -55,7 +53,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides name: "access_context_manager_service_perimeter_basic" skip_test: true primary_resource_id: "service-perimeter" - version: <%= version_name %> vars: access_level_name: "ios_no_lock" service_perimeter_name: "restrict_all" diff --git a/products/appengine/terraform.yaml b/products/appengine/terraform.yaml index 36b1b38d1d70..6d7a019a2a16 100644 --- a/products/appengine/terraform.yaml +++ b/products/appengine/terraform.yaml @@ -20,7 +20,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "app_engine_firewall_rule_basic" primary_resource_id: "rule" - version: <%= version_name %> vars: project_id: "test-project" test_env_vars: diff --git a/products/cloudbuild/terraform.yaml b/products/cloudbuild/terraform.yaml index 9605fe57a24a..132d5a7ee1f5 100644 --- a/products/cloudbuild/terraform.yaml +++ b/products/cloudbuild/terraform.yaml @@ -23,7 +23,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "cloudbuild_trigger_filename" primary_resource_id: "filename-trigger" - version: <%= version_name %> properties: id: !ruby/object:Overrides::Terraform::PropertyOverride name: 'trigger_id' diff --git a/products/cloudscheduler/terraform.yaml b/products/cloudscheduler/terraform.yaml index 3c13484333a5..e9a85d6c0c2d 100644 --- a/products/cloudscheduler/terraform.yaml +++ b/products/cloudscheduler/terraform.yaml @@ -18,20 +18,17 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "scheduler_job_pubsub" primary_resource_id: "job" - version: <%= version_name %> vars: job_name: "test-job" topic_name: "job-topic" - !ruby/object:Provider::Terraform::Examples name: "scheduler_job_http" primary_resource_id: "job" - version: <%= version_name %> vars: job_name: "test-job" - !ruby/object:Provider::Terraform::Examples name: "scheduler_job_app_engine" primary_resource_id: "job" - version: <%= version_name %> vars: job_name: "test-job" properties: diff --git a/products/compute/terraform.yaml b/products/compute/terraform.yaml index 27e7decd8e5a..62acdbcc5518 100644 --- a/products/compute/terraform.yaml +++ b/products/compute/terraform.yaml @@ -19,13 +19,11 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "address_basic" primary_resource_id: "ip_address" - version: <%= version_name %> vars: address_name: "my-address" - !ruby/object:Provider::Terraform::Examples name: "address_with_subnetwork" primary_resource_id: "internal_with_subnet_and_address" - version: <%= version_name %> vars: address_name: "my-internal-address" network_name: "my-network" @@ -34,7 +32,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "instance_with_ip" primary_resource_id: "static" - version: <%= version_name %> vars: address_name: "ipv4-address" instance_name: "vm-instance" @@ -69,10 +66,18 @@ overrides: !ruby/object:Overrides::ResourceOverrides Autoscaler: !ruby/object:Overrides::Terraform::ResourceOverride id_format: "{{zone}}/{{name}}" examples: + - !ruby/object:Provider::Terraform::Examples + name: "autoscaler_beta" + primary_resource_id: "foobar" + min_version: 'beta' + vars: + autoscaler_name: "my-autoscaler" + instance_template_name: "my-instance-template" + target_pool_name: "my-target-pool" + igm_name: "my-igm" - !ruby/object:Provider::Terraform::Examples name: "autoscaler_basic" primary_resource_id: "foobar" - version: <%= version_name %> vars: autoscaler_name: "my-autoscaler" instance_template_name: "my-instance-template" @@ -124,7 +129,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "backend_bucket_basic" primary_resource_id: "image_backend" - version: <%= version_name %> vars: backend_bucket_name: "image-backend-bucket" bucket_name: "image-store-bucket" @@ -213,7 +217,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "disk_basic" primary_resource_id: "default" - version: <%= version_name %> vars: disk_name: "test-disk" DiskType: !ruby/object:Overrides::Terraform::ResourceOverride @@ -223,7 +226,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "firewall_basic" primary_resource_id: "default" - version: <%= version_name %> vars: firewall_name: "test-firewall" network_name: "test-network" @@ -280,7 +282,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "forwarding_rule_basic" primary_resource_id: "default" - version: <%= version_name %> vars: forwarding_rule_name: "website-forwarding-rule" target_pool_name: "website-target-pool" @@ -329,7 +330,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "global_address_basic" primary_resource_id: "default" - version: <%= version_name %> vars: global_address_name: "global-appserver-ip" properties: @@ -362,7 +362,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "http_health_check_basic" primary_resource_id: "default" - version: <%= version_name %> vars: http_health_check_name: "authentication-health-check" properties: @@ -393,7 +392,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "https_health_check_basic" primary_resource_id: "default" - version: <%= version_name %> vars: https_health_check_name: "authentication-health-check" properties: @@ -416,7 +414,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "health_check_basic" primary_resource_id: "internal-health-check" - version: <%= version_name %> vars: health_check_name: "internal-service-health-check" custom_code: !ruby/object:Provider::Terraform::CustomCode @@ -448,7 +445,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "image_basic" primary_resource_id: "example" - version: <%= version_name %> vars: image_name: "example-image" properties: @@ -505,7 +501,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides name: "interconnect_attachment_basic" primary_resource_id: "on_prem" skip_test: true - version: <%= version_name %> vars: interconnect_attachment_name: "on-prem-attachment" router_name: "router" @@ -520,10 +515,18 @@ overrides: !ruby/object:Overrides::ResourceOverrides RegionAutoscaler: !ruby/object:Overrides::Terraform::ResourceOverride id_format: "{{region}}/{{name}}" examples: + - !ruby/object:Provider::Terraform::Examples + name: "region_autoscaler_beta" + primary_resource_id: "foobar" + min_version: 'beta' + vars: + region_autoscaler_name: "my-region-autoscaler" + instance_template_name: "my-instance-template" + target_pool_name: "my-target-pool" + rigm_name: "my-region-igm" - !ruby/object:Provider::Terraform::Examples name: "region_autoscaler_basic" primary_resource_id: "foobar" - version: <%= version_name %> vars: region_autoscaler_name: "my-region-autoscaler" instance_template_name: "my-instance-template" @@ -608,7 +611,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "region_disk_basic" primary_resource_id: "regiondisk" - version: <%= version_name %> vars: region_disk_name: "my-region-disk" disk_name: "my-disk" @@ -620,7 +622,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "route_basic" primary_resource_id: "default" - version: <%= version_name %> vars: route_name: "network-route" network_name: "compute-network" @@ -675,7 +676,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "router_basic" primary_resource_id: "foobar" - version: <%= version_name %> vars: router_name: "my-router" network_name: "my-network" @@ -695,7 +695,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "snapshot_basic" primary_resource_id: "snapshot" - version: <%= version_name %> vars: snapshot_name: "my-snapshot" disk_name: "debian-disk" @@ -747,7 +746,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "managed_ssl_certificate_basic" primary_resource_id: "default" - version: <%= version_name %> vars: cert_name: "test-cert" proxy_name: "test-proxy" @@ -778,17 +776,14 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "ssl_certificate_basic" primary_resource_id: "default" - version: <%= version_name %> ignore_read_extra: - "name_prefix" - !ruby/object:Provider::Terraform::Examples name: "ssl_certificate_random_provider" primary_resource_id: "default" - version: <%= version_name %> - !ruby/object:Provider::Terraform::Examples name: "ssl_certificate_target_https_proxies" primary_resource_id: "default" - version: <%= version_name %> vars: target_https_proxy_name: "test-proxy" url_map_name: "url-map" @@ -822,7 +817,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "ssl_policy_basic" primary_resource_id: "prod-ssl-policy" - version: <%= version_name %> vars: production_ssl_policy_name: "production-ssl-policy" nonprod_ssl_policy_name: "nonprod-ssl-policy" @@ -900,7 +894,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "subnetwork_basic" primary_resource_id: "network-with-private-secondary-ip-ranges" - version: <%= version_name %> vars: subnetwork_name: "test-subnetwork" network_name: "test-network" @@ -909,7 +902,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "target_http_proxy_basic" primary_resource_id: "default" - version: <%= version_name %> vars: target_http_proxy_name: "test-proxy" url_map_name: "url-map" @@ -923,7 +915,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "target_https_proxy_basic" primary_resource_id: "default" - version: <%= version_name %> vars: target_https_proxy_name: "test-proxy" ssl_certificate_name: "my-certificate" @@ -949,7 +940,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "target_ssl_proxy_basic" primary_resource_id: "default" - version: <%= version_name %> vars: target_ssl_proxy_name: "test-proxy" ssl_certificate_name: "default-cert" @@ -967,7 +957,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "target_tcp_proxy_basic" primary_resource_id: "default" - version: <%= version_name %> vars: target_tcp_proxy_name: "test-proxy" backend_service_name: "backend-service" @@ -985,7 +974,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "target_vpn_gateway_basic" primary_resource_id: "target_gateway" - version: <%= version_name %> vars: target_vpn_gateway_name: "vpn1" network_name: "network1" @@ -1011,7 +999,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "url_map_basic" primary_resource_id: "urlmap" - version: <%= version_name %> vars: url_map_name: "urlmap" login_backend_service_name: "login" @@ -1052,7 +1039,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "vpn_tunnel_basic" primary_resource_id: "tunnel1" - version: <%= version_name %> vars: vpn_tunnel_name: "tunnel1" target_vpn_gateway_name: "vpn1" diff --git a/products/containeranalysis/terraform.yaml b/products/containeranalysis/terraform.yaml index c3c27d3946bd..56ff17be8689 100644 --- a/products/containeranalysis/terraform.yaml +++ b/products/containeranalysis/terraform.yaml @@ -21,7 +21,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "container_analysis_note_basic" primary_resource_id: "note" - version: <%= version_name %> vars: note_name: "test-attestor-note" properties: diff --git a/products/dns/terraform.yaml b/products/dns/terraform.yaml index 29f64c7fb320..d3774649d97e 100644 --- a/products/dns/terraform.yaml +++ b/products/dns/terraform.yaml @@ -18,11 +18,9 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "dns_managed_zone_basic" primary_resource_id: "example-zone" - version: <%= version_name %> - !ruby/object:Provider::Terraform::Examples name: "dns_managed_zone_private" primary_resource_id: "private-zone" - version: <%= version_name %> skip_test: true vars: zone_name: "private-zone" @@ -78,7 +76,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "dns_policy_basic" primary_resource_id: "example-policy" - version: <%= version_name %> vars: policy_name: "example-policy" network_1_name: "network-1" diff --git a/products/filestore/terraform.yaml b/products/filestore/terraform.yaml index 4a57364193d6..dee75b295958 100644 --- a/products/filestore/terraform.yaml +++ b/products/filestore/terraform.yaml @@ -20,7 +20,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "filestore_instance_basic" primary_resource_id: "instance" - version: <%= version_name %> vars: instance_name: "test-instance" properties: diff --git a/products/monitoring/terraform.yaml b/products/monitoring/terraform.yaml index 797e7adda1e5..0c4adb1550ec 100644 --- a/products/monitoring/terraform.yaml +++ b/products/monitoring/terraform.yaml @@ -20,7 +20,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "monitoring_alert_policy_basic" primary_resource_id: "alert_policy" - version: <%= version_name %> vars: alert_policy_display_name: "My Alert Policy" custom_code: !ruby/object:Provider::Terraform::CustomCode @@ -34,13 +33,11 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "monitoring_group_basic" primary_resource_id: "basic" - version: <%= version_name %> vars: display_name: "New Test Group" - !ruby/object:Provider::Terraform::Examples name: "monitoring_group_subgroup" primary_resource_id: "subgroup" - version: <%= version_name %> vars: display_name: "New Test SubGroup" display_name2: "New Test SubGroup" @@ -57,7 +54,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides mutex: stackdriver/notifications/{{project}} examples: - !ruby/object:Provider::Terraform::Examples - version: <%= version_name %> name: "notification_channel_basic" primary_resource_id: "basic" vars: @@ -88,13 +84,11 @@ overrides: !ruby/object:Overrides::ResourceOverrides import_format: ["{{name}}"] examples: - !ruby/object:Provider::Terraform::Examples - version: <%= version_name %> name: "uptime_check_config_http" primary_resource_id: "http" vars: display_name: "http-uptime-check" - !ruby/object:Provider::Terraform::Examples - version: <%= version_name %> name: "uptime_check_tcp" primary_resource_id: "tcp_group" vars: diff --git a/products/pubsub/terraform.yaml b/products/pubsub/terraform.yaml index e741130f2044..ede9b3d223f3 100644 --- a/products/pubsub/terraform.yaml +++ b/products/pubsub/terraform.yaml @@ -19,7 +19,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "pubsub_topic_basic" primary_resource_id: "example" - version: <%= version_name %> vars: topic_name: "example-topic" properties: @@ -33,7 +32,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "pubsub_subscription_push" primary_resource_id: "example" - version: <%= version_name %> skip_test: true vars: topic_name: "example-topic" @@ -41,14 +39,12 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "pubsub_subscription_pull" primary_resource_id: "example" - version: <%= version_name %> vars: topic_name: "example-topic" subscription_name: "example-subscription" - !ruby/object:Provider::Terraform::Examples name: "pubsub_subscription_different_project" primary_resource_id: "example" - version: <%= version_name %> skip_test: true vars: topic_name: "example-topic" diff --git a/products/redis/terraform.yaml b/products/redis/terraform.yaml index 9b0397a9b9d8..db6982d84a1a 100644 --- a/products/redis/terraform.yaml +++ b/products/redis/terraform.yaml @@ -21,13 +21,11 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "redis_instance_basic" primary_resource_id: "cache" - version: <%= version_name %> vars: instance_name: "memory-cache" - !ruby/object:Provider::Terraform::Examples name: "redis_instance_full" primary_resource_id: "cache" - version: <%= version_name %> vars: instance_name: "ha-memory-cache" network_name: "authorized-network" diff --git a/products/resourcemanager/terraform.yaml b/products/resourcemanager/terraform.yaml index 723d4e1d36f3..d6d42c95a400 100644 --- a/products/resourcemanager/terraform.yaml +++ b/products/resourcemanager/terraform.yaml @@ -22,7 +22,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides name: "resource_manager_lien" skip_test: true primary_resource_id: "lien" - version: <%= version_name %> vars: project_id: "staging-project" properties: diff --git a/products/sourcerepo/terraform.yaml b/products/sourcerepo/terraform.yaml index cc58b19e9be0..bd542f8e3450 100644 --- a/products/sourcerepo/terraform.yaml +++ b/products/sourcerepo/terraform.yaml @@ -20,7 +20,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "sourcerepo_repository_basic" primary_resource_id: "my-repo" - version: <%= version_name %> vars: repository_name: "my-repository" properties: diff --git a/products/spanner/terraform.yaml b/products/spanner/terraform.yaml index 726b687aeee3..fa7d29732465 100644 --- a/products/spanner/terraform.yaml +++ b/products/spanner/terraform.yaml @@ -25,7 +25,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "spanner_database_basic" primary_resource_id: "database" - version: <%= version_name %> vars: database_name: "my-database" properties: @@ -54,7 +53,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides - !ruby/object:Provider::Terraform::Examples name: "spanner_instance_basic" primary_resource_id: "example" - version: <%= version_name %> properties: name: !ruby/object:Overrides::Terraform::PropertyOverride description: | diff --git a/provider/terraform.rb b/provider/terraform.rb index adb55e1134fb..3fba9964e681 100644 --- a/provider/terraform.rb +++ b/provider/terraform.rb @@ -142,7 +142,13 @@ def generate_documentation(data) end def generate_resource_tests(data) - return if data[:object].examples.reject(&:skip_test).empty? + return if data[:object].examples + .reject(&:skip_test) + .reject do |e| + @api.version_obj_or_default(data[:version]) \ + < @api.version_obj_or_default(e.min_version) + end + .empty? dir = data[:version] == 'beta' ? 'google-beta' : 'google' target_folder = File.join(data[:output_folder], dir) diff --git a/provider/terraform/custom_code.rb b/provider/terraform/custom_code.rb index 91ca28110958..d60d5bf34252 100644 --- a/provider/terraform/custom_code.rb +++ b/provider/terraform/custom_code.rb @@ -87,8 +87,9 @@ class Examples < Api::Object # This list corresponds to the `get*FromEnv` methods in provider_test.go. attr_reader :test_env_vars - # the version (ga, beta, etc.) this example is being generated at - attr_reader :version + # the version of the example. Note that _all features_ used in an example + # must be set to the example min version. + attr_reader :min_version # Extra properties to ignore read on during import. # These properties will likely be custom code. @@ -113,8 +114,7 @@ def config_documentation { vars: vars, test_env_vars: test_env_vars.map { |k, v| [k, docs_defaults[v]] }.to_h, - primary_resource_id: primary_resource_id, - version: version + primary_resource_id: primary_resource_id }, "templates/terraform/examples/#{name}.tf.erb" )) @@ -131,8 +131,7 @@ def config_test { vars: vars.map { |k, str| [k, "#{str}-%{random_suffix}"] }.to_h, test_env_vars: test_env_vars.map { |k, _| [k, "%{#{k}}"] }.to_h, - primary_resource_id: primary_resource_id, - version: version + primary_resource_id: primary_resource_id }, "templates/terraform/examples/#{name}.tf.erb" )) @@ -154,8 +153,7 @@ def config_example body = lines(compile_file( { vars: vars.map { |k, str| [k, "#{str}-${local.name_suffix}"] }.to_h, - primary_resource_id: primary_resource_id, - version: version + primary_resource_id: primary_resource_id }, "templates/terraform/examples/#{name}.tf.erb" )) @@ -195,6 +193,7 @@ def validate super check :name, type: String, required: true check :primary_resource_id, type: String + check :min_version, type: String check :vars, type: Hash check :test_env_vars, type: Hash check :ignore_read_extra, type: Array, item_type: String, default: [] diff --git a/provider/terraform_example.rb b/provider/terraform_example.rb index 631be5f77dd9..56864e444d01 100644 --- a/provider/terraform_example.rb +++ b/provider/terraform_example.rb @@ -19,15 +19,16 @@ class TerraformExample < Provider::Terraform # We don't want *any* static generation, so we override generate to only # generate objects. def generate(output_folder, types, version_name, _product_path, _dump_yaml) - version = @api.version_obj_or_default(version_name) - generate_objects(output_folder, types, version) + generate_objects(output_folder, types, version_name) end # Create a directory of examples per resource def generate_resource(data) + version = @api.version_obj_or_default(data[:version]) examples = data[:object].examples .reject(&:skip_test) .reject { |e| !e.test_env_vars.nil? && e.test_env_vars.any? } + .reject { |e| version < @api.version_obj_or_default(e.min_version) } examples.each do |example| target_folder = data[:output_folder] diff --git a/templates/terraform/examples/autoscaler_basic.tf.erb b/templates/terraform/examples/autoscaler_basic.tf.erb index 06d3d297d111..316904bf2a79 100644 --- a/templates/terraform/examples/autoscaler_basic.tf.erb +++ b/templates/terraform/examples/autoscaler_basic.tf.erb @@ -46,14 +46,8 @@ resource "google_compute_instance_group_manager" "foobar" { name = "<%= ctx[:vars]['igm_name'] %>" zone = "us-central1-f" -<% if ctx[:version].nil? || ctx[:version] == 'ga' -%> instance_template = "${google_compute_instance_template.foobar.self_link}" -<% else -%> - version { - instance_template = "${google_compute_instance_template.foobar.self_link}" - name = "primary" - } -<% end -%> + target_pools = ["${google_compute_target_pool.foobar.self_link}"] base_instance_name = "foobar" } diff --git a/templates/terraform/examples/autoscaler_beta.tf.erb b/templates/terraform/examples/autoscaler_beta.tf.erb new file mode 100644 index 000000000000..c77422771246 --- /dev/null +++ b/templates/terraform/examples/autoscaler_beta.tf.erb @@ -0,0 +1,76 @@ +resource "google_compute_autoscaler" "foobar" { + provider = "google-beta" + + name = "<%= ctx[:vars]['autoscaler_name'] %>" + zone = "us-central1-f" + target = "${google_compute_instance_group_manager.foobar.self_link}" + + autoscaling_policy { + max_replicas = 5 + min_replicas = 1 + cooldown_period = 60 + + cpu_utilization { + target = 0.5 + } + } +} + +resource "google_compute_instance_template" "foobar" { + provider = "google-beta" + + name = "<%= ctx[:vars]['instance_template_name'] %>" + machine_type = "n1-standard-1" + can_ip_forward = false + + tags = ["foo", "bar"] + + disk { + source_image = "${data.google_compute_image.debian_9.self_link}" + } + + network_interface { + network = "default" + } + + metadata = { + foo = "bar" + } + + service_account { + scopes = ["userinfo-email", "compute-ro", "storage-ro"] + } +} + +resource "google_compute_target_pool" "foobar" { + provider = "google-beta" + + name = "<%= ctx[:vars]['target_pool_name'] %>" +} + +resource "google_compute_instance_group_manager" "foobar" { + provider = "google-beta" + + name = "<%= ctx[:vars]['igm_name'] %>" + zone = "us-central1-f" + + version { + instance_template = "${google_compute_instance_template.foobar.self_link}" + name = "primary" + } + + target_pools = ["${google_compute_target_pool.foobar.self_link}"] + base_instance_name = "foobar" +} + +data "google_compute_image" "debian_9" { + provider = "google-beta" + + family = "debian-9" + project = "debian-cloud" +} + +provider "google-beta"{ + region = "us-central1" + zone = "us-central1-a" +} diff --git a/templates/terraform/examples/base_configs/test_file.go.erb b/templates/terraform/examples/base_configs/test_file.go.erb index a97fdc7468ce..d622b594d3ec 100644 --- a/templates/terraform/examples/base_configs/test_file.go.erb +++ b/templates/terraform/examples/base_configs/test_file.go.erb @@ -17,14 +17,30 @@ else terraform_name = "google_" + @config.legacy_name + '_' + object.name.underscore end %> -<% object.examples.reject(&:skip_test).each do |example| -%> <% +# @api.version_obj_or_default(version) is slightly wrong; we want the _object_ version or the generation version. +# Ultimately this won't matter though, since the API default should always be less than the object default. +object.examples + .reject(&:skip_test) + .reject { |e| @api.version_obj_or_default(version) < @api.version_obj_or_default(e.min_version) } + .each do |example| - + + # {Compute}{Address}_{addressBasic} test_slug = "#{resource_name}_#{example.name.camelize(:lower)}Example" ignore_read = data[:object].all_user_properties .select(&:ignore_read) .map { |p| p.name.underscore } .concat(example.ignore_read_extra) + + + # If we've set an explicit version for the example use that, otherwise use the + # object version. + if example.min_version.nil? + example_version = object.min_version.name + else + example_version = example.min_version + end -%> func TestAcc<%= test_slug -%>(t *testing.T) { @@ -53,12 +69,18 @@ func TestAcc<%= test_slug -%>(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, + <% if example_version == 'ga' -%> Providers: testAccProviders, + <% else -%> + Providers: testAccProvidersOiCS, + <% end -%> CheckDestroy: testAccCheck<%= "#{resource_name}" -%>Destroy, Steps: []resource.TestStep{ { Config: testAcc<%= test_slug -%>(context), }, + <%#- The Terraform test runner doesn't let us import resources with aliased providers (yet) -%> + <% if example_version == 'ga' -%> { ResourceName: "<%= terraform_name -%>.<%= example.primary_resource_id -%>", ImportState: true, @@ -67,6 +89,7 @@ func TestAcc<%= test_slug -%>(t *testing.T) { ImportStateVerifyIgnore: <%= go_literal(ignore_read) %>, <%- end -%> }, + <% end -%> }, }) } diff --git a/templates/terraform/examples/container_analysis_note_basic.tf.erb b/templates/terraform/examples/container_analysis_note_basic.tf.erb index 8d2e9ec6f69d..fa5bdb1e79c4 100644 --- a/templates/terraform/examples/container_analysis_note_basic.tf.erb +++ b/templates/terraform/examples/container_analysis_note_basic.tf.erb @@ -1,4 +1,6 @@ resource "google_container_analysis_note" "<%= ctx[:primary_resource_id] %>" { + provider = "google-beta" + name = "<%= ctx[:vars]["note_name"] %>" attestation_authority { hint { @@ -6,3 +8,8 @@ resource "google_container_analysis_note" "<%= ctx[:primary_resource_id] %>" { } } } + +provider "google-beta"{ + region = "us-central1" + zone = "us-central1-a" +} diff --git a/templates/terraform/examples/filestore_instance_basic.tf.erb b/templates/terraform/examples/filestore_instance_basic.tf.erb index 675c6e7d52c8..1f7f3b358de6 100644 --- a/templates/terraform/examples/filestore_instance_basic.tf.erb +++ b/templates/terraform/examples/filestore_instance_basic.tf.erb @@ -1,4 +1,6 @@ resource "google_filestore_instance" "<%= ctx[:primary_resource_id] %>" { + provider = "google-beta" + name = "<%= ctx[:vars]["instance_name"] %>" zone = "us-central1-b" tier = "PREMIUM" @@ -13,3 +15,8 @@ resource "google_filestore_instance" "<%= ctx[:primary_resource_id] %>" { modes = ["MODE_IPV4"] } } + +provider "google-beta"{ + region = "us-central1" + zone = "us-central1-a" +} diff --git a/templates/terraform/examples/managed_ssl_certificate_basic.tf.erb b/templates/terraform/examples/managed_ssl_certificate_basic.tf.erb index b3ba5cd89a4c..8ad7d2df2c69 100644 --- a/templates/terraform/examples/managed_ssl_certificate_basic.tf.erb +++ b/templates/terraform/examples/managed_ssl_certificate_basic.tf.erb @@ -1,4 +1,6 @@ resource "google_compute_managed_ssl_certificate" "default" { + provider = "google-beta" + name = "<%= ctx[:vars]['cert_name'] %>" managed { @@ -7,12 +9,16 @@ resource "google_compute_managed_ssl_certificate" "default" { } resource "google_compute_target_https_proxy" "default" { + provider = "google-beta" + name = "<%= ctx[:vars]['proxy_name'] %>" url_map = "${google_compute_url_map.default.self_link}" ssl_certificates = ["${google_compute_managed_ssl_certificate.default.self_link}"] } resource "google_compute_url_map" "default" { + provider = "google-beta" + name = "<%= ctx[:vars]['url_map_name'] %>" description = "a description" @@ -35,6 +41,8 @@ resource "google_compute_url_map" "default" { } resource "google_compute_backend_service" "default" { + provider = "google-beta" + name = "<%= ctx[:vars]['backend_service_name'] %>" port_name = "http" protocol = "HTTP" @@ -44,6 +52,8 @@ resource "google_compute_backend_service" "default" { } resource "google_compute_http_health_check" "default" { + provider = "google-beta" + name = "<%= ctx[:vars]['http_health_check_name'] %>" request_path = "/" check_interval_sec = 1 @@ -51,20 +61,31 @@ resource "google_compute_http_health_check" "default" { } resource "google_dns_managed_zone" "zone" { + provider = "google-beta" + name = "<%= ctx[:vars]['dns_zone_name'] %>" dns_name = "sslcert.tf-test.club." } resource "google_compute_global_forwarding_rule" "default" { + provider = "google-beta" + name = "<%= ctx[:vars]['forwarding_rule_name'] %>" target = "${google_compute_target_https_proxy.default.self_link}" port_range = 443 } resource "google_dns_record_set" "set" { + provider = "google-beta" + name = "sslcert.tf-test.club." type = "A" ttl = 3600 managed_zone = "${google_dns_managed_zone.zone.name}" rrdatas = ["${google_compute_global_forwarding_rule.default.ip_address}"] } + +provider "google-beta"{ + region = "us-central1" + zone = "us-central1-a" +} diff --git a/templates/terraform/examples/region_autoscaler_basic.tf.erb b/templates/terraform/examples/region_autoscaler_basic.tf.erb index 9a4d497c6da0..5565149beff6 100644 --- a/templates/terraform/examples/region_autoscaler_basic.tf.erb +++ b/templates/terraform/examples/region_autoscaler_basic.tf.erb @@ -46,14 +46,8 @@ resource "google_compute_region_instance_group_manager" "foobar" { name = "<%= ctx[:vars]['rigm_name'] %>" region = "us-central1" -<% if ctx[:version].nil? || ctx[:version] == 'ga' -%> instance_template = "${google_compute_instance_template.foobar.self_link}" -<% else -%> - version { - instance_template = "${google_compute_instance_template.foobar.self_link}" - name = "primary" - } -<% end -%> + target_pools = ["${google_compute_target_pool.foobar.self_link}"] base_instance_name = "foobar" } diff --git a/templates/terraform/examples/region_autoscaler_beta.tf.erb b/templates/terraform/examples/region_autoscaler_beta.tf.erb new file mode 100644 index 000000000000..2aa87b54ec44 --- /dev/null +++ b/templates/terraform/examples/region_autoscaler_beta.tf.erb @@ -0,0 +1,76 @@ +resource "google_compute_region_autoscaler" "foobar" { + provider = "google-beta" + + name = "<%= ctx[:vars]['region_autoscaler_name'] %>" + region = "us-central1" + target = "${google_compute_region_instance_group_manager.foobar.self_link}" + + autoscaling_policy { + max_replicas = 5 + min_replicas = 1 + cooldown_period = 60 + + cpu_utilization { + target = 0.5 + } + } +} + +resource "google_compute_instance_template" "foobar" { + provider = "google-beta" + + name = "<%= ctx[:vars]['instance_template_name'] %>" + machine_type = "n1-standard-1" + can_ip_forward = false + + tags = ["foo", "bar"] + + disk { + source_image = "${data.google_compute_image.debian_9.self_link}" + } + + network_interface { + network = "default" + } + + metadata = { + foo = "bar" + } + + service_account { + scopes = ["userinfo-email", "compute-ro", "storage-ro"] + } +} + +resource "google_compute_target_pool" "foobar" { + provider = "google-beta" + + name = "<%= ctx[:vars]['target_pool_name'] %>" +} + +resource "google_compute_region_instance_group_manager" "foobar" { + provider = "google-beta" + + name = "<%= ctx[:vars]['rigm_name'] %>" + region = "us-central1" + + version { + instance_template = "${google_compute_instance_template.foobar.self_link}" + name = "primary" + } + + target_pools = ["${google_compute_target_pool.foobar.self_link}"] + base_instance_name = "foobar" +} + +data "google_compute_image" "debian_9" { + provider = "google-beta" + + family = "debian-9" + project = "debian-cloud" +} + +provider "google-beta"{ + region = "us-central1" + zone = "us-central1-a" +} diff --git a/templates/terraform/examples/scheduler_job_app_engine.tf.erb b/templates/terraform/examples/scheduler_job_app_engine.tf.erb index 1020ff45c216..20a486d01603 100644 --- a/templates/terraform/examples/scheduler_job_app_engine.tf.erb +++ b/templates/terraform/examples/scheduler_job_app_engine.tf.erb @@ -1,4 +1,6 @@ resource "google_cloud_scheduler_job" "job" { + provider = "google-beta" + name = "<%= ctx[:vars]['job_name'] %>" schedule = "*/4 * * * *" description = "test app engine job" @@ -15,4 +17,9 @@ resource "google_cloud_scheduler_job" "job" { relative_uri = "/ping" } -} \ No newline at end of file +} + +provider "google-beta"{ + region = "us-central1" + zone = "us-central1-a" +} diff --git a/templates/terraform/examples/scheduler_job_http.tf.erb b/templates/terraform/examples/scheduler_job_http.tf.erb index 7b8b3e1f564a..1447890abec4 100644 --- a/templates/terraform/examples/scheduler_job_http.tf.erb +++ b/templates/terraform/examples/scheduler_job_http.tf.erb @@ -1,4 +1,6 @@ resource "google_cloud_scheduler_job" "job" { + provider = "google-beta" + name = "<%= ctx[:vars]['job_name'] %>" description = "test http job" schedule = "*/8 * * * *" @@ -8,4 +10,9 @@ resource "google_cloud_scheduler_job" "job" { http_method = "POST" uri = "https://example.com/ping" } -} \ No newline at end of file +} + +provider "google-beta"{ + region = "us-central1" + zone = "us-central1-a" +} diff --git a/templates/terraform/examples/scheduler_job_pubsub.tf.erb b/templates/terraform/examples/scheduler_job_pubsub.tf.erb index a6e8480d4344..05702a223e45 100644 --- a/templates/terraform/examples/scheduler_job_pubsub.tf.erb +++ b/templates/terraform/examples/scheduler_job_pubsub.tf.erb @@ -1,8 +1,12 @@ resource "google_pubsub_topic" "topic" { + provider = "google-beta" + name = "<%= ctx[:vars]['topic_name'] %>" } resource "google_cloud_scheduler_job" "job" { + provider = "google-beta" + name = "<%= ctx[:vars]['job_name'] %>" description = "test job" schedule = "*/2 * * * *" @@ -12,3 +16,8 @@ resource "google_cloud_scheduler_job" "job" { data = "${base64encode("test")}" } } + +provider "google-beta"{ + region = "us-central1" + zone = "us-central1-a" +} diff --git a/templates/terraform/resource.html.markdown.erb b/templates/terraform/resource.html.markdown.erb index 4c8cb5b8e36f..317106174dbb 100644 --- a/templates/terraform/resource.html.markdown.erb +++ b/templates/terraform/resource.html.markdown.erb @@ -80,6 +80,8 @@ To get more information about <%= object.name -%>, see: ~> **Warning:** <%= object.docs.warning -%> <%- end -%> +<%#- We over-generate examples/oics buttons here; they'll all be _valid_ just not necessarily intended for this provider version. + Unless/Until we split our docs, this is a non-issue. -%> <% unless object.examples.empty? -%> <%- object.examples.each do |example| -%> <%- unless example.skip_test -%> diff --git a/third_party/terraform/utils/provider_test.go b/third_party/terraform/utils/provider_test.go.erb similarity index 89% rename from third_party/terraform/utils/provider_test.go rename to third_party/terraform/utils/provider_test.go.erb index dacfcac583c5..5ac181effcad 100644 --- a/third_party/terraform/utils/provider_test.go +++ b/third_party/terraform/utils/provider_test.go.erb @@ -1,3 +1,4 @@ +<% autogen_exception -%> package google import ( @@ -13,6 +14,9 @@ import ( ) var testAccProviders map[string]terraform.ResourceProvider +<% unless version == 'ga' -%> +var testAccProvidersOiCS map[string]terraform.ResourceProvider +<% end -%> var testAccProvider *schema.Provider var testAccRandomProvider *schema.Provider @@ -60,10 +64,25 @@ var billingAccountEnvVars = []string{ func init() { testAccProvider = Provider().(*schema.Provider) testAccRandomProvider = random.Provider().(*schema.Provider) + <% if version == 'ga' -%> testAccProviders = map[string]terraform.ResourceProvider{ "google": testAccProvider, "random": testAccRandomProvider, } + <% else -%> + testAccProviders = map[string]terraform.ResourceProvider{ + "google": testAccProvider, + "random": testAccRandomProvider, + } + + // The OiCS provider map is used to ensure that OiCS examples use `google-beta` + // if the example is versioned as beta; normal beta tests should continue to + // use the standard provider map. + testAccProvidersOiCS = map[string]terraform.ResourceProvider{ + "google-beta": testAccProvider, + "random": testAccRandomProvider, + } + <% end -%> } func TestProvider(t *testing.T) {