provider/aws: Change Route 53 record to allow resource updates

This removes `ForceNew` from `records` and `ttl`, and introduces a
`resourceAwsRoute53RecordUpdate` function. The `resourceAwsRoute53RecordUpdate`
falls through to the `resourceAwsRoute53RecordCreate` function, which utilizes
AWS `UPSERT` behavior and diffs for us.

`Name` and `Type` are used by AWS in the `UPSERT`, so only records with matching
`name` and `type` can be updated. Others are created as new, so we leave the
`ForceNew` behavior here.
This commit is contained in:
Clint Shryock 2015-04-06 10:16:23 -05:00
parent 2b294ddb81
commit c5eb16cfb1
1 changed files with 14 additions and 2 deletions

View File

@ -18,6 +18,7 @@ func resourceAwsRoute53Record() *schema.Resource {
return &schema.Resource{ return &schema.Resource{
Create: resourceAwsRoute53RecordCreate, Create: resourceAwsRoute53RecordCreate,
Read: resourceAwsRoute53RecordRead, Read: resourceAwsRoute53RecordRead,
Update: resourceAwsRoute53RecordUpdate,
Delete: resourceAwsRoute53RecordDelete, Delete: resourceAwsRoute53RecordDelete,
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
@ -42,14 +43,12 @@ func resourceAwsRoute53Record() *schema.Resource {
"ttl": &schema.Schema{ "ttl": &schema.Schema{
Type: schema.TypeInt, Type: schema.TypeInt,
Required: true, Required: true,
ForceNew: true,
}, },
"records": &schema.Schema{ "records": &schema.Schema{
Type: schema.TypeSet, Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString}, Elem: &schema.Schema{Type: schema.TypeString},
Required: true, Required: true,
ForceNew: true,
Set: func(v interface{}) int { Set: func(v interface{}) int {
return hashcode.String(v.(string)) return hashcode.String(v.(string))
}, },
@ -58,6 +57,19 @@ func resourceAwsRoute53Record() *schema.Resource {
} }
} }
func resourceAwsRoute53RecordUpdate(d *schema.ResourceData, meta interface{}) error {
// Route 53 supports CREATE, DELETE, and UPSERT actions. We use UPSERT, and
// AWS dynamically determins if a record should be created or updated.
// Amazon Route 53 can update an existing resource record set only when all
// of the following values match: Name, Type
// (and SetIdentifier, which we don't use yet).
// See http://docs.aws.amazon.com/Route53/latest/APIReference/API_ChangeResourceRecordSets_Requests.html#change-rrsets-request-action
//
// Because we use UPSERT, for resouce update here we simply fall through to
// our resource create function.
return resourceAwsRoute53RecordCreate(d, meta)
}
func resourceAwsRoute53RecordCreate(d *schema.ResourceData, meta interface{}) error { func resourceAwsRoute53RecordCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).r53conn conn := meta.(*AWSClient).r53conn
zone := d.Get("zone_id").(string) zone := d.Get("zone_id").(string)