diff --git a/google-beta/import.go b/google-beta/import.go index 248c8390b4..abad548a22 100644 --- a/google-beta/import.go +++ b/google-beta/import.go @@ -3,6 +3,7 @@ package google import ( "fmt" "regexp" + "strconv" "strings" ) @@ -25,7 +26,35 @@ func parseImportId(idRegexes []string, d TerraformResourceData, config *Config) // Starting at index 1, the first match is the full string. for i := 1; i < len(fieldValues); i++ { fieldName := re.SubexpNames()[i] - d.Set(fieldName, fieldValues[i]) + fieldValue := fieldValues[i] + // Because we do not know at this point whether 'fieldName' + // corresponds to a TypeString or a TypeInteger in the resource + // schema, we need to determine the type in an unintutitive way. + // We call d.Get, because examining the empty value is the easiest + // way to get that out. Normally, we would be able to just + // use a try/catch pattern - try as a string, and if that doesn't + // work, try as an integer, and if that doesn't work, return the + // error. Unfortunately, this is not possible here - during tests, + // d.Set(...) will panic if there is an error. + val, _ := d.GetOk(fieldName) + if _, ok := val.(string); val == nil || ok { + if err = d.Set(fieldName, fieldValue); err != nil { + return err + } + } else if _, ok := val.(int); ok { + if intVal, atoiErr := strconv.Atoi(fieldValue); atoiErr == nil { + // If the value can be parsed as an integer, we try to set the + // value as an integer. + if err = d.Set(fieldName, intVal); err != nil { + return err + } + } else { + return fmt.Errorf("%s appears to be an integer, but %v cannot be parsed as an int", fieldName, fieldValue) + } + } else { + return fmt.Errorf( + "cannot handle %s, which currently has value %v, and should be set to %#v, during import", fieldName, val, fieldValue) + } } // The first id format is applied first and contains all the fields. diff --git a/google-beta/provider.go b/google-beta/provider.go index 0c75909b62..25b906b260 100644 --- a/google-beta/provider.go +++ b/google-beta/provider.go @@ -121,6 +121,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) { GeneratedFilestoreResourcesMap, GeneratedAccessContextManagerResourcesMap, // end beta-only products + GeneratedAppengineResourcesMap, GeneratedComputeResourcesMap, GeneratedDnsResourcesMap, GeneratedRedisResourcesMap, diff --git a/google-beta/provider_appengine_gen.go b/google-beta/provider_appengine_gen.go new file mode 100644 index 0000000000..d2eb097472 --- /dev/null +++ b/google-beta/provider_appengine_gen.go @@ -0,0 +1,21 @@ +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +// +// ---------------------------------------------------------------------------- +// +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. +// +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. +// +// ---------------------------------------------------------------------------- + +package google + +import "github.com/hashicorp/terraform/helper/schema" + +var GeneratedAppengineResourcesMap = map[string]*schema.Resource{ + "google_appengine_firewall_rule": resourceAppengineFirewallRule(), +} diff --git a/google-beta/resource_appengine_firewall_rule.go b/google-beta/resource_appengine_firewall_rule.go new file mode 100644 index 0000000000..b037bcbfa1 --- /dev/null +++ b/google-beta/resource_appengine_firewall_rule.go @@ -0,0 +1,301 @@ +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +// +// ---------------------------------------------------------------------------- +// +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. +// +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. +// +// ---------------------------------------------------------------------------- + +package google + +import ( + "fmt" + "log" + "reflect" + "strconv" + "strings" + "time" + + "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/helper/validation" +) + +func resourceAppengineFirewallRule() *schema.Resource { + return &schema.Resource{ + Create: resourceAppengineFirewallRuleCreate, + Read: resourceAppengineFirewallRuleRead, + Update: resourceAppengineFirewallRuleUpdate, + Delete: resourceAppengineFirewallRuleDelete, + + Importer: &schema.ResourceImporter{ + State: resourceAppengineFirewallRuleImport, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(240 * time.Second), + Update: schema.DefaultTimeout(240 * time.Second), + Delete: schema.DefaultTimeout(240 * time.Second), + }, + + Schema: map[string]*schema.Schema{ + "action": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{"UNSPECIFIED_ACTION", "ALLOW", "DENY"}, false), + }, + "source_range": { + Type: schema.TypeString, + Required: true, + }, + "description": { + Type: schema.TypeString, + Optional: true, + }, + "priority": { + Type: schema.TypeInt, + Optional: true, + }, + "project": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + }, + } +} + +func resourceAppengineFirewallRuleCreate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + obj := make(map[string]interface{}) + descriptionProp, err := expandAppengineFirewallRuleDescription(d.Get("description"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { + obj["description"] = descriptionProp + } + sourceRangeProp, err := expandAppengineFirewallRuleSourceRange(d.Get("source_range"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("source_range"); !isEmptyValue(reflect.ValueOf(sourceRangeProp)) && (ok || !reflect.DeepEqual(v, sourceRangeProp)) { + obj["sourceRange"] = sourceRangeProp + } + actionProp, err := expandAppengineFirewallRuleAction(d.Get("action"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("action"); !isEmptyValue(reflect.ValueOf(actionProp)) && (ok || !reflect.DeepEqual(v, actionProp)) { + obj["action"] = actionProp + } + priorityProp, err := expandAppengineFirewallRulePriority(d.Get("priority"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("priority"); !isEmptyValue(reflect.ValueOf(priorityProp)) && (ok || !reflect.DeepEqual(v, priorityProp)) { + obj["priority"] = priorityProp + } + + url, err := replaceVars(d, config, "https://appengine.googleapis.com/v1/apps/{{project}}/firewall/ingressRules") + if err != nil { + return err + } + + log.Printf("[DEBUG] Creating new FirewallRule: %#v", obj) + res, err := sendRequestWithTimeout(config, "POST", url, obj, d.Timeout(schema.TimeoutCreate)) + if err != nil { + return fmt.Errorf("Error creating FirewallRule: %s", err) + } + + // Store the ID now + id, err := replaceVars(d, config, "{{project}}/{{priority}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + log.Printf("[DEBUG] Finished creating FirewallRule %q: %#v", d.Id(), res) + + return resourceAppengineFirewallRuleRead(d, meta) +} + +func resourceAppengineFirewallRuleRead(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + url, err := replaceVars(d, config, "https://appengine.googleapis.com/v1/apps/{{project}}/firewall/ingressRules/{{priority}}") + if err != nil { + return err + } + + res, err := sendRequest(config, "GET", url, nil) + if err != nil { + return handleNotFoundError(err, d, fmt.Sprintf("AppengineFirewallRule %q", d.Id())) + } + + project, err := getProject(d, config) + if err != nil { + return err + } + if err := d.Set("project", project); err != nil { + return fmt.Errorf("Error reading FirewallRule: %s", err) + } + + if err := d.Set("description", flattenAppengineFirewallRuleDescription(res["description"], d)); err != nil { + return fmt.Errorf("Error reading FirewallRule: %s", err) + } + if err := d.Set("source_range", flattenAppengineFirewallRuleSourceRange(res["sourceRange"], d)); err != nil { + return fmt.Errorf("Error reading FirewallRule: %s", err) + } + if err := d.Set("action", flattenAppengineFirewallRuleAction(res["action"], d)); err != nil { + return fmt.Errorf("Error reading FirewallRule: %s", err) + } + if err := d.Set("priority", flattenAppengineFirewallRulePriority(res["priority"], d)); err != nil { + return fmt.Errorf("Error reading FirewallRule: %s", err) + } + + return nil +} + +func resourceAppengineFirewallRuleUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + obj := make(map[string]interface{}) + descriptionProp, err := expandAppengineFirewallRuleDescription(d.Get("description"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { + obj["description"] = descriptionProp + } + sourceRangeProp, err := expandAppengineFirewallRuleSourceRange(d.Get("source_range"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("source_range"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, sourceRangeProp)) { + obj["sourceRange"] = sourceRangeProp + } + actionProp, err := expandAppengineFirewallRuleAction(d.Get("action"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("action"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, actionProp)) { + obj["action"] = actionProp + } + priorityProp, err := expandAppengineFirewallRulePriority(d.Get("priority"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("priority"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, priorityProp)) { + obj["priority"] = priorityProp + } + + url, err := replaceVars(d, config, "https://appengine.googleapis.com/v1/apps/{{project}}/firewall/ingressRules/{{priority}}") + if err != nil { + return err + } + + log.Printf("[DEBUG] Updating FirewallRule %q: %#v", d.Id(), obj) + updateMask := []string{} + + if d.HasChange("description") { + updateMask = append(updateMask, "description") + } + + if d.HasChange("source_range") { + updateMask = append(updateMask, "sourceRange") + } + + if d.HasChange("action") { + updateMask = append(updateMask, "action") + } + + if d.HasChange("priority") { + updateMask = append(updateMask, "priority") + } + // updateMask is a URL parameter but not present in the schema, so replaceVars + // won't set it + url, err = addQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")}) + if err != nil { + return err + } + _, err = sendRequestWithTimeout(config, "PATCH", url, obj, d.Timeout(schema.TimeoutUpdate)) + + if err != nil { + return fmt.Errorf("Error updating FirewallRule %q: %s", d.Id(), err) + } + + return resourceAppengineFirewallRuleRead(d, meta) +} + +func resourceAppengineFirewallRuleDelete(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + url, err := replaceVars(d, config, "https://appengine.googleapis.com/v1/apps/{{project}}/firewall/ingressRules/{{priority}}") + if err != nil { + return err + } + + var obj map[string]interface{} + log.Printf("[DEBUG] Deleting FirewallRule %q", d.Id()) + res, err := sendRequestWithTimeout(config, "DELETE", url, obj, d.Timeout(schema.TimeoutDelete)) + if err != nil { + return handleNotFoundError(err, d, "FirewallRule") + } + + log.Printf("[DEBUG] Finished deleting FirewallRule %q: %#v", d.Id(), res) + return nil +} + +func resourceAppengineFirewallRuleImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + config := meta.(*Config) + if err := parseImportId([]string{"(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)"}, d, config); err != nil { + return nil, err + } + + // Replace import id for the resource id + id, err := replaceVars(d, config, "{{project}}/{{priority}}") + if err != nil { + return nil, fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + return []*schema.ResourceData{d}, nil +} + +func flattenAppengineFirewallRuleDescription(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenAppengineFirewallRuleSourceRange(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenAppengineFirewallRuleAction(v interface{}, d *schema.ResourceData) interface{} { + return v +} + +func flattenAppengineFirewallRulePriority(v interface{}, d *schema.ResourceData) interface{} { + // Handles the string fixed64 format + if strVal, ok := v.(string); ok { + if intVal, err := strconv.ParseInt(strVal, 10, 64); err == nil { + return intVal + } // let terraform core handle it if we can't convert the string to an int. + } + return v +} + +func expandAppengineFirewallRuleDescription(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandAppengineFirewallRuleSourceRange(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandAppengineFirewallRuleAction(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandAppengineFirewallRulePriority(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) { + return v, nil +} diff --git a/google-beta/resource_appengine_firewall_rule_generated_test.go b/google-beta/resource_appengine_firewall_rule_generated_test.go new file mode 100644 index 0000000000..4bb0ee6eea --- /dev/null +++ b/google-beta/resource_appengine_firewall_rule_generated_test.go @@ -0,0 +1,93 @@ +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +// +// ---------------------------------------------------------------------------- +// +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. +// +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. +// +// ---------------------------------------------------------------------------- + +package google + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func TestAccAppengineFirewallRule_appengineFirewallRuleBasicExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "org_id": getTestOrgFromEnv(t), + "random_suffix": acctest.RandString(10), + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAppengineFirewallRuleDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAppengineFirewallRule_appengineFirewallRuleBasicExample(context), + }, + { + ResourceName: "google_appengine_firewall_rule.rule", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccAppengineFirewallRule_appengineFirewallRuleBasicExample(context map[string]interface{}) string { + return Nprintf(` +resource "google_project" "my_project" { + name = "tf-test-project" + project_id = "test-project-%{random_suffix}" + org_id = "%{org_id}" +} + +resource "google_app_engine_application" "app" { + project = "${google_project.my_project.project_id}" + location_id = "us-central" +} + +resource "google_appengine_firewall_rule" "rule" { + project = "${google_app_engine_application.app.project}" + priority = 1000 + action = "ALLOW" + source_range = "*" +} +`, context) +} + +func testAccCheckAppengineFirewallRuleDestroy(s *terraform.State) error { + for _, rs := range s.RootModule().Resources { + if rs.Type != "google_appengine_firewall_rule" { + continue + } + + config := testAccProvider.Meta().(*Config) + + url, err := replaceVarsForTest(rs, "https://appengine.googleapis.com/v1/apps/{{project}}/firewall/ingressRules/{{priority}}") + if err != nil { + return err + } + + _, err = sendRequest(config, "GET", url, nil) + if err == nil { + return fmt.Errorf("AppengineFirewallRule still exists at %s", url) + } + } + + return nil +} diff --git a/google-beta/resource_compute_address_generated_test.go b/google-beta/resource_compute_address_generated_test.go index f6590ec69f..0af74708b8 100644 --- a/google-beta/resource_compute_address_generated_test.go +++ b/google-beta/resource_compute_address_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccComputeAddress_addressBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeAddressDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeAddress_addressBasicExample(acctest.RandString(10)), + Config: testAccComputeAddress_addressBasicExample(context), }, { ResourceName: "google_compute_address.ip_address", @@ -44,25 +48,28 @@ func TestAccComputeAddress_addressBasicExample(t *testing.T) { }) } -func testAccComputeAddress_addressBasicExample(val string) string { - return fmt.Sprintf(` +func testAccComputeAddress_addressBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_compute_address" "ip_address" { - name = "my-address-%s" + name = "my-address-%{random_suffix}" } -`, val, - ) +`, context) } func TestAccComputeAddress_addressWithSubnetworkExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeAddressDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeAddress_addressWithSubnetworkExample(acctest.RandString(10)), + Config: testAccComputeAddress_addressWithSubnetworkExample(context), }, { ResourceName: "google_compute_address.internal_with_subnet_and_address", @@ -73,40 +80,43 @@ func TestAccComputeAddress_addressWithSubnetworkExample(t *testing.T) { }) } -func testAccComputeAddress_addressWithSubnetworkExample(val string) string { - return fmt.Sprintf(` +func testAccComputeAddress_addressWithSubnetworkExample(context map[string]interface{}) string { + return Nprintf(` resource "google_compute_network" "default" { - name = "my-network-%s" + name = "my-network-%{random_suffix}" } resource "google_compute_subnetwork" "default" { - name = "my-subnet-%s" + name = "my-subnet-%{random_suffix}" ip_cidr_range = "10.0.0.0/16" region = "us-central1" network = "${google_compute_network.default.self_link}" } resource "google_compute_address" "internal_with_subnet_and_address" { - name = "my-internal-address-%s" + name = "my-internal-address-%{random_suffix}" subnetwork = "${google_compute_subnetwork.default.self_link}" address_type = "INTERNAL" address = "10.0.42.42" region = "us-central1" } -`, val, val, val, - ) +`, context) } func TestAccComputeAddress_instanceWithIpExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeAddressDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeAddress_instanceWithIpExample(acctest.RandString(10)), + Config: testAccComputeAddress_instanceWithIpExample(context), }, { ResourceName: "google_compute_address.static", @@ -117,10 +127,10 @@ func TestAccComputeAddress_instanceWithIpExample(t *testing.T) { }) } -func testAccComputeAddress_instanceWithIpExample(val string) string { - return fmt.Sprintf(` +func testAccComputeAddress_instanceWithIpExample(context map[string]interface{}) string { + return Nprintf(` resource "google_compute_address" "static" { - name = "ipv4-address-%s" + name = "ipv4-address-%{random_suffix}" } data "google_compute_image" "debian_image" { @@ -129,7 +139,7 @@ data "google_compute_image" "debian_image" { } resource "google_compute_instance" "instance_with_ip" { - name = "vm-instance-%s" + name = "vm-instance-%{random_suffix}" machine_type = "f1-micro" zone = "us-central1-a" @@ -146,8 +156,7 @@ resource "google_compute_instance" "instance_with_ip" { } } } -`, val, val, - ) +`, context) } func testAccCheckComputeAddressDestroy(s *terraform.State) error { diff --git a/google-beta/resource_compute_autoscaler_generated_test.go b/google-beta/resource_compute_autoscaler_generated_test.go index 7845ed5434..5f1d5e5cdc 100644 --- a/google-beta/resource_compute_autoscaler_generated_test.go +++ b/google-beta/resource_compute_autoscaler_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccComputeAutoscaler_autoscalerBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeAutoscalerDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeAutoscaler_autoscalerBasicExample(acctest.RandString(10)), + Config: testAccComputeAutoscaler_autoscalerBasicExample(context), }, { ResourceName: "google_compute_autoscaler.foobar", @@ -44,10 +48,10 @@ func TestAccComputeAutoscaler_autoscalerBasicExample(t *testing.T) { }) } -func testAccComputeAutoscaler_autoscalerBasicExample(val string) string { - return fmt.Sprintf(` +func testAccComputeAutoscaler_autoscalerBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_compute_autoscaler" "foobar" { - name = "my-autoscaler-%s" + name = "my-autoscaler-%{random_suffix}" zone = "us-central1-f" target = "${google_compute_instance_group_manager.foobar.self_link}" @@ -63,7 +67,7 @@ resource "google_compute_autoscaler" "foobar" { } resource "google_compute_instance_template" "foobar" { - name = "my-instance-template-%s" + name = "my-instance-template-%{random_suffix}" machine_type = "n1-standard-1" can_ip_forward = false @@ -87,11 +91,11 @@ resource "google_compute_instance_template" "foobar" { } resource "google_compute_target_pool" "foobar" { - name = "my-target-pool-%s" + name = "my-target-pool-%{random_suffix}" } resource "google_compute_instance_group_manager" "foobar" { - name = "my-igm-%s" + name = "my-igm-%{random_suffix}" zone = "us-central1-f" version { @@ -106,8 +110,7 @@ data "google_compute_image" "debian_9" { family = "debian-9" project = "debian-cloud" } -`, val, val, val, val, - ) +`, context) } func testAccCheckComputeAutoscalerDestroy(s *terraform.State) error { diff --git a/google-beta/resource_compute_backend_bucket_generated_test.go b/google-beta/resource_compute_backend_bucket_generated_test.go index 9359a4b85a..0ab0235ac0 100644 --- a/google-beta/resource_compute_backend_bucket_generated_test.go +++ b/google-beta/resource_compute_backend_bucket_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccComputeBackendBucket_backendBucketBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeBackendBucketDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeBackendBucket_backendBucketBasicExample(acctest.RandString(10)), + Config: testAccComputeBackendBucket_backendBucketBasicExample(context), }, { ResourceName: "google_compute_backend_bucket.image_backend", @@ -44,21 +48,20 @@ func TestAccComputeBackendBucket_backendBucketBasicExample(t *testing.T) { }) } -func testAccComputeBackendBucket_backendBucketBasicExample(val string) string { - return fmt.Sprintf(` +func testAccComputeBackendBucket_backendBucketBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_compute_backend_bucket" "image_backend" { - name = "image-backend-bucket-%s" + name = "image-backend-bucket-%{random_suffix}" description = "Contains beautiful images" bucket_name = "${google_storage_bucket.image_bucket.name}" enable_cdn = true } resource "google_storage_bucket" "image_bucket" { - name = "image-store-bucket-%s" + name = "image-store-bucket-%{random_suffix}" location = "EU" } -`, val, val, - ) +`, context) } func testAccCheckComputeBackendBucketDestroy(s *terraform.State) error { diff --git a/google-beta/resource_compute_disk_generated_test.go b/google-beta/resource_compute_disk_generated_test.go index 07833a227f..2e89f4fb71 100644 --- a/google-beta/resource_compute_disk_generated_test.go +++ b/google-beta/resource_compute_disk_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccComputeDisk_diskBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeDiskDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeDisk_diskBasicExample(acctest.RandString(10)), + Config: testAccComputeDisk_diskBasicExample(context), }, { ResourceName: "google_compute_disk.default", @@ -44,10 +48,10 @@ func TestAccComputeDisk_diskBasicExample(t *testing.T) { }) } -func testAccComputeDisk_diskBasicExample(val string) string { - return fmt.Sprintf(` +func testAccComputeDisk_diskBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_compute_disk" "default" { - name = "test-disk-%s" + name = "test-disk-%{random_suffix}" type = "pd-ssd" zone = "us-central1-a" image = "debian-8-jessie-v20170523" @@ -55,8 +59,7 @@ resource "google_compute_disk" "default" { environment = "dev" } } -`, val, - ) +`, context) } func testAccCheckComputeDiskDestroy(s *terraform.State) error { diff --git a/google-beta/resource_compute_firewall_generated_test.go b/google-beta/resource_compute_firewall_generated_test.go index a50c7bc1c8..079be81da6 100644 --- a/google-beta/resource_compute_firewall_generated_test.go +++ b/google-beta/resource_compute_firewall_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccComputeFirewall_firewallBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeFirewall_firewallBasicExample(acctest.RandString(10)), + Config: testAccComputeFirewall_firewallBasicExample(context), }, { ResourceName: "google_compute_firewall.default", @@ -44,10 +48,10 @@ func TestAccComputeFirewall_firewallBasicExample(t *testing.T) { }) } -func testAccComputeFirewall_firewallBasicExample(val string) string { - return fmt.Sprintf(` +func testAccComputeFirewall_firewallBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_compute_firewall" "default" { - name = "test-firewall-%s" + name = "test-firewall-%{random_suffix}" network = "${google_compute_network.default.name}" allow { @@ -63,10 +67,9 @@ resource "google_compute_firewall" "default" { } resource "google_compute_network" "default" { - name = "test-network-%s" + name = "test-network-%{random_suffix}" } -`, val, val, - ) +`, context) } func testAccCheckComputeFirewallDestroy(s *terraform.State) error { diff --git a/google-beta/resource_compute_forwarding_rule_generated_test.go b/google-beta/resource_compute_forwarding_rule_generated_test.go index 36c1003b9f..0142eeb629 100644 --- a/google-beta/resource_compute_forwarding_rule_generated_test.go +++ b/google-beta/resource_compute_forwarding_rule_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccComputeForwardingRule_forwardingRuleBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeForwardingRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeForwardingRule_forwardingRuleBasicExample(acctest.RandString(10)), + Config: testAccComputeForwardingRule_forwardingRuleBasicExample(context), }, { ResourceName: "google_compute_forwarding_rule.default", @@ -44,19 +48,18 @@ func TestAccComputeForwardingRule_forwardingRuleBasicExample(t *testing.T) { }) } -func testAccComputeForwardingRule_forwardingRuleBasicExample(val string) string { - return fmt.Sprintf(` +func testAccComputeForwardingRule_forwardingRuleBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_compute_forwarding_rule" "default" { - name = "website-forwarding-rule-%s" + name = "website-forwarding-rule-%{random_suffix}" target = "${google_compute_target_pool.default.self_link}" port_range = "80" } resource "google_compute_target_pool" "default" { - name = "website-target-pool-%s" + name = "website-target-pool-%{random_suffix}" } -`, val, val, - ) +`, context) } func testAccCheckComputeForwardingRuleDestroy(s *terraform.State) error { diff --git a/google-beta/resource_compute_global_address_generated_test.go b/google-beta/resource_compute_global_address_generated_test.go index 61b114685d..c8aeafceb8 100644 --- a/google-beta/resource_compute_global_address_generated_test.go +++ b/google-beta/resource_compute_global_address_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccComputeGlobalAddress_globalAddressBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeGlobalAddressDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeGlobalAddress_globalAddressBasicExample(acctest.RandString(10)), + Config: testAccComputeGlobalAddress_globalAddressBasicExample(context), }, { ResourceName: "google_compute_global_address.default", @@ -44,13 +48,12 @@ func TestAccComputeGlobalAddress_globalAddressBasicExample(t *testing.T) { }) } -func testAccComputeGlobalAddress_globalAddressBasicExample(val string) string { - return fmt.Sprintf(` +func testAccComputeGlobalAddress_globalAddressBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_compute_global_address" "default" { - name = "global-appserver-ip-%s" + name = "global-appserver-ip-%{random_suffix}" } -`, val, - ) +`, context) } func testAccCheckComputeGlobalAddressDestroy(s *terraform.State) error { diff --git a/google-beta/resource_compute_health_check_generated_test.go b/google-beta/resource_compute_health_check_generated_test.go index 397b8c315c..3c4888dec8 100644 --- a/google-beta/resource_compute_health_check_generated_test.go +++ b/google-beta/resource_compute_health_check_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccComputeHealthCheck_healthCheckBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeHealthCheckDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeHealthCheck_healthCheckBasicExample(acctest.RandString(10)), + Config: testAccComputeHealthCheck_healthCheckBasicExample(context), }, { ResourceName: "google_compute_health_check.internal-health-check", @@ -44,10 +48,10 @@ func TestAccComputeHealthCheck_healthCheckBasicExample(t *testing.T) { }) } -func testAccComputeHealthCheck_healthCheckBasicExample(val string) string { - return fmt.Sprintf(` +func testAccComputeHealthCheck_healthCheckBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_compute_health_check" "internal-health-check" { - name = "internal-service-health-check-%s" + name = "internal-service-health-check-%{random_suffix}" timeout_sec = 1 check_interval_sec = 1 @@ -56,8 +60,7 @@ resource "google_compute_health_check" "internal-health-check" { port = "80" } } -`, val, - ) +`, context) } func testAccCheckComputeHealthCheckDestroy(s *terraform.State) error { diff --git a/google-beta/resource_compute_http_health_check_generated_test.go b/google-beta/resource_compute_http_health_check_generated_test.go index 306cb4caa9..b57e0f0db4 100644 --- a/google-beta/resource_compute_http_health_check_generated_test.go +++ b/google-beta/resource_compute_http_health_check_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccComputeHttpHealthCheck_httpHealthCheckBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeHttpHealthCheckDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeHttpHealthCheck_httpHealthCheckBasicExample(acctest.RandString(10)), + Config: testAccComputeHttpHealthCheck_httpHealthCheckBasicExample(context), }, { ResourceName: "google_compute_http_health_check.default", @@ -44,17 +48,16 @@ func TestAccComputeHttpHealthCheck_httpHealthCheckBasicExample(t *testing.T) { }) } -func testAccComputeHttpHealthCheck_httpHealthCheckBasicExample(val string) string { - return fmt.Sprintf(` +func testAccComputeHttpHealthCheck_httpHealthCheckBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_compute_http_health_check" "default" { - name = "authentication-health-check-%s" + name = "authentication-health-check-%{random_suffix}" request_path = "/health_check" timeout_sec = 1 check_interval_sec = 1 } -`, val, - ) +`, context) } func testAccCheckComputeHttpHealthCheckDestroy(s *terraform.State) error { diff --git a/google-beta/resource_compute_https_health_check_generated_test.go b/google-beta/resource_compute_https_health_check_generated_test.go index e8887dc884..807693b44e 100644 --- a/google-beta/resource_compute_https_health_check_generated_test.go +++ b/google-beta/resource_compute_https_health_check_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccComputeHttpsHealthCheck_httpsHealthCheckBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeHttpsHealthCheckDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeHttpsHealthCheck_httpsHealthCheckBasicExample(acctest.RandString(10)), + Config: testAccComputeHttpsHealthCheck_httpsHealthCheckBasicExample(context), }, { ResourceName: "google_compute_https_health_check.default", @@ -44,17 +48,16 @@ func TestAccComputeHttpsHealthCheck_httpsHealthCheckBasicExample(t *testing.T) { }) } -func testAccComputeHttpsHealthCheck_httpsHealthCheckBasicExample(val string) string { - return fmt.Sprintf(` +func testAccComputeHttpsHealthCheck_httpsHealthCheckBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_compute_https_health_check" "default" { - name = "authentication-health-check-%s" + name = "authentication-health-check-%{random_suffix}" request_path = "/health_check" timeout_sec = 1 check_interval_sec = 1 } -`, val, - ) +`, context) } func testAccCheckComputeHttpsHealthCheckDestroy(s *terraform.State) error { diff --git a/google-beta/resource_compute_region_autoscaler_generated_test.go b/google-beta/resource_compute_region_autoscaler_generated_test.go index bdd91d57db..3ca3285eec 100644 --- a/google-beta/resource_compute_region_autoscaler_generated_test.go +++ b/google-beta/resource_compute_region_autoscaler_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccComputeRegionAutoscaler_regionAutoscalerBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeRegionAutoscalerDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeRegionAutoscaler_regionAutoscalerBasicExample(acctest.RandString(10)), + Config: testAccComputeRegionAutoscaler_regionAutoscalerBasicExample(context), }, { ResourceName: "google_compute_region_autoscaler.foobar", @@ -44,10 +48,10 @@ func TestAccComputeRegionAutoscaler_regionAutoscalerBasicExample(t *testing.T) { }) } -func testAccComputeRegionAutoscaler_regionAutoscalerBasicExample(val string) string { - return fmt.Sprintf(` +func testAccComputeRegionAutoscaler_regionAutoscalerBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_compute_region_autoscaler" "foobar" { - name = "my-region-autoscaler-%s" + name = "my-region-autoscaler-%{random_suffix}" region = "us-central1" target = "${google_compute_region_instance_group_manager.foobar.self_link}" @@ -63,7 +67,7 @@ resource "google_compute_region_autoscaler" "foobar" { } resource "google_compute_instance_template" "foobar" { - name = "my-instance-template-%s" + name = "my-instance-template-%{random_suffix}" machine_type = "n1-standard-1" can_ip_forward = false @@ -87,11 +91,11 @@ resource "google_compute_instance_template" "foobar" { } resource "google_compute_target_pool" "foobar" { - name = "my-target-pool-%s" + name = "my-target-pool-%{random_suffix}" } resource "google_compute_region_instance_group_manager" "foobar" { - name = "my-region-igm-%s" + name = "my-region-igm-%{random_suffix}" region = "us-central1" version { @@ -106,8 +110,7 @@ data "google_compute_image" "debian_9" { family = "debian-9" project = "debian-cloud" } -`, val, val, val, val, - ) +`, context) } func testAccCheckComputeRegionAutoscalerDestroy(s *terraform.State) error { diff --git a/google-beta/resource_compute_region_disk_generated_test.go b/google-beta/resource_compute_region_disk_generated_test.go index 2dd3cb6337..236dd864ba 100644 --- a/google-beta/resource_compute_region_disk_generated_test.go +++ b/google-beta/resource_compute_region_disk_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccComputeRegionDisk_regionDiskBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeRegionDiskDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeRegionDisk_regionDiskBasicExample(acctest.RandString(10)), + Config: testAccComputeRegionDisk_regionDiskBasicExample(context), }, { ResourceName: "google_compute_region_disk.regiondisk", @@ -44,10 +48,10 @@ func TestAccComputeRegionDisk_regionDiskBasicExample(t *testing.T) { }) } -func testAccComputeRegionDisk_regionDiskBasicExample(val string) string { - return fmt.Sprintf(` +func testAccComputeRegionDisk_regionDiskBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_compute_region_disk" "regiondisk" { - name = "my-region-disk-%s" + name = "my-region-disk-%{random_suffix}" snapshot = "${google_compute_snapshot.snapdisk.self_link}" type = "pd-ssd" region = "us-central1" @@ -56,7 +60,7 @@ resource "google_compute_region_disk" "regiondisk" { } resource "google_compute_disk" "disk" { - name = "my-disk-%s" + name = "my-disk-%{random_suffix}" image = "debian-cloud/debian-9" size = 50 type = "pd-ssd" @@ -64,12 +68,11 @@ resource "google_compute_disk" "disk" { } resource "google_compute_snapshot" "snapdisk" { - name = "my-snapshot-%s" + name = "my-snapshot-%{random_suffix}" source_disk = "${google_compute_disk.disk.name}" zone = "us-central1-a" } -`, val, val, val, - ) +`, context) } func testAccCheckComputeRegionDiskDestroy(s *terraform.State) error { diff --git a/google-beta/resource_compute_route_generated_test.go b/google-beta/resource_compute_route_generated_test.go index ca96eddd54..ca59670631 100644 --- a/google-beta/resource_compute_route_generated_test.go +++ b/google-beta/resource_compute_route_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccComputeRoute_routeBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeRouteDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeRoute_routeBasicExample(acctest.RandString(10)), + Config: testAccComputeRoute_routeBasicExample(context), }, { ResourceName: "google_compute_route.default", @@ -44,10 +48,10 @@ func TestAccComputeRoute_routeBasicExample(t *testing.T) { }) } -func testAccComputeRoute_routeBasicExample(val string) string { - return fmt.Sprintf(` +func testAccComputeRoute_routeBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_compute_route" "default" { - name = "network-route-%s" + name = "network-route-%{random_suffix}" dest_range = "15.0.0.0/24" network = "${google_compute_network.default.name}" next_hop_ip = "10.132.1.5" @@ -55,10 +59,9 @@ resource "google_compute_route" "default" { } resource "google_compute_network" "default" { - name = "compute-network-%s" + name = "compute-network-%{random_suffix}" } -`, val, val, - ) +`, context) } func testAccCheckComputeRouteDestroy(s *terraform.State) error { diff --git a/google-beta/resource_compute_router_generated_test.go b/google-beta/resource_compute_router_generated_test.go index d213b01679..34ae3fe60a 100644 --- a/google-beta/resource_compute_router_generated_test.go +++ b/google-beta/resource_compute_router_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccComputeRouter_routerBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeRouterDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeRouter_routerBasicExample(acctest.RandString(10)), + Config: testAccComputeRouter_routerBasicExample(context), }, { ResourceName: "google_compute_router.foobar", @@ -44,10 +48,10 @@ func TestAccComputeRouter_routerBasicExample(t *testing.T) { }) } -func testAccComputeRouter_routerBasicExample(val string) string { - return fmt.Sprintf(` +func testAccComputeRouter_routerBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_compute_router" "foobar" { - name = "my-router-%s" + name = "my-router-%{random_suffix}" network = "${google_compute_network.foobar.name}" bgp { asn = 64514 @@ -63,11 +67,10 @@ resource "google_compute_router" "foobar" { } resource "google_compute_network" "foobar" { - name = "my-network-%s" + name = "my-network-%{random_suffix}" auto_create_subnetworks = false } -`, val, val, - ) +`, context) } func testAccCheckComputeRouterDestroy(s *terraform.State) error { diff --git a/google-beta/resource_compute_snapshot_generated_test.go b/google-beta/resource_compute_snapshot_generated_test.go index 1ab4e256ed..bff95e3dbc 100644 --- a/google-beta/resource_compute_snapshot_generated_test.go +++ b/google-beta/resource_compute_snapshot_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccComputeSnapshot_snapshotBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeSnapshotDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeSnapshot_snapshotBasicExample(acctest.RandString(10)), + Config: testAccComputeSnapshot_snapshotBasicExample(context), }, { ResourceName: "google_compute_snapshot.snapshot", @@ -45,10 +49,10 @@ func TestAccComputeSnapshot_snapshotBasicExample(t *testing.T) { }) } -func testAccComputeSnapshot_snapshotBasicExample(val string) string { - return fmt.Sprintf(` +func testAccComputeSnapshot_snapshotBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_compute_snapshot" "snapshot" { - name = "my-snapshot-%s" + name = "my-snapshot-%{random_suffix}" source_disk = "${google_compute_disk.persistent.name}" zone = "us-central1-a" labels = { @@ -62,14 +66,13 @@ data "google_compute_image" "debian" { } resource "google_compute_disk" "persistent" { - name = "debian-disk-%s" + name = "debian-disk-%{random_suffix}" image = "${data.google_compute_image.debian.self_link}" size = 10 type = "pd-ssd" zone = "us-central1-a" } -`, val, val, - ) +`, context) } func testAccCheckComputeSnapshotDestroy(s *terraform.State) error { diff --git a/google-beta/resource_compute_ssl_certificate_generated_test.go b/google-beta/resource_compute_ssl_certificate_generated_test.go index 6248cdaff2..ec2216824d 100644 --- a/google-beta/resource_compute_ssl_certificate_generated_test.go +++ b/google-beta/resource_compute_ssl_certificate_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccComputeSslCertificate_sslCertificateBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeSslCertificateDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeSslCertificate_sslCertificateBasicExample(acctest.RandString(10)), + Config: testAccComputeSslCertificate_sslCertificateBasicExample(context), }, { ResourceName: "google_compute_ssl_certificate.default", @@ -45,8 +49,8 @@ func TestAccComputeSslCertificate_sslCertificateBasicExample(t *testing.T) { }) } -func testAccComputeSslCertificate_sslCertificateBasicExample(val string) string { - return fmt.Sprintf(` +func testAccComputeSslCertificate_sslCertificateBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_compute_ssl_certificate" "default" { name_prefix = "my-certificate-" description = "a description" @@ -57,20 +61,23 @@ resource "google_compute_ssl_certificate" "default" { create_before_destroy = true } } -`, - ) +`, context) } func TestAccComputeSslCertificate_sslCertificateRandomProviderExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeSslCertificateDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeSslCertificate_sslCertificateRandomProviderExample(acctest.RandString(10)), + Config: testAccComputeSslCertificate_sslCertificateRandomProviderExample(context), }, { ResourceName: "google_compute_ssl_certificate.default", @@ -82,8 +89,8 @@ func TestAccComputeSslCertificate_sslCertificateRandomProviderExample(t *testing }) } -func testAccComputeSslCertificate_sslCertificateRandomProviderExample(val string) string { - return fmt.Sprintf(` +func testAccComputeSslCertificate_sslCertificateRandomProviderExample(context map[string]interface{}) string { + return Nprintf(` # You may also want to control name generation explicitly: resource "google_compute_ssl_certificate" "default" { # The name will contain 8 random hex digits, @@ -107,20 +114,23 @@ resource "random_id" "certificate" { certificate = "${base64sha256(file("test-fixtures/ssl_cert/test.crt"))}" } } -`, - ) +`, context) } func TestAccComputeSslCertificate_sslCertificateTargetHttpsProxiesExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeSslCertificateDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeSslCertificate_sslCertificateTargetHttpsProxiesExample(acctest.RandString(10)), + Config: testAccComputeSslCertificate_sslCertificateTargetHttpsProxiesExample(context), }, { ResourceName: "google_compute_ssl_certificate.default", @@ -132,8 +142,8 @@ func TestAccComputeSslCertificate_sslCertificateTargetHttpsProxiesExample(t *tes }) } -func testAccComputeSslCertificate_sslCertificateTargetHttpsProxiesExample(val string) string { - return fmt.Sprintf(` +func testAccComputeSslCertificate_sslCertificateTargetHttpsProxiesExample(context map[string]interface{}) string { + return Nprintf(` // Using with Target HTTPS Proxies // // SSL certificates cannot be updated after creation. In order to apply @@ -155,13 +165,13 @@ resource "google_compute_ssl_certificate" "default" { } resource "google_compute_target_https_proxy" "default" { - name = "test-proxy-%s" + name = "test-proxy-%{random_suffix}" url_map = "${google_compute_url_map.default.self_link}" ssl_certificates = ["${google_compute_ssl_certificate.default.self_link}"] } resource "google_compute_url_map" "default" { - name = "url-map-%s" + name = "url-map-%{random_suffix}" description = "a description" default_service = "${google_compute_backend_service.default.self_link}" @@ -183,7 +193,7 @@ resource "google_compute_url_map" "default" { } resource "google_compute_backend_service" "default" { - name = "backend-service-%s" + name = "backend-service-%{random_suffix}" port_name = "http" protocol = "HTTP" timeout_sec = 10 @@ -192,13 +202,12 @@ resource "google_compute_backend_service" "default" { } resource "google_compute_http_health_check" "default" { - name = "http-health-check-%s" + name = "http-health-check-%{random_suffix}" request_path = "/" check_interval_sec = 1 timeout_sec = 1 } -`, val, val, val, val, - ) +`, context) } func testAccCheckComputeSslCertificateDestroy(s *terraform.State) error { diff --git a/google-beta/resource_compute_ssl_policy_generated_test.go b/google-beta/resource_compute_ssl_policy_generated_test.go index 790acc62b3..53849c79a3 100644 --- a/google-beta/resource_compute_ssl_policy_generated_test.go +++ b/google-beta/resource_compute_ssl_policy_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccComputeSslPolicy_sslPolicyBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeSslPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeSslPolicy_sslPolicyBasicExample(acctest.RandString(10)), + Config: testAccComputeSslPolicy_sslPolicyBasicExample(context), }, { ResourceName: "google_compute_ssl_policy.prod-ssl-policy", @@ -44,27 +48,26 @@ func TestAccComputeSslPolicy_sslPolicyBasicExample(t *testing.T) { }) } -func testAccComputeSslPolicy_sslPolicyBasicExample(val string) string { - return fmt.Sprintf(` +func testAccComputeSslPolicy_sslPolicyBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_compute_ssl_policy" "prod-ssl-policy" { - name = "production-ssl-policy-%s" + name = "production-ssl-policy-%{random_suffix}" profile = "MODERN" } resource "google_compute_ssl_policy" "nonprod-ssl-policy" { - name = "nonprod-ssl-policy-%s" + name = "nonprod-ssl-policy-%{random_suffix}" profile = "MODERN" min_tls_version = "TLS_1_2" } resource "google_compute_ssl_policy" "custom-ssl-policy" { - name = "custom-ssl-policy-%s" + name = "custom-ssl-policy-%{random_suffix}" min_tls_version = "TLS_1_2" profile = "CUSTOM" custom_features = ["TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"] } -`, val, val, val, - ) +`, context) } func testAccCheckComputeSslPolicyDestroy(s *terraform.State) error { diff --git a/google-beta/resource_compute_subnetwork_generated_test.go b/google-beta/resource_compute_subnetwork_generated_test.go index d05b56dd75..12e370c3c1 100644 --- a/google-beta/resource_compute_subnetwork_generated_test.go +++ b/google-beta/resource_compute_subnetwork_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccComputeSubnetwork_subnetworkBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeSubnetworkDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeSubnetwork_subnetworkBasicExample(acctest.RandString(10)), + Config: testAccComputeSubnetwork_subnetworkBasicExample(context), }, { ResourceName: "google_compute_subnetwork.network-with-private-secondary-ip-ranges", @@ -44,10 +48,10 @@ func TestAccComputeSubnetwork_subnetworkBasicExample(t *testing.T) { }) } -func testAccComputeSubnetwork_subnetworkBasicExample(val string) string { - return fmt.Sprintf(` +func testAccComputeSubnetwork_subnetworkBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_compute_subnetwork" "network-with-private-secondary-ip-ranges" { - name = "test-subnetwork-%s" + name = "test-subnetwork-%{random_suffix}" ip_cidr_range = "10.2.0.0/16" region = "us-central1" network = "${google_compute_network.custom-test.self_link}" @@ -58,11 +62,10 @@ resource "google_compute_subnetwork" "network-with-private-secondary-ip-ranges" } resource "google_compute_network" "custom-test" { - name = "test-network-%s" + name = "test-network-%{random_suffix}" auto_create_subnetworks = false } -`, val, val, - ) +`, context) } func testAccCheckComputeSubnetworkDestroy(s *terraform.State) error { diff --git a/google-beta/resource_compute_target_http_proxy_generated_test.go b/google-beta/resource_compute_target_http_proxy_generated_test.go index e2ab9db0d0..c8f440fe76 100644 --- a/google-beta/resource_compute_target_http_proxy_generated_test.go +++ b/google-beta/resource_compute_target_http_proxy_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccComputeTargetHttpProxy_targetHttpProxyBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeTargetHttpProxyDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeTargetHttpProxy_targetHttpProxyBasicExample(acctest.RandString(10)), + Config: testAccComputeTargetHttpProxy_targetHttpProxyBasicExample(context), }, { ResourceName: "google_compute_target_http_proxy.default", @@ -44,15 +48,15 @@ func TestAccComputeTargetHttpProxy_targetHttpProxyBasicExample(t *testing.T) { }) } -func testAccComputeTargetHttpProxy_targetHttpProxyBasicExample(val string) string { - return fmt.Sprintf(` +func testAccComputeTargetHttpProxy_targetHttpProxyBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_compute_target_http_proxy" "default" { - name = "test-proxy-%s" + name = "test-proxy-%{random_suffix}" url_map = "${google_compute_url_map.default.self_link}" } resource "google_compute_url_map" "default" { - name = "url-map-%s" + name = "url-map-%{random_suffix}" default_service = "${google_compute_backend_service.default.self_link}" host_rule { @@ -72,7 +76,7 @@ resource "google_compute_url_map" "default" { } resource "google_compute_backend_service" "default" { - name = "backend-service-%s" + name = "backend-service-%{random_suffix}" port_name = "http" protocol = "HTTP" timeout_sec = 10 @@ -81,13 +85,12 @@ resource "google_compute_backend_service" "default" { } resource "google_compute_http_health_check" "default" { - name = "http-health-check-%s" + name = "http-health-check-%{random_suffix}" request_path = "/" check_interval_sec = 1 timeout_sec = 1 } -`, val, val, val, val, - ) +`, context) } func testAccCheckComputeTargetHttpProxyDestroy(s *terraform.State) error { diff --git a/google-beta/resource_compute_target_https_proxy_generated_test.go b/google-beta/resource_compute_target_https_proxy_generated_test.go index c0ad859c8e..735eed53a3 100644 --- a/google-beta/resource_compute_target_https_proxy_generated_test.go +++ b/google-beta/resource_compute_target_https_proxy_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccComputeTargetHttpsProxy_targetHttpsProxyBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeTargetHttpsProxyDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeTargetHttpsProxy_targetHttpsProxyBasicExample(acctest.RandString(10)), + Config: testAccComputeTargetHttpsProxy_targetHttpsProxyBasicExample(context), }, { ResourceName: "google_compute_target_https_proxy.default", @@ -44,22 +48,22 @@ func TestAccComputeTargetHttpsProxy_targetHttpsProxyBasicExample(t *testing.T) { }) } -func testAccComputeTargetHttpsProxy_targetHttpsProxyBasicExample(val string) string { - return fmt.Sprintf(` +func testAccComputeTargetHttpsProxy_targetHttpsProxyBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_compute_target_https_proxy" "default" { - name = "test-proxy-%s" + name = "test-proxy-%{random_suffix}" url_map = "${google_compute_url_map.default.self_link}" ssl_certificates = ["${google_compute_ssl_certificate.default.self_link}"] } resource "google_compute_ssl_certificate" "default" { - name = "my-certificate-%s" + name = "my-certificate-%{random_suffix}" private_key = "${file("test-fixtures/ssl_cert/test.key")}" certificate = "${file("test-fixtures/ssl_cert/test.crt")}" } resource "google_compute_url_map" "default" { - name = "url-map-%s" + name = "url-map-%{random_suffix}" description = "a description" default_service = "${google_compute_backend_service.default.self_link}" @@ -81,7 +85,7 @@ resource "google_compute_url_map" "default" { } resource "google_compute_backend_service" "default" { - name = "backend-service-%s" + name = "backend-service-%{random_suffix}" port_name = "http" protocol = "HTTP" timeout_sec = 10 @@ -90,13 +94,12 @@ resource "google_compute_backend_service" "default" { } resource "google_compute_http_health_check" "default" { - name = "http-health-check-%s" + name = "http-health-check-%{random_suffix}" request_path = "/" check_interval_sec = 1 timeout_sec = 1 } -`, val, val, val, val, val, - ) +`, context) } func testAccCheckComputeTargetHttpsProxyDestroy(s *terraform.State) error { diff --git a/google-beta/resource_compute_target_ssl_proxy_generated_test.go b/google-beta/resource_compute_target_ssl_proxy_generated_test.go index 2c2d3f812a..ccd44d5e26 100644 --- a/google-beta/resource_compute_target_ssl_proxy_generated_test.go +++ b/google-beta/resource_compute_target_ssl_proxy_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccComputeTargetSslProxy_targetSslProxyBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeTargetSslProxyDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeTargetSslProxy_targetSslProxyBasicExample(acctest.RandString(10)), + Config: testAccComputeTargetSslProxy_targetSslProxyBasicExample(context), }, { ResourceName: "google_compute_target_ssl_proxy.default", @@ -44,36 +48,35 @@ func TestAccComputeTargetSslProxy_targetSslProxyBasicExample(t *testing.T) { }) } -func testAccComputeTargetSslProxy_targetSslProxyBasicExample(val string) string { - return fmt.Sprintf(` +func testAccComputeTargetSslProxy_targetSslProxyBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_compute_target_ssl_proxy" "default" { - name = "test-proxy-%s" + name = "test-proxy-%{random_suffix}" backend_service = "${google_compute_backend_service.default.self_link}" ssl_certificates = ["${google_compute_ssl_certificate.default.self_link}"] } resource "google_compute_ssl_certificate" "default" { - name = "default-cert-%s" + name = "default-cert-%{random_suffix}" private_key = "${file("test-fixtures/ssl_cert/test.key")}" certificate = "${file("test-fixtures/ssl_cert/test.crt")}" } resource "google_compute_backend_service" "default" { - name = "backend-service-%s" + name = "backend-service-%{random_suffix}" protocol = "SSL" health_checks = ["${google_compute_health_check.default.self_link}"] } resource "google_compute_health_check" "default" { - name = "health-check-%s" + name = "health-check-%{random_suffix}" check_interval_sec = 1 timeout_sec = 1 tcp_health_check { port = "443" } } -`, val, val, val, val, - ) +`, context) } func testAccCheckComputeTargetSslProxyDestroy(s *terraform.State) error { diff --git a/google-beta/resource_compute_target_tcp_proxy_generated_test.go b/google-beta/resource_compute_target_tcp_proxy_generated_test.go index 8e66ca619f..69807b0ea0 100644 --- a/google-beta/resource_compute_target_tcp_proxy_generated_test.go +++ b/google-beta/resource_compute_target_tcp_proxy_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccComputeTargetTcpProxy_targetTcpProxyBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeTargetTcpProxyDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeTargetTcpProxy_targetTcpProxyBasicExample(acctest.RandString(10)), + Config: testAccComputeTargetTcpProxy_targetTcpProxyBasicExample(context), }, { ResourceName: "google_compute_target_tcp_proxy.default", @@ -44,15 +48,15 @@ func TestAccComputeTargetTcpProxy_targetTcpProxyBasicExample(t *testing.T) { }) } -func testAccComputeTargetTcpProxy_targetTcpProxyBasicExample(val string) string { - return fmt.Sprintf(` +func testAccComputeTargetTcpProxy_targetTcpProxyBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_compute_target_tcp_proxy" "default" { - name = "test-proxy-%s" + name = "test-proxy-%{random_suffix}" backend_service = "${google_compute_backend_service.default.self_link}" } resource "google_compute_backend_service" "default" { - name = "backend-service-%s" + name = "backend-service-%{random_suffix}" protocol = "TCP" timeout_sec = 10 @@ -60,7 +64,7 @@ resource "google_compute_backend_service" "default" { } resource "google_compute_health_check" "default" { - name = "health-check-%s" + name = "health-check-%{random_suffix}" timeout_sec = 1 check_interval_sec = 1 @@ -68,8 +72,7 @@ resource "google_compute_health_check" "default" { port = "443" } } -`, val, val, val, - ) +`, context) } func testAccCheckComputeTargetTcpProxyDestroy(s *terraform.State) error { diff --git a/google-beta/resource_compute_url_map_generated_test.go b/google-beta/resource_compute_url_map_generated_test.go index a7b14da04e..f83a61b37d 100644 --- a/google-beta/resource_compute_url_map_generated_test.go +++ b/google-beta/resource_compute_url_map_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccComputeUrlMap_urlMapBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeUrlMapDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeUrlMap_urlMapBasicExample(acctest.RandString(10)), + Config: testAccComputeUrlMap_urlMapBasicExample(context), }, { ResourceName: "google_compute_url_map.urlmap", @@ -44,10 +48,10 @@ func TestAccComputeUrlMap_urlMapBasicExample(t *testing.T) { }) } -func testAccComputeUrlMap_urlMapBasicExample(val string) string { - return fmt.Sprintf(` +func testAccComputeUrlMap_urlMapBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_compute_url_map" "urlmap" { - name = "urlmap-%s" + name = "urlmap-%{random_suffix}" description = "a description" default_service = "${google_compute_backend_service.home.self_link}" @@ -85,7 +89,7 @@ resource "google_compute_url_map" "urlmap" { } resource "google_compute_backend_service" "login" { - name = "login-%s" + name = "login-%{random_suffix}" port_name = "http" protocol = "HTTP" timeout_sec = 10 @@ -94,7 +98,7 @@ resource "google_compute_backend_service" "login" { } resource "google_compute_backend_service" "home" { - name = "home-%s" + name = "home-%{random_suffix}" port_name = "http" protocol = "HTTP" timeout_sec = 10 @@ -103,24 +107,23 @@ resource "google_compute_backend_service" "home" { } resource "google_compute_http_health_check" "default" { - name = "health-check-%s" + name = "health-check-%{random_suffix}" request_path = "/" check_interval_sec = 1 timeout_sec = 1 } resource "google_compute_backend_bucket" "static" { - name = "static-asset-backend-bucket-%s" + name = "static-asset-backend-bucket-%{random_suffix}" bucket_name = "${google_storage_bucket.static.name}" enable_cdn = true } resource "google_storage_bucket" "static" { - name = "static-asset-bucket-%s" + name = "static-asset-bucket-%{random_suffix}" location = "US" } -`, val, val, val, val, val, val, - ) +`, context) } func testAccCheckComputeUrlMapDestroy(s *terraform.State) error { diff --git a/google-beta/resource_compute_vpn_gateway_generated_test.go b/google-beta/resource_compute_vpn_gateway_generated_test.go index c2f6dcf51c..eb705e833b 100644 --- a/google-beta/resource_compute_vpn_gateway_generated_test.go +++ b/google-beta/resource_compute_vpn_gateway_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccComputeVpnGateway_targetVpnGatewayBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeVpnGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeVpnGateway_targetVpnGatewayBasicExample(acctest.RandString(10)), + Config: testAccComputeVpnGateway_targetVpnGatewayBasicExample(context), }, { ResourceName: "google_compute_vpn_gateway.target_gateway", @@ -44,30 +48,30 @@ func TestAccComputeVpnGateway_targetVpnGatewayBasicExample(t *testing.T) { }) } -func testAccComputeVpnGateway_targetVpnGatewayBasicExample(val string) string { - return fmt.Sprintf(` +func testAccComputeVpnGateway_targetVpnGatewayBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_compute_vpn_gateway" "target_gateway" { - name = "vpn1-%s" + name = "vpn1-%{random_suffix}" network = "${google_compute_network.network1.self_link}" } resource "google_compute_network" "network1" { - name = "network1-%s" + name = "network1-%{random_suffix}" } resource "google_compute_address" "vpn_static_ip" { - name = "vpn-static-ip-%s" + name = "vpn-static-ip-%{random_suffix}" } resource "google_compute_forwarding_rule" "fr_esp" { - name = "fr-esp-%s" + name = "fr-esp-%{random_suffix}" ip_protocol = "ESP" ip_address = "${google_compute_address.vpn_static_ip.address}" target = "${google_compute_vpn_gateway.target_gateway.self_link}" } resource "google_compute_forwarding_rule" "fr_udp500" { - name = "fr-udp500-%s" + name = "fr-udp500-%{random_suffix}" ip_protocol = "UDP" port_range = "500" ip_address = "${google_compute_address.vpn_static_ip.address}" @@ -75,7 +79,7 @@ resource "google_compute_forwarding_rule" "fr_udp500" { } resource "google_compute_forwarding_rule" "fr_udp4500" { - name = "fr-udp4500-%s" + name = "fr-udp4500-%{random_suffix}" ip_protocol = "UDP" port_range = "4500" ip_address = "${google_compute_address.vpn_static_ip.address}" @@ -83,7 +87,7 @@ resource "google_compute_forwarding_rule" "fr_udp4500" { } resource "google_compute_vpn_tunnel" "tunnel1" { - name = "tunnel1-%s" + name = "tunnel1-%{random_suffix}" peer_ip = "15.0.0.120" shared_secret = "a secret message" @@ -97,15 +101,14 @@ resource "google_compute_vpn_tunnel" "tunnel1" { } resource "google_compute_route" "route1" { - name = "route1-%s" + name = "route1-%{random_suffix}" network = "${google_compute_network.network1.name}" dest_range = "15.0.0.0/24" priority = 1000 next_hop_vpn_tunnel = "${google_compute_vpn_tunnel.tunnel1.self_link}" } -`, val, val, val, val, val, val, val, val, - ) +`, context) } func testAccCheckComputeVpnGatewayDestroy(s *terraform.State) error { diff --git a/google-beta/resource_compute_vpn_tunnel_generated_test.go b/google-beta/resource_compute_vpn_tunnel_generated_test.go index 992516be2d..de7168019d 100644 --- a/google-beta/resource_compute_vpn_tunnel_generated_test.go +++ b/google-beta/resource_compute_vpn_tunnel_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccComputeVpnTunnel_vpnTunnelBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckComputeVpnTunnelDestroy, Steps: []resource.TestStep{ { - Config: testAccComputeVpnTunnel_vpnTunnelBasicExample(acctest.RandString(10)), + Config: testAccComputeVpnTunnel_vpnTunnelBasicExample(context), }, { ResourceName: "google_compute_vpn_tunnel.tunnel1", @@ -45,10 +49,10 @@ func TestAccComputeVpnTunnel_vpnTunnelBasicExample(t *testing.T) { }) } -func testAccComputeVpnTunnel_vpnTunnelBasicExample(val string) string { - return fmt.Sprintf(` +func testAccComputeVpnTunnel_vpnTunnelBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_compute_vpn_tunnel" "tunnel1" { - name = "tunnel1-%s" + name = "tunnel1-%{random_suffix}" peer_ip = "15.0.0.120" shared_secret = "a secret message" @@ -62,27 +66,27 @@ resource "google_compute_vpn_tunnel" "tunnel1" { } resource "google_compute_vpn_gateway" "target_gateway" { - name = "vpn1-%s" + name = "vpn1-%{random_suffix}" network = "${google_compute_network.network1.self_link}" } resource "google_compute_network" "network1" { - name = "network1-%s" + name = "network1-%{random_suffix}" } resource "google_compute_address" "vpn_static_ip" { - name = "vpn-static-ip-%s" + name = "vpn-static-ip-%{random_suffix}" } resource "google_compute_forwarding_rule" "fr_esp" { - name = "fr-esp-%s" + name = "fr-esp-%{random_suffix}" ip_protocol = "ESP" ip_address = "${google_compute_address.vpn_static_ip.address}" target = "${google_compute_vpn_gateway.target_gateway.self_link}" } resource "google_compute_forwarding_rule" "fr_udp500" { - name = "fr-udp500-%s" + name = "fr-udp500-%{random_suffix}" ip_protocol = "UDP" port_range = "500" ip_address = "${google_compute_address.vpn_static_ip.address}" @@ -90,7 +94,7 @@ resource "google_compute_forwarding_rule" "fr_udp500" { } resource "google_compute_forwarding_rule" "fr_udp4500" { - name = "fr-udp4500-%s" + name = "fr-udp4500-%{random_suffix}" ip_protocol = "UDP" port_range = "4500" ip_address = "${google_compute_address.vpn_static_ip.address}" @@ -98,15 +102,14 @@ resource "google_compute_forwarding_rule" "fr_udp4500" { } resource "google_compute_route" "route1" { - name = "route1-%s" + name = "route1-%{random_suffix}" network = "${google_compute_network.network1.name}" dest_range = "15.0.0.0/24" priority = 1000 next_hop_vpn_tunnel = "${google_compute_vpn_tunnel.tunnel1.self_link}" } -`, val, val, val, val, val, val, val, val, - ) +`, context) } func testAccCheckComputeVpnTunnelDestroy(s *terraform.State) error { diff --git a/google-beta/resource_containeranalysis_note_generated_test.go b/google-beta/resource_containeranalysis_note_generated_test.go index fb873024fd..4a603a98ad 100644 --- a/google-beta/resource_containeranalysis_note_generated_test.go +++ b/google-beta/resource_containeranalysis_note_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccContainerAnalysisNote_containerAnalysisNoteBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckContainerAnalysisNoteDestroy, Steps: []resource.TestStep{ { - Config: testAccContainerAnalysisNote_containerAnalysisNoteBasicExample(acctest.RandString(10)), + Config: testAccContainerAnalysisNote_containerAnalysisNoteBasicExample(context), }, { ResourceName: "google_container_analysis_note.note", @@ -44,18 +48,17 @@ func TestAccContainerAnalysisNote_containerAnalysisNoteBasicExample(t *testing.T }) } -func testAccContainerAnalysisNote_containerAnalysisNoteBasicExample(val string) string { - return fmt.Sprintf(` +func testAccContainerAnalysisNote_containerAnalysisNoteBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_container_analysis_note" "note" { - name = "test-attestor-note-%s" + name = "test-attestor-note-%{random_suffix}" attestation_authority { hint { human_readable_name = "Attestor Note" } } } -`, val, - ) +`, context) } func testAccCheckContainerAnalysisNoteDestroy(s *terraform.State) error { diff --git a/google-beta/resource_dns_managed_zone_generated_test.go b/google-beta/resource_dns_managed_zone_generated_test.go index f51c868db2..36c70d2204 100644 --- a/google-beta/resource_dns_managed_zone_generated_test.go +++ b/google-beta/resource_dns_managed_zone_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccDnsManagedZone_dnsManagedZoneBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckDnsManagedZoneDestroy, Steps: []resource.TestStep{ { - Config: testAccDnsManagedZone_dnsManagedZoneBasicExample(acctest.RandString(10)), + Config: testAccDnsManagedZone_dnsManagedZoneBasicExample(context), }, { ResourceName: "google_dns_managed_zone.example-zone", @@ -44,8 +48,8 @@ func TestAccDnsManagedZone_dnsManagedZoneBasicExample(t *testing.T) { }) } -func testAccDnsManagedZone_dnsManagedZoneBasicExample(val string) string { - return fmt.Sprintf(` +func testAccDnsManagedZone_dnsManagedZoneBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_dns_managed_zone" "example-zone" { name = "example-zone" dns_name = "example-${random_id.rnd.hex}.com." @@ -58,8 +62,7 @@ resource "google_dns_managed_zone" "example-zone" { resource "random_id" "rnd" { byte_length = 4 } -`, - ) +`, context) } func testAccCheckDnsManagedZoneDestroy(s *terraform.State) error { diff --git a/google-beta/resource_filestore_instance_generated_test.go b/google-beta/resource_filestore_instance_generated_test.go index 2e1154ecd6..d371f25d08 100644 --- a/google-beta/resource_filestore_instance_generated_test.go +++ b/google-beta/resource_filestore_instance_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccFilestoreInstance_filestoreInstanceBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckFilestoreInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccFilestoreInstance_filestoreInstanceBasicExample(acctest.RandString(10)), + Config: testAccFilestoreInstance_filestoreInstanceBasicExample(context), }, { ResourceName: "google_filestore_instance.instance", @@ -45,10 +49,10 @@ func TestAccFilestoreInstance_filestoreInstanceBasicExample(t *testing.T) { }) } -func testAccFilestoreInstance_filestoreInstanceBasicExample(val string) string { - return fmt.Sprintf(` +func testAccFilestoreInstance_filestoreInstanceBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_filestore_instance" "instance" { - name = "test-instance-%s" + name = "test-instance-%{random_suffix}" zone = "us-central1-b" tier = "PREMIUM" @@ -62,8 +66,7 @@ resource "google_filestore_instance" "instance" { modes = ["MODE_IPV4"] } } -`, val, - ) +`, context) } func testAccCheckFilestoreInstanceDestroy(s *terraform.State) error { diff --git a/google-beta/resource_monitoring_group_generated_test.go b/google-beta/resource_monitoring_group_generated_test.go index 2940b2f1e4..e1c7616385 100644 --- a/google-beta/resource_monitoring_group_generated_test.go +++ b/google-beta/resource_monitoring_group_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccMonitoringGroup_monitoringGroupBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckMonitoringGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccMonitoringGroup_monitoringGroupBasicExample(acctest.RandString(10)), + Config: testAccMonitoringGroup_monitoringGroupBasicExample(context), }, { ResourceName: "google_monitoring_group.basic", @@ -44,27 +48,30 @@ func TestAccMonitoringGroup_monitoringGroupBasicExample(t *testing.T) { }) } -func testAccMonitoringGroup_monitoringGroupBasicExample(val string) string { - return fmt.Sprintf(` +func testAccMonitoringGroup_monitoringGroupBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_monitoring_group" "basic" { - display_name = "New Test Group-%s" + display_name = "New Test Group-%{random_suffix}" filter = "resource.metadata.region=\"europe-west2\"" } -`, val, - ) +`, context) } func TestAccMonitoringGroup_monitoringGroupSubgroupExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckMonitoringGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccMonitoringGroup_monitoringGroupSubgroupExample(acctest.RandString(10)), + Config: testAccMonitoringGroup_monitoringGroupSubgroupExample(context), }, { ResourceName: "google_monitoring_group.subgroup", @@ -75,20 +82,19 @@ func TestAccMonitoringGroup_monitoringGroupSubgroupExample(t *testing.T) { }) } -func testAccMonitoringGroup_monitoringGroupSubgroupExample(val string) string { - return fmt.Sprintf(` +func testAccMonitoringGroup_monitoringGroupSubgroupExample(context map[string]interface{}) string { + return Nprintf(` resource "google_monitoring_group" "parent" { - display_name = "New Test SubGroup-%s" + display_name = "New Test SubGroup-%{random_suffix}" filter = "resource.metadata.region=\"europe-west2\"" } resource "google_monitoring_group" "subgroup" { - display_name = "New Test SubGroup-%s" + display_name = "New Test SubGroup-%{random_suffix}" filter = "resource.metadata.region=\"europe-west2\"" parent_name = "${google_monitoring_group.parent.name}" } -`, val, val, - ) +`, context) } func testAccCheckMonitoringGroupDestroy(s *terraform.State) error { diff --git a/google-beta/resource_monitoring_notification_channel_generated_test.go b/google-beta/resource_monitoring_notification_channel_generated_test.go index 6751892f36..a451fc4265 100644 --- a/google-beta/resource_monitoring_notification_channel_generated_test.go +++ b/google-beta/resource_monitoring_notification_channel_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccMonitoringNotificationChannel_notificationChannelBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckMonitoringNotificationChannelDestroy, Steps: []resource.TestStep{ { - Config: testAccMonitoringNotificationChannel_notificationChannelBasicExample(acctest.RandString(10)), + Config: testAccMonitoringNotificationChannel_notificationChannelBasicExample(context), }, { ResourceName: "google_monitoring_notification_channel.basic", @@ -44,17 +48,16 @@ func TestAccMonitoringNotificationChannel_notificationChannelBasicExample(t *tes }) } -func testAccMonitoringNotificationChannel_notificationChannelBasicExample(val string) string { - return fmt.Sprintf(` +func testAccMonitoringNotificationChannel_notificationChannelBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_monitoring_notification_channel" "basic" { - display_name = "Test Notification Channel-%s" + display_name = "Test Notification Channel-%{random_suffix}" type = "email" labels = { email_address = "fake_email@blahblah.com" } } -`, val, - ) +`, context) } func testAccCheckMonitoringNotificationChannelDestroy(s *terraform.State) error { diff --git a/google-beta/resource_monitoring_uptime_check_config_generated_test.go b/google-beta/resource_monitoring_uptime_check_config_generated_test.go index 1e7e4ea996..c4e8d15f25 100644 --- a/google-beta/resource_monitoring_uptime_check_config_generated_test.go +++ b/google-beta/resource_monitoring_uptime_check_config_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccMonitoringUptimeCheckConfig_uptimeCheckConfigHttpExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckMonitoringUptimeCheckConfigDestroy, Steps: []resource.TestStep{ { - Config: testAccMonitoringUptimeCheckConfig_uptimeCheckConfigHttpExample(acctest.RandString(10)), + Config: testAccMonitoringUptimeCheckConfig_uptimeCheckConfigHttpExample(context), }, { ResourceName: "google_monitoring_uptime_check_config.http", @@ -44,10 +48,10 @@ func TestAccMonitoringUptimeCheckConfig_uptimeCheckConfigHttpExample(t *testing. }) } -func testAccMonitoringUptimeCheckConfig_uptimeCheckConfigHttpExample(val string) string { - return fmt.Sprintf(` +func testAccMonitoringUptimeCheckConfig_uptimeCheckConfigHttpExample(context map[string]interface{}) string { + return Nprintf(` resource "google_monitoring_uptime_check_config" "http" { - display_name = "http-uptime-check-%s" + display_name = "http-uptime-check-%{random_suffix}" timeout = "60s" http_check { @@ -67,20 +71,23 @@ resource "google_monitoring_uptime_check_config" "http" { content = "example" } } -`, val, - ) +`, context) } func TestAccMonitoringUptimeCheckConfig_uptimeCheckTcpExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckMonitoringUptimeCheckConfigDestroy, Steps: []resource.TestStep{ { - Config: testAccMonitoringUptimeCheckConfig_uptimeCheckTcpExample(acctest.RandString(10)), + Config: testAccMonitoringUptimeCheckConfig_uptimeCheckTcpExample(context), }, { ResourceName: "google_monitoring_uptime_check_config.tcp_group", @@ -91,10 +98,10 @@ func TestAccMonitoringUptimeCheckConfig_uptimeCheckTcpExample(t *testing.T) { }) } -func testAccMonitoringUptimeCheckConfig_uptimeCheckTcpExample(val string) string { - return fmt.Sprintf(` +func testAccMonitoringUptimeCheckConfig_uptimeCheckTcpExample(context map[string]interface{}) string { + return Nprintf(` resource "google_monitoring_uptime_check_config" "tcp_group" { - display_name = "tcp-uptime-check-%s" + display_name = "tcp-uptime-check-%{random_suffix}" timeout = "60s" tcp_check { @@ -109,11 +116,10 @@ resource "google_monitoring_uptime_check_config" "tcp_group" { resource "google_monitoring_group" "check" { - display_name = "uptime-check-group-%s" + display_name = "uptime-check-group-%{random_suffix}" filter = "resource.metadata.name=has_substring(\"foo\")" } -`, val, val, - ) +`, context) } func testAccCheckMonitoringUptimeCheckConfigDestroy(s *terraform.State) error { diff --git a/google-beta/resource_redis_instance_generated_test.go b/google-beta/resource_redis_instance_generated_test.go index 3d2860fb4a..f0469202c0 100644 --- a/google-beta/resource_redis_instance_generated_test.go +++ b/google-beta/resource_redis_instance_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccRedisInstance_redisInstanceBasicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckRedisInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccRedisInstance_redisInstanceBasicExample(acctest.RandString(10)), + Config: testAccRedisInstance_redisInstanceBasicExample(context), }, { ResourceName: "google_redis_instance.cache", @@ -45,26 +49,29 @@ func TestAccRedisInstance_redisInstanceBasicExample(t *testing.T) { }) } -func testAccRedisInstance_redisInstanceBasicExample(val string) string { - return fmt.Sprintf(` +func testAccRedisInstance_redisInstanceBasicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_redis_instance" "cache" { - name = "memory-cache-%s" + name = "memory-cache-%{random_suffix}" memory_size_gb = 1 } -`, val, - ) +`, context) } func TestAccRedisInstance_redisInstanceFullExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckRedisInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccRedisInstance_redisInstanceFullExample(acctest.RandString(10)), + Config: testAccRedisInstance_redisInstanceFullExample(context), }, { ResourceName: "google_redis_instance.cache", @@ -76,10 +83,10 @@ func TestAccRedisInstance_redisInstanceFullExample(t *testing.T) { }) } -func testAccRedisInstance_redisInstanceFullExample(val string) string { - return fmt.Sprintf(` +func testAccRedisInstance_redisInstanceFullExample(context map[string]interface{}) string { + return Nprintf(` resource "google_redis_instance" "cache" { - name = "ha-memory-cache-%s" + name = "ha-memory-cache-%{random_suffix}" tier = "STANDARD_HA" memory_size_gb = 1 @@ -99,10 +106,9 @@ resource "google_redis_instance" "cache" { } resource "google_compute_network" "auto-network" { - name = "authorized-network-%s" + name = "authorized-network-%{random_suffix}" } -`, val, val, - ) +`, context) } func testAccCheckRedisInstanceDestroy(s *terraform.State) error { diff --git a/google-beta/resource_storage_default_object_access_control_generated_test.go b/google-beta/resource_storage_default_object_access_control_generated_test.go index 7cee156e8a..af91c9bc42 100644 --- a/google-beta/resource_storage_default_object_access_control_generated_test.go +++ b/google-beta/resource_storage_default_object_access_control_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccStorageDefaultObjectAccessControl_storageDefaultObjectAccessControlPublicExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckStorageDefaultObjectAccessControlDestroy, Steps: []resource.TestStep{ { - Config: testAccStorageDefaultObjectAccessControl_storageDefaultObjectAccessControlPublicExample(acctest.RandString(10)), + Config: testAccStorageDefaultObjectAccessControl_storageDefaultObjectAccessControlPublicExample(context), }, { ResourceName: "google_storage_default_object_access_control.public_rule", @@ -45,8 +49,8 @@ func TestAccStorageDefaultObjectAccessControl_storageDefaultObjectAccessControlP }) } -func testAccStorageDefaultObjectAccessControl_storageDefaultObjectAccessControlPublicExample(val string) string { - return fmt.Sprintf(` +func testAccStorageDefaultObjectAccessControl_storageDefaultObjectAccessControlPublicExample(context map[string]interface{}) string { + return Nprintf(` resource "google_storage_default_object_access_control" "public_rule" { bucket = "${google_storage_bucket.bucket.name}" role = "READER" @@ -54,10 +58,9 @@ resource "google_storage_default_object_access_control" "public_rule" { } resource "google_storage_bucket" "bucket" { - name = "static-content-bucket-%s" + name = "static-content-bucket-%{random_suffix}" } -`, val, - ) +`, context) } func testAccCheckStorageDefaultObjectAccessControlDestroy(s *terraform.State) error { diff --git a/google-beta/resource_storage_object_access_control_generated_test.go b/google-beta/resource_storage_object_access_control_generated_test.go index 3d4c36cb0c..b88e5c3f05 100644 --- a/google-beta/resource_storage_object_access_control_generated_test.go +++ b/google-beta/resource_storage_object_access_control_generated_test.go @@ -27,13 +27,17 @@ import ( func TestAccStorageObjectAccessControl_storageObjectAccessControlPublicObjectExample(t *testing.T) { t.Parallel() + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckStorageObjectAccessControlDestroy, Steps: []resource.TestStep{ { - Config: testAccStorageObjectAccessControl_storageObjectAccessControlPublicObjectExample(acctest.RandString(10)), + Config: testAccStorageObjectAccessControl_storageObjectAccessControlPublicObjectExample(context), }, { ResourceName: "google_storage_object_access_control.public_rule", @@ -44,8 +48,8 @@ func TestAccStorageObjectAccessControl_storageObjectAccessControlPublicObjectExa }) } -func testAccStorageObjectAccessControl_storageObjectAccessControlPublicObjectExample(val string) string { - return fmt.Sprintf(` +func testAccStorageObjectAccessControl_storageObjectAccessControlPublicObjectExample(context map[string]interface{}) string { + return Nprintf(` resource "google_storage_object_access_control" "public_rule" { object = "${google_storage_bucket_object.object.name}" bucket = "${google_storage_bucket.bucket.name}" @@ -54,16 +58,15 @@ resource "google_storage_object_access_control" "public_rule" { } resource "google_storage_bucket" "bucket" { - name = "static-content-bucket-%s" + name = "static-content-bucket-%{random_suffix}" } resource "google_storage_bucket_object" "object" { - name = "public-object-%s" + name = "public-object-%{random_suffix}" bucket = "${google_storage_bucket.bucket.name}" source = "test-fixtures/header-logo.png" } -`, val, val, - ) +`, context) } func testAccCheckStorageObjectAccessControlDestroy(s *terraform.State) error { diff --git a/google-beta/transport.go b/google-beta/transport.go index 3a6fe0c199..7b788c5725 100644 --- a/google-beta/transport.go +++ b/google-beta/transport.go @@ -156,7 +156,7 @@ func replaceVars(d TerraformResourceData, config *Config, linkTmpl string) (stri } v, ok := d.GetOk(m) if ok { - return v.(string) + return fmt.Sprintf("%v", v) } return "" } diff --git a/google-beta/utils.go b/google-beta/utils.go index 6778242ece..3c1bde6573 100644 --- a/google-beta/utils.go +++ b/google-beta/utils.go @@ -365,6 +365,17 @@ func lockedCall(lockKey string, f func() error) error { return f() } +// This is a Printf sibling (Nprintf; Named Printf), which handles strings like +// Nprintf("Hello %{target}!", map[string]interface{}{"target":"world"}) == "Hello world!". +// This is particularly useful for generated tests, where we don't want to use Printf, +// since that would require us to generate a very particular ordering of arguments. +func Nprintf(format string, params map[string]interface{}) string { + for key, val := range params { + format = strings.Replace(format, "%{"+key+"}", fmt.Sprintf("%v", val), -1) + } + return format +} + // serviceAccountFQN will attempt to generate the fully qualified name in the format of: // "projects/(-|)/serviceAccounts/@.iam.gserviceaccount.com" // A project is required if we are trying to build the FQN from a service account id and diff --git a/website/docs/r/appengine_firewall_rule.html.markdown b/website/docs/r/appengine_firewall_rule.html.markdown new file mode 100644 index 0000000000..21b34d964c --- /dev/null +++ b/website/docs/r/appengine_firewall_rule.html.markdown @@ -0,0 +1,115 @@ +--- +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +# +# ---------------------------------------------------------------------------- +# +# This file is automatically generated by Magic Modules and manual +# changes will be clobbered when the file is regenerated. +# +# Please read more about how to change this file in +# .github/CONTRIBUTING.md. +# +# ---------------------------------------------------------------------------- +layout: "google" +page_title: "Google: google_appengine_firewall_rule" +sidebar_current: "docs-google-appengine-firewall-rule" +description: |- + A single firewall rule that is evaluated against incoming traffic + and provides an action to take on matched requests. +--- + +# google\_appengine\_firewall\_rule + +A single firewall rule that is evaluated against incoming traffic +and provides an action to take on matched requests. + + +To get more information about FirewallRule, see: + +* [API documentation](https://cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps.firewall.ingressRules) +* How-to Guides + * [Official Documentation](https://cloud.google.com/appengine/docs/standard/python/creating-firewalls#creating_firewall_rules) + + +## Example Usage - Appengine Firewall Rule Basic + + +```hcl +resource "google_project" "my_project" { + name = "tf-test-project" + project_id = "test-project" + org_id = "123456789" +} + +resource "google_app_engine_application" "app" { + project = "${google_project.my_project.project_id}" + location_id = "us-central" +} + +resource "google_appengine_firewall_rule" "rule" { + project = "${google_app_engine_application.app.project}" + priority = 1000 + action = "ALLOW" + source_range = "*" +} +``` + +## Argument Reference + +The following arguments are supported: + + +* `source_range` - + (Required) + IP address or range, defined using CIDR notation, of requests that this rule applies to. + +* `action` - + (Required) + The action to take if this rule matches. + + +- - - + + +* `description` - + (Optional) + An optional string description of this rule. + +* `priority` - + (Optional) + A positive integer that defines the order of rule evaluation. + Rules with the lowest priority are evaluated first. + A default rule at priority Int32.MaxValue matches all IPv4 and + IPv6 traffic when no previous rule matches. Only the action of + this rule can be modified by the user. +* `project` - (Optional) The ID of the project in which the resource belongs. + If it is not provided, the provider project is used. + + + +## Timeouts + +This resource provides the following +[Timeouts](/docs/configuration/resources.html#timeouts) configuration options: + +- `create` - Default is 4 minutes. +- `update` - Default is 4 minutes. +- `delete` - Default is 4 minutes. + +## Import + +FirewallRule can be imported using any of these accepted formats: + +``` +$ terraform import google_appengine_firewall_rule.default {{project}}/{{priority}} +$ terraform import google_appengine_firewall_rule.default {{priority}} +``` + +-> If you're importing a resource with beta features, make sure to include `-provider=google-beta` +as an argument so that Terraform uses the correct provider to import your resource.