-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for geolocation and latency records to aws route53 provider
- Loading branch information
Adam Mielke
committed
Mar 28, 2016
1 parent
1b1e462
commit b542278
Showing
6 changed files
with
17,248 additions
and
40 deletions.
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
41 changes: 41 additions & 0 deletions
41
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,41 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"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 Route 53 Record State v0; migrating to v1") | ||
return migrateR53RecordStateV0toV1(is) | ||
default: | ||
return is, fmt.Errorf("Unexpected schema version: %d", v) | ||
} | ||
} | ||
|
||
func migrateR53RecordStateV0toV1(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) | ||
if is.Attributes["weight"] != "-1" { | ||
is.Attributes["weighted_routing_policy.#"] = "1" | ||
key := fmt.Sprintf("weighted_routing_policy.0.weight") | ||
is.Attributes[key] = is.Attributes["weight"] | ||
} | ||
if is.Attributes["failover"] != "" { | ||
is.Attributes["failover_routing_policy.#"] = "1" | ||
key := fmt.Sprintf("failover_routing_policy.0.type") | ||
is.Attributes[key] = is.Attributes["failover"] | ||
} | ||
delete(is.Attributes, "weight") | ||
delete(is.Attributes, "failover") | ||
log.Printf("[DEBUG] Attributes after migration: %#v", is.Attributes) | ||
return is, nil | ||
} |
58 changes: 58 additions & 0 deletions
58
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,58 @@ | ||
package aws | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAWSRoute53RecordMigrateState(t *testing.T) { | ||
cases := map[string]struct { | ||
StateVersion int | ||
Attributes map[string]string | ||
Expected map[string]string | ||
Meta interface{} | ||
}{ | ||
"v0_1": { | ||
StateVersion: 0, | ||
Attributes: map[string]string{ | ||
"weight": "0", | ||
"failover": "PRIMARY", | ||
}, | ||
Expected: map[string]string{ | ||
"weighted_routing_policy.#": "1", | ||
"weighted_routing_policy.0.weight": "0", | ||
"failover_routing_policy.#": "1", | ||
"failover_routing_policy.0.type": "PRIMARY", | ||
}, | ||
}, | ||
"v0_2": { | ||
StateVersion: 0, | ||
Attributes: map[string]string{ | ||
"weight": "-1", | ||
}, | ||
Expected: map[string]string{}, | ||
}, | ||
} | ||
|
||
for tn, tc := range cases { | ||
is := &terraform.InstanceState{ | ||
ID: "route53_record", | ||
Attributes: tc.Attributes, | ||
} | ||
is, err := resourceAwsRoute53Record().MigrateState( | ||
tc.StateVersion, is, tc.Meta) | ||
|
||
if err != nil { | ||
t.Fatalf("bad: %s, err: %#v", tn, err) | ||
} | ||
|
||
for k, v := range tc.Expected { | ||
if is.Attributes[k] != v { | ||
t.Fatalf( | ||
"bad: %s\n\n expected: %#v -> %#v\n got: %#v -> %#v\n in: %#v", | ||
tn, k, v, k, is.Attributes[k], is.Attributes) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.