SQL DB Instance has attribute first_ip_address (#1050)

* Expose first ip address on sql db instance.

Signed-off-by: Desmond Pompa Alarcon Rawls <captaingrover@gmail.com>

* Use the ip_address key on the first map in ip_address list.

Signed-off-by: Genevieve LEsperance <glesperance@pivotal.io>

* Run first_ip_address test check if there is an ip address.

Signed-off-by: Desmond Pompa Alarcon Rawls <captaingrover@gmail.com>

* Add first_ip_address to sql db instance scheme.

Signed-off-by: Genevieve LEsperance <glesperance@pivotal.io>
This commit is contained in:
Genevieve 2018-03-01 17:12:33 -08:00 committed by Dana Hoffman
parent 58a7ef9d03
commit 7e358d894a
2 changed files with 24 additions and 1 deletions

View File

@ -257,6 +257,11 @@ func resourceSqlDatabaseInstance() *schema.Resource {
},
},
"first_ip_address": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
@ -729,13 +734,23 @@ func resourceSqlDatabaseInstanceRead(d *schema.ResourceData, meta interface{}) e
if err := d.Set("settings", flattenSettings(instance.Settings)); err != nil {
log.Printf("[WARN] Failed to set SQL Database Instance Settings")
}
if err := d.Set("replica_configuration", flattenReplicaConfiguration(instance.ReplicaConfiguration)); err != nil {
log.Printf("[WARN] Failed to set SQL Database Instance Replica Configuration")
}
if err := d.Set("ip_address", flattenIpAddresses(instance.IpAddresses)); err != nil {
ipAddresses := flattenIpAddresses(instance.IpAddresses)
if err := d.Set("ip_address", ipAddresses); err != nil {
log.Printf("[WARN] Failed to set SQL Database Instance IP Addresses")
}
if len(ipAddresses) > 0 {
firstIpAddress := ipAddresses[0]["ip_address"]
if err := d.Set("first_ip_address", firstIpAddress); err != nil {
log.Printf("[WARN] Failed to set SQL Database Instance First IP Address")
}
}
if err := d.Set("server_ca_cert", flattenServerCaCert(instance.ServerCaCert)); err != nil {
log.Printf("[WARN] Failed to set SQL Database CA Certificate")
}

View File

@ -570,6 +570,14 @@ func testAccCheckGoogleSqlDatabaseInstanceEquals(n string,
}
}
if len(instance.IpAddresses) > 0 {
server = instance.IpAddresses[0].IpAddress
local = attributes["first_ip_address"]
if server != local {
return fmt.Errorf("Error first_ip_address mismatch, server has %s but local has %s", server, local)
}
}
server = instance.Settings.ActivationPolicy
local = attributes["settings.0.activation_policy"]
if server != local && len(server) > 0 && len(local) > 0 {