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

Add support for Cloud SQL CA Cert (#635) #1020

Merged
merged 1 commit into from
Jan 30, 2018
Merged
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
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(hello friends I know this is already merged but-)
since this is only set on read (and not something passed in to create or update), it should be only computed and not also optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! follow up inbound

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