From 7e358d894ad08f1dbdde5be17e6b29fb7f7fa57e Mon Sep 17 00:00:00 2001 From: Genevieve Date: Thu, 1 Mar 2018 17:12:33 -0800 Subject: [PATCH] SQL DB Instance has attribute first_ip_address (#1050) * Expose first ip address on sql db instance. Signed-off-by: Desmond Pompa Alarcon Rawls * Use the ip_address key on the first map in ip_address list. Signed-off-by: Genevieve LEsperance * Run first_ip_address test check if there is an ip address. Signed-off-by: Desmond Pompa Alarcon Rawls * Add first_ip_address to sql db instance scheme. Signed-off-by: Genevieve LEsperance --- google/resource_sql_database_instance.go | 17 ++++++++++++++++- google/resource_sql_database_instance_test.go | 8 ++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/google/resource_sql_database_instance.go b/google/resource_sql_database_instance.go index 5f026532436..28ca32d4e01 100644 --- a/google/resource_sql_database_instance.go +++ b/google/resource_sql_database_instance.go @@ -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") } diff --git a/google/resource_sql_database_instance_test.go b/google/resource_sql_database_instance_test.go index 5878336cc6f..b1e3ae06e4a 100644 --- a/google/resource_sql_database_instance_test.go +++ b/google/resource_sql_database_instance_test.go @@ -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 {