-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6592 from hashicorp/b-aws-r53-name-state
provider/aws: Update Route53 Record to schema v1, normalizing name
- Loading branch information
Showing
4 changed files
with
162 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
builtin/providers/aws/resource_aws_route53_record_migrate.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"strings" | ||
|
||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func resourceAwsRoute53RecordMigrateState( | ||
v int, is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) { | ||
switch v { | ||
case 0: | ||
log.Println("[INFO] Found AWS Route53 Record State v0; migrating to v1") | ||
return migrateRoute53RecordStateV0toV1(is) | ||
default: | ||
return is, fmt.Errorf("Unexpected schema version: %d", v) | ||
} | ||
} | ||
|
||
func migrateRoute53RecordStateV0toV1(is *terraform.InstanceState) (*terraform.InstanceState, error) { | ||
if is.Empty() { | ||
log.Println("[DEBUG] Empty InstanceState; nothing to migrate.") | ||
return is, nil | ||
} | ||
|
||
log.Printf("[DEBUG] Attributes before migration: %#v", is.Attributes) | ||
newName := strings.TrimSuffix(is.Attributes["name"], ".") | ||
is.Attributes["name"] = newName | ||
log.Printf("[DEBUG] Attributes after migration: %#v, new name: %s", is.Attributes, newName) | ||
return is, nil | ||
} |
59 changes: 59 additions & 0 deletions
59
builtin/providers/aws/resource_aws_route53_record_migrate_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package aws | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAWSRoute53RecordMigrateState(t *testing.T) { | ||
cases := map[string]struct { | ||
StateVersion int | ||
ID string | ||
Attributes map[string]string | ||
Expected string | ||
Meta interface{} | ||
}{ | ||
"v0_0": { | ||
StateVersion: 0, | ||
ID: "some_id", | ||
Attributes: map[string]string{ | ||
"name": "www", | ||
}, | ||
Expected: "www", | ||
}, | ||
"v0_1": { | ||
StateVersion: 0, | ||
ID: "some_id", | ||
Attributes: map[string]string{ | ||
"name": "www.notdomain.com.", | ||
}, | ||
Expected: "www.notdomain.com", | ||
}, | ||
"v0_2": { | ||
StateVersion: 0, | ||
ID: "some_id", | ||
Attributes: map[string]string{ | ||
"name": "www.notdomain.com", | ||
}, | ||
Expected: "www.notdomain.com", | ||
}, | ||
} | ||
|
||
for tn, tc := range cases { | ||
is := &terraform.InstanceState{ | ||
ID: tc.ID, | ||
Attributes: tc.Attributes, | ||
} | ||
is, err := resourceAwsRoute53RecordMigrateState( | ||
tc.StateVersion, is, tc.Meta) | ||
|
||
if err != nil { | ||
t.Fatalf("bad: %s, err: %#v", tn, err) | ||
} | ||
|
||
if is.Attributes["name"] != tc.Expected { | ||
t.Fatalf("bad Route 53 Migrate: %s\n\n expected: %s", is.Attributes["name"], tc.Expected) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters