Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where flattened ip_address had extra empty element #357

Merged
merged 1 commit into from
Aug 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion google/resource_sql_database_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ func flattenReplicaConfiguration(replicaConfiguration *sqladmin.ReplicaConfigura
}

func flattenIpAddresses(ipAddresses []*sqladmin.IpMapping) []map[string]interface{} {
ips := make([]map[string]interface{}, len(ipAddresses))
var ips []map[string]interface{}

for _, ip := range ipAddresses {
data := map[string]interface{}{
Expand Down
22 changes: 22 additions & 0 deletions google/resource_sql_database_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,28 @@ func testAccCheckGoogleSqlDatabaseInstanceEquals(n string,
return fmt.Errorf("Error master_instance_name mismatch, (%s, %s)", server, local)
}

ip_len, err := strconv.Atoi(attributes["ip_address.#"])
if err != nil {
return fmt.Errorf("Error parsing ip_addresses.# : %s", err.Error())
}
if ip_len != len(instance.IpAddresses) {
return fmt.Errorf("Error ip_addresses.# mismatch, server has %d but local has %d", len(instance.IpAddresses), ip_len)
}
// For now, assume the order matches
for idx, ip := range instance.IpAddresses {
server = attributes["ip_address."+strconv.Itoa(idx)+".ip_address"]
local = ip.IpAddress
if server != local {
return fmt.Errorf("Error ip_addresses.%d.ip_address mismatch, server has %s but local has %s", idx, server, local)
}

server = attributes["ip_address."+strconv.Itoa(idx)+".time_to_retire"]
local = ip.TimeToRetire
if server != local {
return fmt.Errorf("Error ip_addresses.%d.time_to_retire mismatch, server has %s but local has %s", idx, server, local)
}
}

server = instance.Settings.ActivationPolicy
local = attributes["settings.0.activation_policy"]
if server != local && len(server) > 0 && len(local) > 0 {
Expand Down