Terraform | Retrieve the (client-key) certificate

2019-12-16 17:01发布

问题:

I would like to retrieve the client-key SSL key of cloudsql via Terraform, I was able to retrieve the server-ca and the client-cert via terraform but have no idea how to get the client-key file. TO retrieve the client-cert I have used the below mentioned point: Please look.

resource "google_sql_ssl_cert" "client_cert" {
 depends_on  = ["google_sql_database_instance.new_instance_sql_master", 
            "google_sql_user.users"]
 common_name = "terraform1"
 project    = "${var.project_id}"
 instance ="${google_sql_database_instance.new_instance_sql_master.name}"
 }

Output.tf

output "client_cert" {
 value       = "${google_sql_ssl_cert.client_cert.0.cert}"
 description = "The CA Certificate used to connect to the SQL Instance via 
                SSL"
 }

Please let me know how can I retrieve the client-key private key. i.e server-ca, client-cert and I need client-key via terraform.

回答1:

In order to get the client private key, use the following snippet with any other parameters you wish to have:

output "client_privkey" {
  value       = "${google_sql_ssl_cert.client_cert.*.private_key}"
}

For client-certificate: value = "${google_sql_ssl_cert.client_cert.*.cert}"

For server certificate: value = ${google_sql_ssl_cert.client_cert.*.server_ca_cert}"