github.com/gabrielperezs/terraform@v0.7.0-rc2.0.20160715084931-f7da2612946f/builtin/providers/aws/resource_aws_route53_record_test.go (about)

     1  package aws
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  	"testing"
     7  
     8  	"github.com/hashicorp/terraform/helper/acctest"
     9  	"github.com/hashicorp/terraform/helper/resource"
    10  	"github.com/hashicorp/terraform/terraform"
    11  
    12  	"github.com/aws/aws-sdk-go/aws"
    13  	"github.com/aws/aws-sdk-go/aws/awserr"
    14  	"github.com/aws/aws-sdk-go/service/route53"
    15  )
    16  
    17  func TestCleanRecordName(t *testing.T) {
    18  	cases := []struct {
    19  		Input, Output string
    20  	}{
    21  		{"www.nonexample.com", "www.nonexample.com"},
    22  		{"\\052.nonexample.com", "*.nonexample.com"},
    23  		{"nonexample.com", "nonexample.com"},
    24  	}
    25  
    26  	for _, tc := range cases {
    27  		actual := cleanRecordName(tc.Input)
    28  		if actual != tc.Output {
    29  			t.Fatalf("input: %s\noutput: %s", tc.Input, actual)
    30  		}
    31  	}
    32  }
    33  
    34  func TestExpandRecordName(t *testing.T) {
    35  	cases := []struct {
    36  		Input, Output string
    37  	}{
    38  		{"www", "www.nonexample.com"},
    39  		{"dev.www", "dev.www.nonexample.com"},
    40  		{"*", "*.nonexample.com"},
    41  		{"nonexample.com", "nonexample.com"},
    42  		{"test.nonexample.com", "test.nonexample.com"},
    43  		{"test.nonexample.com.", "test.nonexample.com"},
    44  	}
    45  
    46  	zone_name := "nonexample.com"
    47  	for _, tc := range cases {
    48  		actual := expandRecordName(tc.Input, zone_name)
    49  		if actual != tc.Output {
    50  			t.Fatalf("input: %s\noutput: %s", tc.Input, actual)
    51  		}
    52  	}
    53  }
    54  
    55  func TestAccAWSRoute53Record_basic(t *testing.T) {
    56  	resource.Test(t, resource.TestCase{
    57  		PreCheck:      func() { testAccPreCheck(t) },
    58  		IDRefreshName: "aws_route53_record.default",
    59  		Providers:     testAccProviders,
    60  		CheckDestroy:  testAccCheckRoute53RecordDestroy,
    61  		Steps: []resource.TestStep{
    62  			resource.TestStep{
    63  				Config: testAccRoute53RecordConfig,
    64  				Check: resource.ComposeTestCheckFunc(
    65  					testAccCheckRoute53RecordExists("aws_route53_record.default"),
    66  				),
    67  			},
    68  		},
    69  	})
    70  }
    71  
    72  func TestAccAWSRoute53Record_basic_fqdn(t *testing.T) {
    73  	resource.Test(t, resource.TestCase{
    74  		PreCheck:      func() { testAccPreCheck(t) },
    75  		IDRefreshName: "aws_route53_record.default",
    76  		Providers:     testAccProviders,
    77  		CheckDestroy:  testAccCheckRoute53RecordDestroy,
    78  		Steps: []resource.TestStep{
    79  			resource.TestStep{
    80  				Config: testAccRoute53RecordConfig_fqdn,
    81  				Check: resource.ComposeTestCheckFunc(
    82  					testAccCheckRoute53RecordExists("aws_route53_record.default"),
    83  				),
    84  			},
    85  
    86  			// Ensure that changing the name to include a trailing "dot" results in
    87  			// nothing happening, because the name is stripped of trailing dots on
    88  			// save. Otherwise, an update would occur and due to the
    89  			// create_before_destroy, the record would actually be destroyed, and a
    90  			// non-empty plan would appear, and the record will fail to exist in
    91  			// testAccCheckRoute53RecordExists
    92  			resource.TestStep{
    93  				Config: testAccRoute53RecordConfig_fqdn_no_op,
    94  				Check: resource.ComposeTestCheckFunc(
    95  					testAccCheckRoute53RecordExists("aws_route53_record.default"),
    96  				),
    97  			},
    98  		},
    99  	})
   100  }
   101  
   102  func TestAccAWSRoute53Record_txtSupport(t *testing.T) {
   103  	resource.Test(t, resource.TestCase{
   104  		PreCheck:        func() { testAccPreCheck(t) },
   105  		IDRefreshName:   "aws_route53_record.default",
   106  		IDRefreshIgnore: []string{"zone_id"}, // just for this test
   107  		Providers:       testAccProviders,
   108  		CheckDestroy:    testAccCheckRoute53RecordDestroy,
   109  		Steps: []resource.TestStep{
   110  			resource.TestStep{
   111  				Config: testAccRoute53RecordConfigTXT,
   112  				Check: resource.ComposeTestCheckFunc(
   113  					testAccCheckRoute53RecordExists("aws_route53_record.default"),
   114  				),
   115  			},
   116  		},
   117  	})
   118  }
   119  
   120  func TestAccAWSRoute53Record_spfSupport(t *testing.T) {
   121  	resource.Test(t, resource.TestCase{
   122  		PreCheck:      func() { testAccPreCheck(t) },
   123  		IDRefreshName: "aws_route53_record.default",
   124  		Providers:     testAccProviders,
   125  		CheckDestroy:  testAccCheckRoute53RecordDestroy,
   126  		Steps: []resource.TestStep{
   127  			resource.TestStep{
   128  				Config: testAccRoute53RecordConfigSPF,
   129  				Check: resource.ComposeTestCheckFunc(
   130  					testAccCheckRoute53RecordExists("aws_route53_record.default"),
   131  					resource.TestCheckResourceAttr(
   132  						"aws_route53_record.default", "records.2930149397", "include:notexample.com"),
   133  				),
   134  			},
   135  		},
   136  	})
   137  }
   138  func TestAccAWSRoute53Record_generatesSuffix(t *testing.T) {
   139  	resource.Test(t, resource.TestCase{
   140  		PreCheck:      func() { testAccPreCheck(t) },
   141  		IDRefreshName: "aws_route53_record.default",
   142  		Providers:     testAccProviders,
   143  		CheckDestroy:  testAccCheckRoute53RecordDestroy,
   144  		Steps: []resource.TestStep{
   145  			resource.TestStep{
   146  				Config: testAccRoute53RecordConfigSuffix,
   147  				Check: resource.ComposeTestCheckFunc(
   148  					testAccCheckRoute53RecordExists("aws_route53_record.default"),
   149  				),
   150  			},
   151  		},
   152  	})
   153  }
   154  
   155  func TestAccAWSRoute53Record_wildcard(t *testing.T) {
   156  	resource.Test(t, resource.TestCase{
   157  		PreCheck:      func() { testAccPreCheck(t) },
   158  		IDRefreshName: "aws_route53_record.wildcard",
   159  		Providers:     testAccProviders,
   160  		CheckDestroy:  testAccCheckRoute53RecordDestroy,
   161  		Steps: []resource.TestStep{
   162  			resource.TestStep{
   163  				Config: testAccRoute53WildCardRecordConfig,
   164  				Check: resource.ComposeTestCheckFunc(
   165  					testAccCheckRoute53RecordExists("aws_route53_record.wildcard"),
   166  				),
   167  			},
   168  
   169  			// Cause a change, which will trigger a refresh
   170  			resource.TestStep{
   171  				Config: testAccRoute53WildCardRecordConfigUpdate,
   172  				Check: resource.ComposeTestCheckFunc(
   173  					testAccCheckRoute53RecordExists("aws_route53_record.wildcard"),
   174  				),
   175  			},
   176  		},
   177  	})
   178  }
   179  
   180  func TestAccAWSRoute53Record_failover(t *testing.T) {
   181  	resource.Test(t, resource.TestCase{
   182  		PreCheck:      func() { testAccPreCheck(t) },
   183  		IDRefreshName: "aws_route53_record.www-primary",
   184  		Providers:     testAccProviders,
   185  		CheckDestroy:  testAccCheckRoute53RecordDestroy,
   186  		Steps: []resource.TestStep{
   187  			resource.TestStep{
   188  				Config: testAccRoute53FailoverCNAMERecord,
   189  				Check: resource.ComposeTestCheckFunc(
   190  					testAccCheckRoute53RecordExists("aws_route53_record.www-primary"),
   191  					testAccCheckRoute53RecordExists("aws_route53_record.www-secondary"),
   192  				),
   193  			},
   194  		},
   195  	})
   196  }
   197  
   198  func TestAccAWSRoute53Record_weighted_basic(t *testing.T) {
   199  	resource.Test(t, resource.TestCase{
   200  		PreCheck:      func() { testAccPreCheck(t) },
   201  		IDRefreshName: "aws_route53_record.www-live",
   202  		Providers:     testAccProviders,
   203  		CheckDestroy:  testAccCheckRoute53RecordDestroy,
   204  		Steps: []resource.TestStep{
   205  			resource.TestStep{
   206  				Config: testAccRoute53WeightedCNAMERecord,
   207  				Check: resource.ComposeTestCheckFunc(
   208  					testAccCheckRoute53RecordExists("aws_route53_record.www-dev"),
   209  					testAccCheckRoute53RecordExists("aws_route53_record.www-live"),
   210  					testAccCheckRoute53RecordExists("aws_route53_record.www-off"),
   211  				),
   212  			},
   213  		},
   214  	})
   215  }
   216  
   217  func TestAccAWSRoute53Record_alias(t *testing.T) {
   218  	rs := acctest.RandString(10)
   219  	config := fmt.Sprintf(testAccRoute53ElbAliasRecord, rs)
   220  	resource.Test(t, resource.TestCase{
   221  		PreCheck:      func() { testAccPreCheck(t) },
   222  		IDRefreshName: "aws_route53_record.alias",
   223  		Providers:     testAccProviders,
   224  		CheckDestroy:  testAccCheckRoute53RecordDestroy,
   225  		Steps: []resource.TestStep{
   226  			resource.TestStep{
   227  				Config: config,
   228  				Check: resource.ComposeTestCheckFunc(
   229  					testAccCheckRoute53RecordExists("aws_route53_record.alias"),
   230  				),
   231  			},
   232  		},
   233  	})
   234  }
   235  
   236  func TestAccAWSRoute53Record_s3_alias(t *testing.T) {
   237  	resource.Test(t, resource.TestCase{
   238  		PreCheck:     func() { testAccPreCheck(t) },
   239  		Providers:    testAccProviders,
   240  		CheckDestroy: testAccCheckRoute53RecordDestroy,
   241  		Steps: []resource.TestStep{
   242  			resource.TestStep{
   243  				Config: testAccRoute53S3AliasRecord,
   244  				Check: resource.ComposeTestCheckFunc(
   245  					testAccCheckRoute53RecordExists("aws_route53_record.alias"),
   246  				),
   247  			},
   248  		},
   249  	})
   250  }
   251  
   252  func TestAccAWSRoute53Record_weighted_alias(t *testing.T) {
   253  	resource.Test(t, resource.TestCase{
   254  		PreCheck:      func() { testAccPreCheck(t) },
   255  		IDRefreshName: "aws_route53_record.elb_weighted_alias_live",
   256  		Providers:     testAccProviders,
   257  		CheckDestroy:  testAccCheckRoute53RecordDestroy,
   258  		Steps: []resource.TestStep{
   259  			resource.TestStep{
   260  				Config: testAccRoute53WeightedElbAliasRecord,
   261  				Check: resource.ComposeTestCheckFunc(
   262  					testAccCheckRoute53RecordExists("aws_route53_record.elb_weighted_alias_live"),
   263  					testAccCheckRoute53RecordExists("aws_route53_record.elb_weighted_alias_dev"),
   264  				),
   265  			},
   266  
   267  			resource.TestStep{
   268  				Config: testAccRoute53WeightedR53AliasRecord,
   269  				Check: resource.ComposeTestCheckFunc(
   270  					testAccCheckRoute53RecordExists("aws_route53_record.green_origin"),
   271  					testAccCheckRoute53RecordExists("aws_route53_record.r53_weighted_alias_live"),
   272  					testAccCheckRoute53RecordExists("aws_route53_record.blue_origin"),
   273  					testAccCheckRoute53RecordExists("aws_route53_record.r53_weighted_alias_dev"),
   274  				),
   275  			},
   276  		},
   277  	})
   278  }
   279  
   280  func TestAccAWSRoute53Record_geolocation_basic(t *testing.T) {
   281  	resource.Test(t, resource.TestCase{
   282  		PreCheck:     func() { testAccPreCheck(t) },
   283  		Providers:    testAccProviders,
   284  		CheckDestroy: testAccCheckRoute53RecordDestroy,
   285  		Steps: []resource.TestStep{
   286  			resource.TestStep{
   287  				Config: testAccRoute53GeolocationCNAMERecord,
   288  				Check: resource.ComposeTestCheckFunc(
   289  					testAccCheckRoute53RecordExists("aws_route53_record.default"),
   290  					testAccCheckRoute53RecordExists("aws_route53_record.california"),
   291  					testAccCheckRoute53RecordExists("aws_route53_record.oceania"),
   292  					testAccCheckRoute53RecordExists("aws_route53_record.denmark"),
   293  				),
   294  			},
   295  		},
   296  	})
   297  }
   298  
   299  func TestAccAWSRoute53Record_latency_basic(t *testing.T) {
   300  	resource.Test(t, resource.TestCase{
   301  		PreCheck:     func() { testAccPreCheck(t) },
   302  		Providers:    testAccProviders,
   303  		CheckDestroy: testAccCheckRoute53RecordDestroy,
   304  		Steps: []resource.TestStep{
   305  			resource.TestStep{
   306  				Config: testAccRoute53LatencyCNAMERecord,
   307  				Check: resource.ComposeTestCheckFunc(
   308  					testAccCheckRoute53RecordExists("aws_route53_record.us-east-1"),
   309  					testAccCheckRoute53RecordExists("aws_route53_record.eu-west-1"),
   310  					testAccCheckRoute53RecordExists("aws_route53_record.ap-northeast-1"),
   311  				),
   312  			},
   313  		},
   314  	})
   315  }
   316  
   317  func TestAccAWSRoute53Record_TypeChange(t *testing.T) {
   318  	resource.Test(t, resource.TestCase{
   319  		PreCheck:      func() { testAccPreCheck(t) },
   320  		IDRefreshName: "aws_route53_record.sample",
   321  		Providers:     testAccProviders,
   322  		CheckDestroy:  testAccCheckRoute53RecordDestroy,
   323  		Steps: []resource.TestStep{
   324  			resource.TestStep{
   325  				Config: testAccRoute53RecordTypeChangePre,
   326  				Check: resource.ComposeTestCheckFunc(
   327  					testAccCheckRoute53RecordExists("aws_route53_record.sample"),
   328  				),
   329  			},
   330  
   331  			// Cause a change, which will trigger a refresh
   332  			resource.TestStep{
   333  				Config: testAccRoute53RecordTypeChangePost,
   334  				Check: resource.ComposeTestCheckFunc(
   335  					testAccCheckRoute53RecordExists("aws_route53_record.sample"),
   336  				),
   337  			},
   338  		},
   339  	})
   340  }
   341  
   342  func testAccCheckRoute53RecordDestroy(s *terraform.State) error {
   343  	conn := testAccProvider.Meta().(*AWSClient).r53conn
   344  	for _, rs := range s.RootModule().Resources {
   345  		if rs.Type != "aws_route53_record" {
   346  			continue
   347  		}
   348  
   349  		parts := strings.Split(rs.Primary.ID, "_")
   350  		zone := parts[0]
   351  		name := parts[1]
   352  		rType := parts[2]
   353  
   354  		lopts := &route53.ListResourceRecordSetsInput{
   355  			HostedZoneId:    aws.String(cleanZoneID(zone)),
   356  			StartRecordName: aws.String(name),
   357  			StartRecordType: aws.String(rType),
   358  		}
   359  
   360  		resp, err := conn.ListResourceRecordSets(lopts)
   361  		if err != nil {
   362  			if awsErr, ok := err.(awserr.Error); ok {
   363  				// if NoSuchHostedZone, then all the things are destroyed
   364  				if awsErr.Code() == "NoSuchHostedZone" {
   365  					return nil
   366  				}
   367  			}
   368  			return err
   369  		}
   370  		if len(resp.ResourceRecordSets) == 0 {
   371  			return nil
   372  		}
   373  		rec := resp.ResourceRecordSets[0]
   374  		if FQDN(*rec.Name) == FQDN(name) && *rec.Type == rType {
   375  			return fmt.Errorf("Record still exists: %#v", rec)
   376  		}
   377  	}
   378  	return nil
   379  }
   380  
   381  func testAccCheckRoute53RecordExists(n string) resource.TestCheckFunc {
   382  	return func(s *terraform.State) error {
   383  		conn := testAccProvider.Meta().(*AWSClient).r53conn
   384  		rs, ok := s.RootModule().Resources[n]
   385  		if !ok {
   386  			return fmt.Errorf("Not found: %s", n)
   387  		}
   388  
   389  		if rs.Primary.ID == "" {
   390  			return fmt.Errorf("No hosted zone ID is set")
   391  		}
   392  
   393  		parts := strings.Split(rs.Primary.ID, "_")
   394  		zone := parts[0]
   395  		name := parts[1]
   396  		rType := parts[2]
   397  
   398  		en := expandRecordName(name, "notexample.com")
   399  
   400  		lopts := &route53.ListResourceRecordSetsInput{
   401  			HostedZoneId:    aws.String(cleanZoneID(zone)),
   402  			StartRecordName: aws.String(en),
   403  			StartRecordType: aws.String(rType),
   404  		}
   405  
   406  		resp, err := conn.ListResourceRecordSets(lopts)
   407  		if err != nil {
   408  			return err
   409  		}
   410  		if len(resp.ResourceRecordSets) == 0 {
   411  			return fmt.Errorf("Record does not exist")
   412  		}
   413  		// rec := resp.ResourceRecordSets[0]
   414  		for _, rec := range resp.ResourceRecordSets {
   415  			recName := cleanRecordName(*rec.Name)
   416  			if FQDN(strings.ToLower(recName)) == FQDN(strings.ToLower(en)) && *rec.Type == rType {
   417  				return nil
   418  			}
   419  		}
   420  		return fmt.Errorf("Record does not exist: %#v", rs.Primary.ID)
   421  	}
   422  }
   423  
   424  const testAccRoute53RecordConfig = `
   425  resource "aws_route53_zone" "main" {
   426  	name = "notexample.com"
   427  }
   428  
   429  resource "aws_route53_record" "default" {
   430  	zone_id = "${aws_route53_zone.main.zone_id}"
   431  	name = "www.NOTexamplE.com"
   432  	type = "A"
   433  	ttl = "30"
   434  	records = ["127.0.0.1", "127.0.0.27"]
   435  }
   436  `
   437  const testAccRoute53RecordConfig_fqdn = `
   438  resource "aws_route53_zone" "main" {
   439    name = "notexample.com"
   440  }
   441  
   442  resource "aws_route53_record" "default" {
   443    zone_id = "${aws_route53_zone.main.zone_id}"
   444    name    = "www.NOTexamplE.com"
   445    type    = "A"
   446    ttl     = "30"
   447    records = ["127.0.0.1", "127.0.0.27"]
   448  
   449    lifecycle {
   450      create_before_destroy = true
   451    }
   452  }
   453  `
   454  
   455  const testAccRoute53RecordConfig_fqdn_no_op = `
   456  resource "aws_route53_zone" "main" {
   457    name = "notexample.com"
   458  }
   459  
   460  resource "aws_route53_record" "default" {
   461    zone_id = "${aws_route53_zone.main.zone_id}"
   462    name    = "www.NOTexamplE.com."
   463    type    = "A"
   464    ttl     = "30"
   465    records = ["127.0.0.1", "127.0.0.27"]
   466  
   467    lifecycle {
   468      create_before_destroy = true
   469    }
   470  }
   471  `
   472  
   473  const testAccRoute53RecordNoConfig = `
   474  resource "aws_route53_zone" "main" {
   475  	name = "notexample.com"
   476  }
   477  `
   478  
   479  const testAccRoute53RecordConfigSuffix = `
   480  resource "aws_route53_zone" "main" {
   481  	name = "notexample.com"
   482  }
   483  
   484  resource "aws_route53_record" "default" {
   485  	zone_id = "${aws_route53_zone.main.zone_id}"
   486  	name = "subdomain"
   487  	type = "A"
   488  	ttl = "30"
   489  	records = ["127.0.0.1", "127.0.0.27"]
   490  }
   491  `
   492  
   493  const testAccRoute53WildCardRecordConfig = `
   494  resource "aws_route53_zone" "main" {
   495      name = "notexample.com"
   496  }
   497  
   498  resource "aws_route53_record" "default" {
   499  	zone_id = "${aws_route53_zone.main.zone_id}"
   500  	name = "subdomain"
   501  	type = "A"
   502  	ttl = "30"
   503  	records = ["127.0.0.1", "127.0.0.27"]
   504  }
   505  
   506  resource "aws_route53_record" "wildcard" {
   507      zone_id = "${aws_route53_zone.main.zone_id}"
   508      name = "*.notexample.com"
   509      type = "A"
   510      ttl = "30"
   511      records = ["127.0.0.1"]
   512  }
   513  `
   514  
   515  const testAccRoute53WildCardRecordConfigUpdate = `
   516  resource "aws_route53_zone" "main" {
   517      name = "notexample.com"
   518  }
   519  
   520  resource "aws_route53_record" "default" {
   521  	zone_id = "${aws_route53_zone.main.zone_id}"
   522  	name = "subdomain"
   523  	type = "A"
   524  	ttl = "30"
   525  	records = ["127.0.0.1", "127.0.0.27"]
   526  }
   527  
   528  resource "aws_route53_record" "wildcard" {
   529      zone_id = "${aws_route53_zone.main.zone_id}"
   530      name = "*.notexample.com"
   531      type = "A"
   532      ttl = "60"
   533      records = ["127.0.0.1"]
   534  }
   535  `
   536  const testAccRoute53RecordConfigTXT = `
   537  resource "aws_route53_zone" "main" {
   538  	name = "notexample.com"
   539  }
   540  
   541  resource "aws_route53_record" "default" {
   542  	zone_id = "/hostedzone/${aws_route53_zone.main.zone_id}"
   543  	name = "subdomain"
   544  	type = "TXT"
   545  	ttl = "30"
   546  	records = ["lalalala"]
   547  }
   548  `
   549  const testAccRoute53RecordConfigSPF = `
   550  resource "aws_route53_zone" "main" {
   551  	name = "notexample.com"
   552  }
   553  
   554  resource "aws_route53_record" "default" {
   555  	zone_id = "${aws_route53_zone.main.zone_id}"
   556  	name = "test"
   557  	type = "SPF"
   558  	ttl = "30"
   559  	records = ["include:notexample.com"]
   560  }
   561  `
   562  
   563  const testAccRoute53FailoverCNAMERecord = `
   564  resource "aws_route53_zone" "main" {
   565  	name = "notexample.com"
   566  }
   567  
   568  resource "aws_route53_health_check" "foo" {
   569    fqdn = "dev.notexample.com"
   570    port = 80
   571    type = "HTTP"
   572    resource_path = "/"
   573    failure_threshold = "2"
   574    request_interval = "30"
   575  
   576    tags = {
   577      Name = "tf-test-health-check"
   578     }
   579  }
   580  
   581  resource "aws_route53_record" "www-primary" {
   582    zone_id = "${aws_route53_zone.main.zone_id}"
   583    name = "www"
   584    type = "CNAME"
   585    ttl = "5"
   586    failover_routing_policy {
   587      type = "PRIMARY"
   588    }
   589    health_check_id = "${aws_route53_health_check.foo.id}"
   590    set_identifier = "www-primary"
   591    records = ["primary.notexample.com"]
   592  }
   593  
   594  resource "aws_route53_record" "www-secondary" {
   595    zone_id = "${aws_route53_zone.main.zone_id}"
   596    name = "www"
   597    type = "CNAME"
   598    ttl = "5"
   599    failover_routing_policy {
   600      type = "SECONDARY"
   601    }
   602    set_identifier = "www-secondary"
   603    records = ["secondary.notexample.com"]
   604  }
   605  `
   606  
   607  const testAccRoute53WeightedCNAMERecord = `
   608  resource "aws_route53_zone" "main" {
   609  	name = "notexample.com"
   610  }
   611  
   612  resource "aws_route53_record" "www-dev" {
   613    zone_id = "${aws_route53_zone.main.zone_id}"
   614    name = "www"
   615    type = "CNAME"
   616    ttl = "5"
   617    weighted_routing_policy {
   618  	weight = 10
   619    }
   620    set_identifier = "dev"
   621    records = ["dev.notexample.com"]
   622  }
   623  
   624  resource "aws_route53_record" "www-live" {
   625    zone_id = "${aws_route53_zone.main.zone_id}"
   626    name = "www"
   627    type = "CNAME"
   628    ttl = "5"
   629    weighted_routing_policy {
   630  	weight = 90
   631    }
   632    set_identifier = "live"
   633    records = ["dev.notexample.com"]
   634  }
   635  
   636  resource "aws_route53_record" "www-off" {
   637    zone_id = "${aws_route53_zone.main.zone_id}"
   638    name = "www"
   639    type = "CNAME"
   640    ttl = "5"
   641    weighted_routing_policy = {
   642  	weight = 0
   643    }
   644    set_identifier = "off"
   645    records = ["dev.notexample.com"]
   646  }
   647  `
   648  
   649  const testAccRoute53GeolocationCNAMERecord = `
   650  resource "aws_route53_zone" "main" {
   651    name = "notexample.com"
   652  }
   653  
   654  resource "aws_route53_record" "default" {
   655    zone_id = "${aws_route53_zone.main.zone_id}"
   656    name = "www"
   657    type = "CNAME"
   658    ttl = "5"
   659    geolocation_routing_policy {
   660      country = "*"
   661    }
   662    set_identifier = "Default"
   663    records = ["dev.notexample.com"]
   664  }
   665  
   666  resource "aws_route53_record" "california" {
   667    zone_id = "${aws_route53_zone.main.zone_id}"
   668    name = "www"
   669    type = "CNAME"
   670    ttl = "5"
   671    geolocation_routing_policy {
   672      country = "US"
   673      subdivision = "CA"
   674    }
   675    set_identifier = "California"
   676    records = ["dev.notexample.com"]
   677  }
   678  
   679  resource "aws_route53_record" "oceania" {
   680    zone_id = "${aws_route53_zone.main.zone_id}"
   681    name = "www"
   682    type = "CNAME"
   683    ttl = "5"
   684    geolocation_routing_policy {
   685      continent = "OC"
   686    }
   687    set_identifier = "Oceania"
   688    records = ["dev.notexample.com"]
   689  }
   690  
   691  resource "aws_route53_record" "denmark" {
   692    zone_id = "${aws_route53_zone.main.zone_id}"
   693    name = "www"
   694    type = "CNAME"
   695    ttl = "5"
   696    geolocation_routing_policy {
   697      country = "DK"
   698    }
   699    set_identifier = "Denmark"
   700    records = ["dev.notexample.com"]
   701  }
   702  `
   703  
   704  const testAccRoute53LatencyCNAMERecord = `
   705  resource "aws_route53_zone" "main" {
   706    name = "notexample.com"
   707  }
   708  
   709  resource "aws_route53_record" "us-east-1" {
   710    zone_id = "${aws_route53_zone.main.zone_id}"
   711    name = "www"
   712    type = "CNAME"
   713    ttl = "5"
   714    latency_routing_policy {
   715      region = "us-east-1"
   716    }
   717    set_identifier = "us-east-1"
   718    records = ["dev.notexample.com"]
   719  }
   720  
   721  resource "aws_route53_record" "eu-west-1" {
   722    zone_id = "${aws_route53_zone.main.zone_id}"
   723    name = "www"
   724    type = "CNAME"
   725    ttl = "5"
   726    latency_routing_policy {
   727      region = "eu-west-1"
   728    }
   729    set_identifier = "eu-west-1"
   730    records = ["dev.notexample.com"]
   731  }
   732  
   733  resource "aws_route53_record" "ap-northeast-1" {
   734    zone_id = "${aws_route53_zone.main.zone_id}"
   735    name = "www"
   736    type = "CNAME"
   737    ttl = "5"
   738    latency_routing_policy {
   739      region = "ap-northeast-1"
   740    }
   741    set_identifier = "ap-northeast-1"
   742    records = ["dev.notexample.com"]
   743  }
   744  `
   745  
   746  const testAccRoute53ElbAliasRecord = `
   747  resource "aws_route53_zone" "main" {
   748    name = "notexample.com"
   749  }
   750  
   751  resource "aws_route53_record" "alias" {
   752    zone_id = "${aws_route53_zone.main.zone_id}"
   753    name = "www"
   754    type = "A"
   755  
   756    alias {
   757    	zone_id = "${aws_elb.main.zone_id}"
   758    	name = "${aws_elb.main.dns_name}"
   759    	evaluate_target_health = true
   760    }
   761  }
   762  
   763  resource "aws_elb" "main" {
   764    name = "foobar-terraform-elb-%s"
   765    availability_zones = ["us-west-2a"]
   766  
   767    listener {
   768      instance_port = 80
   769      instance_protocol = "http"
   770      lb_port = 80
   771      lb_protocol = "http"
   772    }
   773  }
   774  `
   775  
   776  const testAccRoute53AliasRecord = `
   777  resource "aws_route53_zone" "main" {
   778    name = "notexample.com"
   779  }
   780  
   781  resource "aws_route53_record" "origin" {
   782    zone_id = "${aws_route53_zone.main.zone_id}"
   783    name = "origin"
   784    type = "A"
   785    ttl = 5
   786    records = ["127.0.0.1"]
   787  }
   788  
   789  resource "aws_route53_record" "alias" {
   790    zone_id = "${aws_route53_zone.main.zone_id}"
   791    name = "www"
   792    type = "A"
   793  
   794    alias {
   795      zone_id = "${aws_route53_zone.main.zone_id}"
   796      name = "${aws_route53_record.origin.name}.${aws_route53_zone.main.name}"
   797      evaluate_target_health = true
   798    }
   799  }
   800  `
   801  
   802  const testAccRoute53S3AliasRecord = `
   803  resource "aws_route53_zone" "main" {
   804    name = "notexample.com"
   805  }
   806  
   807  resource "aws_s3_bucket" "website" {
   808    bucket = "website.notexample.com"
   809  	acl = "public-read"
   810  	website {
   811  		index_document = "index.html"
   812  	}
   813  }
   814  
   815  resource "aws_route53_record" "alias" {
   816    zone_id = "${aws_route53_zone.main.zone_id}"
   817    name = "www"
   818    type = "A"
   819  
   820    alias {
   821      zone_id = "${aws_s3_bucket.website.hosted_zone_id}"
   822      name = "${aws_s3_bucket.website.website_domain}"
   823      evaluate_target_health = true
   824    }
   825  }
   826  `
   827  
   828  const testAccRoute53WeightedElbAliasRecord = `
   829  resource "aws_route53_zone" "main" {
   830    name = "notexample.com"
   831  }
   832  
   833  resource "aws_elb" "live" {
   834    name = "foobar-terraform-elb-live"
   835    availability_zones = ["us-west-2a"]
   836  
   837    listener {
   838      instance_port = 80
   839      instance_protocol = "http"
   840      lb_port = 80
   841      lb_protocol = "http"
   842    }
   843  }
   844  
   845  resource "aws_route53_record" "elb_weighted_alias_live" {
   846    zone_id = "${aws_route53_zone.main.zone_id}"
   847    name = "www"
   848    type = "A"
   849  
   850    weighted_routing_policy {
   851  	weight = 90
   852    }
   853    set_identifier = "live"
   854  
   855    alias {
   856      zone_id = "${aws_elb.live.zone_id}"
   857      name = "${aws_elb.live.dns_name}"
   858      evaluate_target_health = true
   859    }
   860  }
   861  
   862  resource "aws_elb" "dev" {
   863    name = "foobar-terraform-elb-dev"
   864    availability_zones = ["us-west-2a"]
   865  
   866    listener {
   867      instance_port = 80
   868      instance_protocol = "http"
   869      lb_port = 80
   870      lb_protocol = "http"
   871    }
   872  }
   873  
   874  resource "aws_route53_record" "elb_weighted_alias_dev" {
   875    zone_id = "${aws_route53_zone.main.zone_id}"
   876    name = "www"
   877    type = "A"
   878  
   879    weighted_routing_policy {
   880  	weight = 10
   881    }
   882    set_identifier = "dev"
   883  
   884    alias {
   885      zone_id = "${aws_elb.dev.zone_id}"
   886      name = "${aws_elb.dev.dns_name}"
   887      evaluate_target_health = true
   888    }
   889  }
   890  `
   891  
   892  const testAccRoute53WeightedR53AliasRecord = `
   893  resource "aws_route53_zone" "main" {
   894    name = "notexample.com"
   895  }
   896  
   897  resource "aws_route53_record" "blue_origin" {
   898    zone_id = "${aws_route53_zone.main.zone_id}"
   899    name = "blue-origin"
   900    type = "CNAME"
   901    ttl = 5
   902    records = ["v1.terraform.io"]
   903  }
   904  
   905  resource "aws_route53_record" "r53_weighted_alias_live" {
   906    zone_id = "${aws_route53_zone.main.zone_id}"
   907    name = "www"
   908    type = "CNAME"
   909  
   910    weighted_routing_policy {
   911  	weight = 90
   912    }
   913    set_identifier = "blue"
   914  
   915    alias {
   916      zone_id = "${aws_route53_zone.main.zone_id}"
   917      name = "${aws_route53_record.blue_origin.name}.${aws_route53_zone.main.name}"
   918      evaluate_target_health = false
   919    }
   920  }
   921  
   922  resource "aws_route53_record" "green_origin" {
   923    zone_id = "${aws_route53_zone.main.zone_id}"
   924    name = "green-origin"
   925    type = "CNAME"
   926    ttl = 5
   927    records = ["v2.terraform.io"]
   928  }
   929  
   930  resource "aws_route53_record" "r53_weighted_alias_dev" {
   931    zone_id = "${aws_route53_zone.main.zone_id}"
   932    name = "www"
   933    type = "CNAME"
   934  
   935    weighted_routing_policy {
   936  	weight = 10
   937    }
   938    set_identifier = "green"
   939  
   940    alias {
   941      zone_id = "${aws_route53_zone.main.zone_id}"
   942      name = "${aws_route53_record.green_origin.name}.${aws_route53_zone.main.name}"
   943      evaluate_target_health = false
   944    }
   945  }
   946  `
   947  
   948  const testAccRoute53RecordTypeChangePre = `
   949  resource "aws_route53_zone" "main" {
   950  	name = "notexample.com"
   951  }
   952  
   953  resource "aws_route53_record" "sample" {
   954  	zone_id = "${aws_route53_zone.main.zone_id}"
   955    name = "sample"
   956    type = "CNAME"
   957    ttl = "30"
   958    records = ["www.terraform.io"]
   959  }
   960  `
   961  
   962  const testAccRoute53RecordTypeChangePost = `
   963  resource "aws_route53_zone" "main" {
   964  	name = "notexample.com"
   965  }
   966  
   967  resource "aws_route53_record" "sample" {
   968    zone_id = "${aws_route53_zone.main.zone_id}"
   969    name = "sample"
   970    type = "A"
   971    ttl = "30"
   972    records = ["127.0.0.1", "8.8.8.8"]
   973  }
   974  `