Skip to content

Commit

Permalink
SQL DB Instance has attribute first_ip_address (#1050)
Browse files Browse the repository at this point in the history
* Expose first ip address on sql db instance.

Signed-off-by: Desmond Pompa Alarcon Rawls <[email protected]>

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

Signed-off-by: Genevieve LEsperance <[email protected]>

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

Signed-off-by: Desmond Pompa Alarcon Rawls <[email protected]>

* Add first_ip_address to sql db instance scheme.

Signed-off-by: Genevieve LEsperance <[email protected]>
  • Loading branch information
Genevieve authored and danawillow committed Mar 2, 2018
1 parent 58a7ef9 commit 7e358d8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
17 changes: 16 additions & 1 deletion google/resource_sql_database_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
}
Expand Down
8 changes: 8 additions & 0 deletions google/resource_sql_database_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7e358d8

Please sign in to comment.