diff --git a/aws/resource_aws_route53_record.go b/aws/resource_aws_route53_record.go index 63e1e26ee47..ae101bac131 100644 --- a/aws/resource_aws_route53_record.go +++ b/aws/resource_aws_route53_record.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "log" + "math" "regexp" "strconv" "strings" @@ -84,6 +85,7 @@ func resourceAwsRoute53Record() *schema.Resource { Type: schema.TypeInt, Optional: true, ConflictsWith: []string{"alias"}, + ValidateFunc: validation.IntBetween(0, math.MaxInt32), }, "set_identifier": { @@ -136,13 +138,10 @@ func resourceAwsRoute53Record() *schema.Resource { "type": { Type: schema.TypeString, Required: true, - ValidateFunc: func(v interface{}, k string) (ws []string, es []error) { - value := v.(string) - if value != "PRIMARY" && value != "SECONDARY" { - es = append(es, fmt.Errorf("Failover policy type must be PRIMARY or SECONDARY")) - } - return - }, + ValidateFunc: validation.StringInSlice([]string{ + route53.ResourceRecordSetFailoverPrimary, + route53.ResourceRecordSetFailoverSecondary, + }, false), }, }, }, @@ -181,6 +180,15 @@ func resourceAwsRoute53Record() *schema.Resource { "continent": { Type: schema.TypeString, Optional: true, + ValidateFunc: validation.StringInSlice([]string{ + "AF", + "AN", + "AS", + "EU", + "OC", + "NA", + "SA", + }, false), }, "country": { Type: schema.TypeString, @@ -206,8 +214,9 @@ func resourceAwsRoute53Record() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "weight": { - Type: schema.TypeInt, - Required: true, + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween(0, 255), }, }, }, @@ -234,7 +243,6 @@ func resourceAwsRoute53Record() *schema.Resource { ConflictsWith: []string{"alias"}, Elem: &schema.Schema{Type: schema.TypeString}, Optional: true, - Set: schema.HashString, }, "allow_overwrite": { @@ -295,7 +303,7 @@ func resourceAwsRoute53RecordUpdate(d *schema.ResourceData, meta interface{}) er } } - if v, _ := d.GetChange("ttl"); v.(int) != 0 { + if v, _ := d.GetChange("ttl"); v != nil { oldRec.TTL = aws.Int64(int64(v.(int))) } @@ -537,7 +545,7 @@ func resourceAwsRoute53RecordRead(d *schema.ResourceData, meta interface{}) erro err = d.Set("records", flattenResourceRecords(record.ResourceRecords, aws.StringValue(record.Type))) if err != nil { - return fmt.Errorf("Error setting records for: %s, error: %w", d.Id(), err) + return fmt.Errorf("error setting records for: %s, error: %w", d.Id(), err) } if alias := record.AliasTarget; alias != nil { @@ -558,7 +566,7 @@ func resourceAwsRoute53RecordRead(d *schema.ResourceData, meta interface{}) erro "type": aws.StringValue(record.Failover), }} if err := d.Set("failover_routing_policy", v); err != nil { - return fmt.Errorf("Error setting failover records for: %s, error: %w", d.Id(), err) + return fmt.Errorf("error setting failover records for: %s, error: %w", d.Id(), err) } } @@ -569,7 +577,7 @@ func resourceAwsRoute53RecordRead(d *schema.ResourceData, meta interface{}) erro "subdivision": aws.StringValue(record.GeoLocation.SubdivisionCode), }} if err := d.Set("geolocation_routing_policy", v); err != nil { - return fmt.Errorf("Error setting gelocation records for: %s, error: %w", d.Id(), err) + return fmt.Errorf("error setting gelocation records for: %s, error: %w", d.Id(), err) } } @@ -578,22 +586,22 @@ func resourceAwsRoute53RecordRead(d *schema.ResourceData, meta interface{}) erro "region": aws.StringValue(record.Region), }} if err := d.Set("latency_routing_policy", v); err != nil { - return fmt.Errorf("Error setting latency records for: %s, error: %w", d.Id(), err) + return fmt.Errorf("error setting latency records for: %s, error: %w", d.Id(), err) } } if record.Weight != nil { v := []map[string]interface{}{{ - "weight": aws.Int64Value((record.Weight)), + "weight": aws.Int64Value(record.Weight), }} if err := d.Set("weighted_routing_policy", v); err != nil { - return fmt.Errorf("Error setting weighted records for: %s, error: %w", d.Id(), err) + return fmt.Errorf("error setting weighted records for: %s, error: %w", d.Id(), err) } } if record.MultiValueAnswer != nil { if err := d.Set("multivalue_answer_routing_policy", record.MultiValueAnswer); err != nil { - return fmt.Errorf("Error setting multivalue answer records for: %s, error: %w", d.Id(), err) + return fmt.Errorf("error setting multivalue answer records for: %s, error: %w", d.Id(), err) } } @@ -680,7 +688,7 @@ func findRecord(d *schema.ResourceData, meta interface{}) (*route53.ResourceReco err = conn.ListResourceRecordSetsPages(lopts, func(resp *route53.ListResourceRecordSetsOutput, lastPage bool) bool { for _, recordSet := range resp.ResourceRecordSets { - responseName := strings.ToLower(cleanRecordName(*recordSet.Name)) + responseName := strings.ToLower(cleanRecordName(aws.StringValue(recordSet.Name))) responseType := strings.ToUpper(aws.StringValue(recordSet.Type)) if recordName != responseName { @@ -788,7 +796,7 @@ func resourceAwsRoute53RecordBuildSet(d *schema.ResourceData, zoneName string) ( Type: aws.String(d.Get("type").(string)), } - if v, ok := d.GetOk("ttl"); ok { + if v, ok := d.GetOkExists("ttl"); ok { rec.TTL = aws.Int64(int64(v.(int))) } @@ -812,7 +820,7 @@ func resourceAwsRoute53RecordBuildSet(d *schema.ResourceData, zoneName string) ( } log.Printf("[DEBUG] Creating alias: %#v", alias) } else { - if _, ok := d.GetOk("ttl"); !ok { + if _, ok := d.GetOkExists("ttl"); !ok { return nil, fmt.Errorf(`provider.aws: aws_route53_record: %s: "ttl": required field is not set`, d.Get("name").(string)) } diff --git a/aws/resource_aws_route53_record_test.go b/aws/resource_aws_route53_record_test.go index ecabd2fee9a..c25cbccfe74 100644 --- a/aws/resource_aws_route53_record_test.go +++ b/aws/resource_aws_route53_record_test.go @@ -2,6 +2,7 @@ package aws import ( "fmt" + "regexp" "strings" "testing" @@ -10,10 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/terraform-providers/terraform-provider-aws/aws/internal/tfawsresource" - "regexp" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/route53" ) @@ -108,7 +106,7 @@ func TestParseRecordId(t *testing.T) { func TestAccAWSRoute53Record_basic(t *testing.T) { var record1 route53.ResourceRecordSet - resourceName := "aws_route53_record.default" + resourceName := "aws_route53_record.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -132,9 +130,50 @@ func TestAccAWSRoute53Record_basic(t *testing.T) { }) } +func TestAccAWSRoute53Record_ttl(t *testing.T) { + var record1 route53.ResourceRecordSet + resourceName := "aws_route53_record.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + IDRefreshName: resourceName, + Providers: testAccProviders, + CheckDestroy: testAccCheckRoute53RecordDestroy, + Steps: []resource.TestStep{ + { + Config: testAccRoute53RecordConfigZeroTTL, + Check: resource.ComposeTestCheckFunc( + testAccCheckRoute53RecordExists(resourceName, &record1), + resource.TestCheckResourceAttr(resourceName, "ttl", "0"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"allow_overwrite", "weight"}, + }, + { + Config: testAccRoute53RecordConfig, + Check: resource.ComposeTestCheckFunc( + testAccCheckRoute53RecordExists(resourceName, &record1), + resource.TestCheckResourceAttr(resourceName, "ttl", "30"), + ), + }, + { + Config: testAccRoute53RecordConfigZeroTTL, + Check: resource.ComposeTestCheckFunc( + testAccCheckRoute53RecordExists(resourceName, &record1), + resource.TestCheckResourceAttr(resourceName, "ttl", "0"), + ), + }, + }, + }) +} + func TestAccAWSRoute53Record_underscored(t *testing.T) { var record1 route53.ResourceRecordSet - resourceName := "aws_route53_record.underscore" + resourceName := "aws_route53_record.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -160,7 +199,7 @@ func TestAccAWSRoute53Record_underscored(t *testing.T) { func TestAccAWSRoute53Record_disappears(t *testing.T) { var record1 route53.ResourceRecordSet var zone1 route53.GetHostedZoneOutput - resourceName := "aws_route53_record.default" + resourceName := "aws_route53_record.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -170,9 +209,9 @@ func TestAccAWSRoute53Record_disappears(t *testing.T) { { Config: testAccRoute53RecordConfig, Check: resource.ComposeTestCheckFunc( - testAccCheckRoute53ZoneExists("aws_route53_zone.main", &zone1), + testAccCheckRoute53ZoneExists("aws_route53_zone.test", &zone1), testAccCheckRoute53RecordExists(resourceName, &record1), - testAccCheckRoute53RecordDisappears(&zone1, &record1), + testAccCheckResourceDisappears(testAccProvider, resourceAwsRoute53Record(), resourceName), ), ExpectNonEmptyPlan: true, }, @@ -198,7 +237,7 @@ func TestAccAWSRoute53Record_disappears_MultipleRecords(t *testing.T) { testAccCheckRoute53RecordExists("aws_route53_record.test.2", &record3), testAccCheckRoute53RecordExists("aws_route53_record.test.3", &record4), testAccCheckRoute53RecordExists("aws_route53_record.test.4", &record5), - testAccCheckRoute53RecordDisappears(&zone1, &record1), + testAccCheckResourceDisappears(testAccProvider, resourceAwsRoute53Record(), "aws_route53_record.test.0"), ), ExpectNonEmptyPlan: true, }, @@ -208,7 +247,7 @@ func TestAccAWSRoute53Record_disappears_MultipleRecords(t *testing.T) { func TestAccAWSRoute53Record_basic_fqdn(t *testing.T) { var record1, record2 route53.ResourceRecordSet - resourceName := "aws_route53_record.default" + resourceName := "aws_route53_record.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -275,7 +314,7 @@ func TestAccAWSRoute53Record_basic_trailingPeriodAndZoneID(t *testing.T) { func TestAccAWSRoute53Record_txtSupport(t *testing.T) { var record1 route53.ResourceRecordSet - resourceName := "aws_route53_record.default" + resourceName := "aws_route53_record.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -302,7 +341,7 @@ func TestAccAWSRoute53Record_txtSupport(t *testing.T) { func TestAccAWSRoute53Record_spfSupport(t *testing.T) { var record1 route53.ResourceRecordSet - resourceName := "aws_route53_record.default" + resourceName := "aws_route53_record.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -329,7 +368,7 @@ func TestAccAWSRoute53Record_spfSupport(t *testing.T) { func TestAccAWSRoute53Record_caaSupport(t *testing.T) { var record1 route53.ResourceRecordSet - resourceName := "aws_route53_record.default" + resourceName := "aws_route53_record.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -356,7 +395,7 @@ func TestAccAWSRoute53Record_caaSupport(t *testing.T) { func TestAccAWSRoute53Record_generatesSuffix(t *testing.T) { var record1 route53.ResourceRecordSet - resourceName := "aws_route53_record.default" + resourceName := "aws_route53_record.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -382,7 +421,7 @@ func TestAccAWSRoute53Record_generatesSuffix(t *testing.T) { func TestAccAWSRoute53Record_wildcard(t *testing.T) { var record1, record2 route53.ResourceRecordSet - resourceName := "aws_route53_record.wildcard" + resourceName := "aws_route53_record.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -471,7 +510,7 @@ func TestAccAWSRoute53Record_weighted_basic(t *testing.T) { func TestAccAWSRoute53Record_weighted_to_simple_basic(t *testing.T) { var record1 route53.ResourceRecordSet - resourceName := "aws_route53_record.www-server1" + resourceName := "aws_route53_record.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -502,7 +541,7 @@ func TestAccAWSRoute53Record_weighted_to_simple_basic(t *testing.T) { func TestAccAWSRoute53Record_Alias_Elb(t *testing.T) { var record1 route53.ResourceRecordSet - resourceName := "aws_route53_record.alias" + resourceName := "aws_route53_record.test" rs := acctest.RandString(10) config := fmt.Sprintf(testAccRoute53RecordConfigAliasElb, rs) @@ -586,7 +625,7 @@ func TestAccAWSRoute53Record_Alias_VpcEndpoint(t *testing.T) { func TestAccAWSRoute53Record_Alias_Uppercase(t *testing.T) { var record1 route53.ResourceRecordSet - resourceName := "aws_route53_record.alias" + resourceName := "aws_route53_record.test" rs := acctest.RandString(10) config := fmt.Sprintf(testAccRoute53RecordConfigAliasElbUppercase, rs) @@ -651,7 +690,7 @@ func TestAccAWSRoute53Record_weighted_alias(t *testing.T) { func TestAccAWSRoute53Record_geolocation_basic(t *testing.T) { var record1, record2, record3, record4 route53.ResourceRecordSet - resourceName := "aws_route53_record.default" + resourceName := "aws_route53_record.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -661,7 +700,7 @@ func TestAccAWSRoute53Record_geolocation_basic(t *testing.T) { { Config: testAccRoute53GeolocationCNAMERecord, Check: resource.ComposeTestCheckFunc( - testAccCheckRoute53RecordExists("aws_route53_record.default", &record1), + testAccCheckRoute53RecordExists(resourceName, &record1), testAccCheckRoute53RecordExists("aws_route53_record.california", &record2), testAccCheckRoute53RecordExists("aws_route53_record.oceania", &record3), testAccCheckRoute53RecordExists("aws_route53_record.denmark", &record4), @@ -770,7 +809,7 @@ func TestAccAWSRoute53Record_latency_basic(t *testing.T) { func TestAccAWSRoute53Record_TypeChange(t *testing.T) { var record1, record2 route53.ResourceRecordSet - resourceName := "aws_route53_record.sample" + resourceName := "aws_route53_record.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -839,7 +878,7 @@ func TestAccAWSRoute53Record_NameChange(t *testing.T) { func TestAccAWSRoute53Record_SetIdentifierChange(t *testing.T) { var record1, record2 route53.ResourceRecordSet - resourceName := "aws_route53_record.basic_to_weighted" + resourceName := "aws_route53_record.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -873,7 +912,7 @@ func TestAccAWSRoute53Record_SetIdentifierChange(t *testing.T) { func TestAccAWSRoute53Record_AliasChange(t *testing.T) { var record1, record2 route53.ResourceRecordSet - resourceName := "aws_route53_record.elb_alias_change" + resourceName := "aws_route53_record.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -907,7 +946,7 @@ func TestAccAWSRoute53Record_AliasChange(t *testing.T) { func TestAccAWSRoute53Record_empty(t *testing.T) { var record1 route53.ResourceRecordSet - resourceName := "aws_route53_record.empty" + resourceName := "aws_route53_record.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -928,7 +967,7 @@ func TestAccAWSRoute53Record_empty(t *testing.T) { // Regression test for https://github.com/hashicorp/terraform/issues/8423 func TestAccAWSRoute53Record_longTXTrecord(t *testing.T) { var record1 route53.ResourceRecordSet - resourceName := "aws_route53_record.long_txt" + resourceName := "aws_route53_record.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -1027,11 +1066,8 @@ func testAccCheckRoute53RecordDestroy(s *terraform.State) error { resp, err := conn.ListResourceRecordSets(lopts) if err != nil { - if awsErr, ok := err.(awserr.Error); ok { - // if NoSuchHostedZone, then all the things are destroyed - if awsErr.Code() == "NoSuchHostedZone" { - return nil - } + if isAWSErr(err, route53.ErrCodeNoSuchHostedZone, "") { + return nil } return err } @@ -1039,48 +1075,13 @@ func testAccCheckRoute53RecordDestroy(s *terraform.State) error { return nil } rec := resp.ResourceRecordSets[0] - if FQDN(*rec.Name) == FQDN(name) && *rec.Type == rType { + if FQDN(aws.StringValue(rec.Name)) == FQDN(name) && aws.StringValue(rec.Type) == rType { return fmt.Errorf("Record still exists: %#v", rec) } } return nil } -func testAccCheckRoute53RecordDisappears(zone *route53.GetHostedZoneOutput, resourceRecordSet *route53.ResourceRecordSet) resource.TestCheckFunc { - return func(s *terraform.State) error { - conn := testAccProvider.Meta().(*AWSClient).r53conn - - input := &route53.ChangeResourceRecordSetsInput{ - HostedZoneId: zone.HostedZone.Id, - ChangeBatch: &route53.ChangeBatch{ - Comment: aws.String("Deleted by Terraform"), - Changes: []*route53.Change{ - { - Action: aws.String(route53.ChangeActionDelete), - ResourceRecordSet: resourceRecordSet, - }, - }, - }, - } - - respRaw, err := deleteRoute53RecordSet(conn, input) - if err != nil { - return fmt.Errorf("error deleting resource record set: %s", err) - } - - changeInfo := respRaw.(*route53.ChangeResourceRecordSetsOutput).ChangeInfo - if changeInfo == nil { - return nil - } - - if err := waitForRoute53RecordSetToSync(conn, cleanChangeID(*changeInfo.Id)); err != nil { - return fmt.Errorf("error waiting for resource record set deletion: %s", err) - } - - return nil - } -} - func testAccCheckRoute53RecordExists(n string, resourceRecordSet *route53.ResourceRecordSet) resource.TestCheckFunc { return func(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).r53conn @@ -1116,8 +1117,8 @@ func testAccCheckRoute53RecordExists(n string, resourceRecordSet *route53.Resour // rec := resp.ResourceRecordSets[0] for _, rec := range resp.ResourceRecordSets { - recName := cleanRecordName(*rec.Name) - if FQDN(strings.ToLower(recName)) == FQDN(strings.ToLower(en)) && *rec.Type == rType { + recName := cleanRecordName(aws.StringValue(rec.Name)) + if FQDN(strings.ToLower(recName)) == FQDN(strings.ToLower(en)) && aws.StringValue(rec.Type) == rType { *resourceRecordSet = *rec return nil @@ -1149,8 +1150,8 @@ func testAccCheckRoute53RecordDoesNotExist(zoneResourceName string, recordName s found := false for _, rec := range resp.ResourceRecordSets { - recName := cleanRecordName(*rec.Name) - if FQDN(strings.ToLower(recName)) == FQDN(strings.ToLower(en)) && *rec.Type == recordType { + recName := cleanRecordName(aws.StringValue(rec.Name)) + if FQDN(strings.ToLower(recName)) == FQDN(strings.ToLower(en)) && aws.StringValue(rec.Type) == recordType { found = true break } @@ -1166,12 +1167,12 @@ func testAccCheckRoute53RecordDoesNotExist(zoneResourceName string, recordName s func testAccRoute53RecordConfig_allowOverwrite(allowOverwrite bool) string { return fmt.Sprintf(` -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com." } -resource "aws_route53_record" "default" { - zone_id = aws_route53_zone.main.zone_id +resource "aws_route53_record" "test" { + zone_id = aws_route53_zone.test.zone_id name = "www.notexample.com" type = "A" ttl = "30" @@ -1179,10 +1180,10 @@ resource "aws_route53_record" "default" { } resource "aws_route53_record" "overwriting" { - depends_on = [aws_route53_record.default] + depends_on = ["aws_route53_record.test"] allow_overwrite = %v - zone_id = aws_route53_zone.main.zone_id + zone_id = aws_route53_zone.test.zone_id name = "www.notexample.com" type = "A" ttl = "30" @@ -1192,12 +1193,12 @@ resource "aws_route53_record" "overwriting" { } const testAccRoute53RecordConfig = ` -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } -resource "aws_route53_record" "default" { - zone_id = aws_route53_zone.main.zone_id +resource "aws_route53_record" "test" { + zone_id = aws_route53_zone.test.zone_id name = "www.NOTexamplE.com" type = "A" ttl = "30" @@ -1219,6 +1220,20 @@ resource "aws_route53_record" "default" { } ` +const testAccRoute53RecordConfigZeroTTL = ` +resource "aws_route53_zone" "test" { + name = "notexample.com" +} + +resource "aws_route53_record" "test" { + zone_id = aws_route53_zone.test.zone_id + name = "www.NOTexamplE.com" + type = "A" + ttl = "0" + records = ["127.0.0.1", "127.0.0.27"] +} +` + const testAccRoute53RecordConfigMultiple = ` resource "aws_route53_zone" "test" { name = "notexample.com" @@ -1236,12 +1251,12 @@ resource "aws_route53_record" "test" { ` const testAccRoute53RecordConfig_fqdn = ` -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } -resource "aws_route53_record" "default" { - zone_id = aws_route53_zone.main.zone_id +resource "aws_route53_record" "test" { + zone_id = aws_route53_zone.test.zone_id name = "www.NOTexamplE.com" type = "A" ttl = "30" @@ -1254,12 +1269,12 @@ resource "aws_route53_record" "default" { ` const testAccRoute53RecordConfig_fqdn_no_op = ` -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } -resource "aws_route53_record" "default" { - zone_id = aws_route53_zone.main.zone_id +resource "aws_route53_record" "test" { + zone_id = aws_route53_zone.test.zone_id name = "www.NOTexamplE.com." type = "A" ttl = "30" @@ -1272,12 +1287,12 @@ resource "aws_route53_record" "default" { ` const testAccRoute53RecordConfigSuffix = ` -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } -resource "aws_route53_record" "default" { - zone_id = aws_route53_zone.main.zone_id +resource "aws_route53_record" "test" { + zone_id = aws_route53_zone.test.zone_id name = "subdomain" type = "A" ttl = "30" @@ -1286,12 +1301,12 @@ resource "aws_route53_record" "default" { ` const testAccRoute53WildCardRecordConfig = ` -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } -resource "aws_route53_record" "default" { - zone_id = aws_route53_zone.main.zone_id +resource "aws_route53_record" "test" { + zone_id = aws_route53_zone.test.zone_id name = "subdomain" type = "A" ttl = "30" @@ -1299,7 +1314,7 @@ resource "aws_route53_record" "default" { } resource "aws_route53_record" "wildcard" { - zone_id = aws_route53_zone.main.zone_id + zone_id = aws_route53_zone.test.zone_id name = "*.notexample.com" type = "A" ttl = "30" @@ -1308,12 +1323,12 @@ resource "aws_route53_record" "wildcard" { ` const testAccRoute53WildCardRecordConfigUpdate = ` -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } -resource "aws_route53_record" "default" { - zone_id = aws_route53_zone.main.zone_id +resource "aws_route53_record" "test" { + zone_id = aws_route53_zone.test.zone_id name = "subdomain" type = "A" ttl = "30" @@ -1321,7 +1336,7 @@ resource "aws_route53_record" "default" { } resource "aws_route53_record" "wildcard" { - zone_id = aws_route53_zone.main.zone_id + zone_id = aws_route53_zone.test.zone_id name = "*.notexample.com" type = "A" ttl = "60" @@ -1330,12 +1345,12 @@ resource "aws_route53_record" "wildcard" { ` const testAccRoute53RecordConfigTXT = ` -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } -resource "aws_route53_record" "default" { - zone_id = "/hostedzone/${aws_route53_zone.main.zone_id}" +resource "aws_route53_record" "test" { + zone_id = "/hostedzone/${aws_route53_zone.test.zone_id}" name = "subdomain" type = "TXT" ttl = "30" @@ -1344,12 +1359,12 @@ resource "aws_route53_record" "default" { ` const testAccRoute53RecordConfigSPF = ` -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } -resource "aws_route53_record" "default" { - zone_id = aws_route53_zone.main.zone_id +resource "aws_route53_record" "test" { + zone_id = aws_route53_zone.test.zone_id name = "test" type = "SPF" ttl = "30" @@ -1358,12 +1373,12 @@ resource "aws_route53_record" "default" { ` const testAccRoute53RecordConfigCAA = ` -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } -resource "aws_route53_record" "default" { - zone_id = aws_route53_zone.main.zone_id +resource "aws_route53_record" "test" { + zone_id = aws_route53_zone.test.zone_id name = "test" type = "CAA" ttl = "30" @@ -1373,11 +1388,11 @@ resource "aws_route53_record" "default" { ` const testAccRoute53FailoverCNAMERecord = ` -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } -resource "aws_route53_health_check" "foo" { +resource "aws_route53_health_check" "test" { fqdn = "dev.notexample.com" port = 80 type = "HTTP" @@ -1391,26 +1406,24 @@ resource "aws_route53_health_check" "foo" { } resource "aws_route53_record" "www-primary" { - zone_id = aws_route53_zone.main.zone_id + zone_id = aws_route53_zone.test.zone_id name = "www" type = "CNAME" ttl = "5" - failover_routing_policy { type = "PRIMARY" } - health_check_id = aws_route53_health_check.foo.id + health_check_id = aws_route53_health_check.test.id set_identifier = "www-primary" records = ["primary.notexample.com"] } resource "aws_route53_record" "www-secondary" { - zone_id = aws_route53_zone.main.zone_id + zone_id = aws_route53_zone.test.zone_id name = "www" type = "CNAME" ttl = "5" - failover_routing_policy { type = "SECONDARY" } @@ -1421,16 +1434,15 @@ resource "aws_route53_record" "www-secondary" { ` const testAccRoute53WeightedCNAMERecord = ` -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } resource "aws_route53_record" "www-dev" { - zone_id = aws_route53_zone.main.zone_id + zone_id = aws_route53_zone.test.zone_id name = "www" type = "CNAME" ttl = "5" - weighted_routing_policy { weight = 10 } @@ -1440,11 +1452,10 @@ resource "aws_route53_record" "www-dev" { } resource "aws_route53_record" "www-live" { - zone_id = aws_route53_zone.main.zone_id + zone_id = aws_route53_zone.test.zone_id name = "www" type = "CNAME" ttl = "5" - weighted_routing_policy { weight = 90 } @@ -1454,11 +1465,10 @@ resource "aws_route53_record" "www-live" { } resource "aws_route53_record" "www-off" { - zone_id = aws_route53_zone.main.zone_id + zone_id = aws_route53_zone.test.zone_id name = "www" type = "CNAME" ttl = "5" - weighted_routing_policy { weight = 0 } @@ -1469,16 +1479,15 @@ resource "aws_route53_record" "www-off" { ` const testAccRoute53GeolocationCNAMERecord = ` -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } -resource "aws_route53_record" "default" { - zone_id = aws_route53_zone.main.zone_id +resource "aws_route53_record" "test" { + zone_id = aws_route53_zone.test.zone_id name = "www" type = "CNAME" ttl = "5" - geolocation_routing_policy { country = "*" } @@ -1488,11 +1497,10 @@ resource "aws_route53_record" "default" { } resource "aws_route53_record" "california" { - zone_id = aws_route53_zone.main.zone_id + zone_id = aws_route53_zone.test.zone_id name = "www" type = "CNAME" ttl = "5" - geolocation_routing_policy { country = "US" subdivision = "CA" @@ -1503,11 +1511,10 @@ resource "aws_route53_record" "california" { } resource "aws_route53_record" "oceania" { - zone_id = aws_route53_zone.main.zone_id + zone_id = aws_route53_zone.test.zone_id name = "www" type = "CNAME" ttl = "5" - geolocation_routing_policy { continent = "OC" } @@ -1517,11 +1524,10 @@ resource "aws_route53_record" "oceania" { } resource "aws_route53_record" "denmark" { - zone_id = aws_route53_zone.main.zone_id + zone_id = aws_route53_zone.test.zone_id name = "www" type = "CNAME" ttl = "5" - geolocation_routing_policy { country = "DK" } @@ -1532,16 +1538,15 @@ resource "aws_route53_record" "denmark" { ` const testAccRoute53LatencyCNAMERecord = ` -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } resource "aws_route53_record" "us-east-1" { - zone_id = aws_route53_zone.main.zone_id + zone_id = aws_route53_zone.test.zone_id name = "www" type = "CNAME" ttl = "5" - latency_routing_policy { region = "us-east-1" } @@ -1551,11 +1556,10 @@ resource "aws_route53_record" "us-east-1" { } resource "aws_route53_record" "eu-west-1" { - zone_id = aws_route53_zone.main.zone_id + zone_id = aws_route53_zone.test.zone_id name = "www" type = "CNAME" ttl = "5" - latency_routing_policy { region = "eu-west-1" } @@ -1565,11 +1569,10 @@ resource "aws_route53_record" "eu-west-1" { } resource "aws_route53_record" "ap-northeast-1" { - zone_id = aws_route53_zone.main.zone_id + zone_id = aws_route53_zone.test.zone_id name = "www" type = "CNAME" ttl = "5" - latency_routing_policy { region = "ap-northeast-1" } @@ -1589,23 +1592,23 @@ data "aws_availability_zones" "available" { } } -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } -resource "aws_route53_record" "alias" { - zone_id = aws_route53_zone.main.zone_id +resource "aws_route53_record" "test" { + zone_id = aws_route53_zone.test.zone_id name = "www" type = "A" alias { - zone_id = aws_elb.main.zone_id - name = aws_elb.main.dns_name + zone_id = aws_elb.test.zone_id + name = aws_elb.test.dns_name evaluate_target_health = true } } -resource "aws_elb" "main" { +resource "aws_elb" "test" { name = "foobar-terraform-elb-%s" availability_zones = slice(data.aws_availability_zones.available.names, 0, 1) @@ -1628,23 +1631,23 @@ data "aws_availability_zones" "available" { } } -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } -resource "aws_route53_record" "alias" { - zone_id = aws_route53_zone.main.zone_id +resource "aws_route53_record" "test" { + zone_id = aws_route53_zone.test.zone_id name = "www" type = "A" alias { - zone_id = aws_elb.main.zone_id - name = aws_elb.main.dns_name + zone_id = aws_elb.test.zone_id + name = aws_elb.test.dns_name evaluate_target_health = true } } -resource "aws_elb" "main" { +resource "aws_elb" "test" { name = "FOOBAR-TERRAFORM-ELB-%s" availability_zones = slice(data.aws_availability_zones.available.names, 0, 1) @@ -1659,11 +1662,11 @@ resource "aws_elb" "main" { func testAccRoute53RecordConfigAliasS3(rName string) string { return fmt.Sprintf(` -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } -resource "aws_s3_bucket" "website" { +resource "aws_s3_bucket" "test" { bucket = %q acl = "public-read" @@ -1673,13 +1676,13 @@ resource "aws_s3_bucket" "website" { } resource "aws_route53_record" "alias" { - zone_id = aws_route53_zone.main.zone_id + zone_id = aws_route53_zone.test.zone_id name = "www" type = "A" alias { - zone_id = aws_s3_bucket.website.hosted_zone_id - name = aws_s3_bucket.website.website_domain + zone_id = aws_s3_bucket.test.hosted_zone_id + name = aws_s3_bucket.test.website_domain evaluate_target_health = true } } @@ -1820,6 +1823,10 @@ resource "aws_security_group" "test" { resource "aws_vpc_endpoint_service" "test" { acceptance_required = false network_load_balancer_arns = [aws_lb.test.id] + + tags = { + Name = %[1]q + } } resource "aws_vpc_endpoint" "test" { @@ -1829,6 +1836,10 @@ resource "aws_vpc_endpoint" "test" { subnet_ids = [aws_subnet.test.id] vpc_endpoint_type = "Interface" vpc_id = aws_vpc.test.id + + tags = { + Name = %[1]q + } } resource "aws_route53_zone" "test" { @@ -1900,7 +1911,7 @@ resource "aws_elb" "live" { } resource "aws_route53_record" "elb_weighted_alias_live" { - zone_id = aws_route53_zone.main.zone_id + zone_id = aws_route53_zone.test.zone_id name = "www" type = "A" @@ -1930,7 +1941,7 @@ resource "aws_elb" "dev" { } resource "aws_route53_record" "elb_weighted_alias_dev" { - zone_id = aws_route53_zone.main.zone_id + zone_id = aws_route53_zone.test.zone_id name = "www" type = "A" @@ -1949,12 +1960,12 @@ resource "aws_route53_record" "elb_weighted_alias_dev" { ` const testAccRoute53WeightedR53AliasRecord = ` -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } resource "aws_route53_record" "blue_origin" { - zone_id = aws_route53_zone.main.zone_id + zone_id = aws_route53_zone.test.zone_id name = "blue-origin" type = "CNAME" ttl = 5 @@ -1962,7 +1973,7 @@ resource "aws_route53_record" "blue_origin" { } resource "aws_route53_record" "r53_weighted_alias_live" { - zone_id = aws_route53_zone.main.zone_id + zone_id = aws_route53_zone.test.zone_id name = "www" type = "CNAME" @@ -1973,14 +1984,14 @@ resource "aws_route53_record" "r53_weighted_alias_live" { set_identifier = "blue" alias { - zone_id = aws_route53_zone.main.zone_id - name = "${aws_route53_record.blue_origin.name}.${aws_route53_zone.main.name}" + zone_id = aws_route53_zone.test.zone_id + name = "${aws_route53_record.blue_origin.name}.${aws_route53_zone.test.name}" evaluate_target_health = false } } resource "aws_route53_record" "green_origin" { - zone_id = aws_route53_zone.main.zone_id + zone_id = aws_route53_zone.test.zone_id name = "green-origin" type = "CNAME" ttl = 5 @@ -1988,7 +1999,7 @@ resource "aws_route53_record" "green_origin" { } resource "aws_route53_record" "r53_weighted_alias_dev" { - zone_id = aws_route53_zone.main.zone_id + zone_id = aws_route53_zone.test.zone_id name = "www" type = "CNAME" @@ -1999,20 +2010,20 @@ resource "aws_route53_record" "r53_weighted_alias_dev" { set_identifier = "green" alias { - zone_id = aws_route53_zone.main.zone_id - name = "${aws_route53_record.green_origin.name}.${aws_route53_zone.main.name}" + zone_id = aws_route53_zone.test.zone_id + name = "${aws_route53_record.green_origin.name}.${aws_route53_zone.test.name}" evaluate_target_health = false } } ` const testAccRoute53RecordTypeChangePre = ` -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } -resource "aws_route53_record" "sample" { - zone_id = aws_route53_zone.main.zone_id +resource "aws_route53_record" "test" { + zone_id = aws_route53_zone.test.zone_id name = "sample" type = "CNAME" ttl = "30" @@ -2021,12 +2032,12 @@ resource "aws_route53_record" "sample" { ` const testAccRoute53RecordTypeChangePost = ` -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } -resource "aws_route53_record" "sample" { - zone_id = aws_route53_zone.main.zone_id +resource "aws_route53_record" "test" { + zone_id = aws_route53_zone.test.zone_id name = "sample" type = "A" ttl = "30" @@ -2063,12 +2074,12 @@ resource "aws_route53_record" "sample" { ` const testAccRoute53RecordSetIdentifierChangePre = ` -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } -resource "aws_route53_record" "basic_to_weighted" { - zone_id = aws_route53_zone.main.zone_id +resource "aws_route53_record" "test" { + zone_id = aws_route53_zone.test.zone_id name = "sample" type = "A" ttl = "30" @@ -2077,12 +2088,12 @@ resource "aws_route53_record" "basic_to_weighted" { ` const testAccRoute53RecordSetIdentifierChangePost = ` -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } -resource "aws_route53_record" "basic_to_weighted" { - zone_id = aws_route53_zone.main.zone_id +resource "aws_route53_record" "test" { + zone_id = aws_route53_zone.test.zone_id name = "sample" type = "A" ttl = "30" @@ -2105,11 +2116,11 @@ data "aws_availability_zones" "available" { } } -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } -resource "aws_elb" "alias_change" { +resource "aws_elb" "test" { name = "foobar-tf-elb-alias-change" availability_zones = slice(data.aws_availability_zones.available.names, 0, 1) @@ -2121,26 +2132,26 @@ resource "aws_elb" "alias_change" { } } -resource "aws_route53_record" "elb_alias_change" { - zone_id = aws_route53_zone.main.zone_id +resource "aws_route53_record" "test" { + zone_id = aws_route53_zone.test.zone_id name = "alias-change" type = "A" alias { - zone_id = aws_elb.alias_change.zone_id - name = aws_elb.alias_change.dns_name + zone_id = aws_elb.test.zone_id + name = aws_elb.test.dns_name evaluate_target_health = true } } ` const testAccRoute53RecordAliasChangePost = ` -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } -resource "aws_route53_record" "elb_alias_change" { - zone_id = aws_route53_zone.main.zone_id +resource "aws_route53_record" "test" { + zone_id = aws_route53_zone.test.zone_id name = "alias-change" type = "CNAME" ttl = "30" @@ -2149,12 +2160,12 @@ resource "aws_route53_record" "elb_alias_change" { ` const testAccRoute53RecordConfigEmptyName = ` -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } -resource "aws_route53_record" "empty" { - zone_id = aws_route53_zone.main.zone_id +resource "aws_route53_record" "test" { + zone_id = aws_route53_zone.test.zone_id name = "" type = "A" ttl = "30" @@ -2163,12 +2174,12 @@ resource "aws_route53_record" "empty" { ` const testAccRoute53RecordConfigLongTxtRecord = ` -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } -resource "aws_route53_record" "long_txt" { - zone_id = aws_route53_zone.main.zone_id +resource "aws_route53_record" "test" { + zone_id = aws_route53_zone.test.zone_id name = "google.notexample.com" type = "TXT" ttl = "30" @@ -2179,12 +2190,12 @@ resource "aws_route53_record" "long_txt" { ` const testAccRoute53RecordConfigUnderscoreInName = ` -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } -resource "aws_route53_record" "underscore" { - zone_id = aws_route53_zone.main.zone_id +resource "aws_route53_record" "test" { + zone_id = aws_route53_zone.test.zone_id name = "_underscore.notexample.com" type = "A" ttl = "30" @@ -2193,12 +2204,12 @@ resource "aws_route53_record" "underscore" { ` const testAccRoute53MultiValueAnswerARecord = ` -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } resource "aws_route53_record" "www-server1" { - zone_id = aws_route53_zone.main.zone_id + zone_id = aws_route53_zone.test.zone_id name = "www" type = "A" ttl = "5" @@ -2208,7 +2219,7 @@ resource "aws_route53_record" "www-server1" { } resource "aws_route53_record" "www-server2" { - zone_id = aws_route53_zone.main.zone_id + zone_id = aws_route53_zone.test.zone_id name = "www" type = "A" ttl = "5" @@ -2219,12 +2230,12 @@ resource "aws_route53_record" "www-server2" { ` const testaccRoute53RecordConfigWithWeightedRoutingPolicy = ` -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } -resource "aws_route53_record" "www-server1" { - zone_id = aws_route53_zone.main.zone_id +resource "aws_route53_record" "test" { + zone_id = aws_route53_zone.test.zone_id name = "www" type = "A" @@ -2239,12 +2250,12 @@ resource "aws_route53_record" "www-server1" { ` const testaccRoute53RecordConfigWithSimpleRoutingPolicy = ` -resource "aws_route53_zone" "main" { +resource "aws_route53_zone" "test" { name = "notexample.com" } -resource "aws_route53_record" "www-server1" { - zone_id = aws_route53_zone.main.zone_id +resource "aws_route53_record" "test" { + zone_id = aws_route53_zone.test.zone_id name = "www" type = "A" ttl = "300"