Skip to content

Commit

Permalink
Merge pull request #1020 from johnsonj/master
Browse files Browse the repository at this point in the history
Add support for Cloud SQL CA Cert (#635)
  • Loading branch information
emilymye authored Jan 30, 2018
2 parents 429c8e8 + 6e101dd commit 7e91cbb
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion google/resource_sql_database_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,36 @@ func resourceSqlDatabaseInstance() *schema.Resource {
},
},
},

"server_ca_cert": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cert": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"common_name": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"create_time": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"expiration_time": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"sha1_fingerprint": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
},
},
},
"self_link": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -708,6 +737,10 @@ func resourceSqlDatabaseInstanceRead(d *schema.ResourceData, meta interface{}) e
log.Printf("[WARN] Failed to set SQL Database Instance IP Addresses")
}

if err := d.Set("server_ca_cert", flattenServerCaCert(instance.ServerCaCert)); err != nil {
log.Printf("[WARN] Failed to set SQL Database CA Certificate")
}

d.Set("master_instance_name", strings.TrimPrefix(instance.MasterInstanceName, project+":"))
d.Set("project", project)
d.Set("self_link", instance.SelfLink)
Expand Down Expand Up @@ -1156,6 +1189,24 @@ func flattenIpAddresses(ipAddresses []*sqladmin.IpMapping) []map[string]interfac
return ips
}

func flattenServerCaCert(caCert *sqladmin.SslCert) []map[string]interface{} {
var cert []map[string]interface{}

if caCert != nil {
data := map[string]interface{}{
"cert": caCert.Cert,
"common_name": caCert.CommonName,
"create_time": caCert.CreateTime,
"expiration_time": caCert.ExpirationTime,
"sha1_fingerprint": caCert.Sha1Fingerprint,
}

cert = append(cert, data)
}

return cert
}

func instanceMutexKey(project, instance_name string) string {
return fmt.Sprintf("google-sql-database-instance-%s-%s", project, instance_name)
}
Expand Down

0 comments on commit 7e91cbb

Please sign in to comment.