-
Notifications
You must be signed in to change notification settings - Fork 286
feat(cloud_sql): Add samples for Google/Customer-managed CAS instances. #842
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b7e1274
feat(cloud_sql): Add samples for Google/Customer-managed CAS instances.
feng-zhe 50c65d7
feat(cloud_sql): improve the samples for customer-managed CAS CA inst…
feng-zhe 3f6f788
resolve some review comments
feng-zhe 378840c
Add edition to make mysql and pg examples work
feng-zhe 0cd1b6c
Merge branch 'main' into main
feng-zhe af14240
Merge branch 'main' into main
feng-zhe 34a8514
fix lint issues.
feng-zhe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
cloud_sql/mysql_instance_customer_managed_cas_ca/main.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /** | ||
| * Copyright 2022 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| # [START cloud_sql_instance_service_identity] | ||
| resource "google_project_service_identity" "gcp_sa_cloud_sql" { | ||
| provider = google-beta | ||
| service = "sqladmin.googleapis.com" | ||
| } | ||
| # [END cloud_sql_instance_service_identity] | ||
|
|
||
| # [START cloud_sql_mysql_instance_ca_pool] | ||
| resource "google_privateca_ca_pool" "customer_ca_pool" { | ||
feng-zhe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| name = "tf-test-cap" | ||
feng-zhe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| location = "asia-northeast1" | ||
| tier = "DEVOPS" | ||
| publishing_options { | ||
| publish_ca_cert = false | ||
| publish_crl = false | ||
| } | ||
| } | ||
| # [END cloud_sql_mysql_instance_ca_pool] | ||
|
|
||
| # [START cloud_sql_mysql_instance_ca] | ||
| resource "google_privateca_certificate_authority" "customer_ca" { | ||
| pool = google_privateca_ca_pool.customer_ca_pool.name | ||
| certificate_authority_id = "tf-test-ca" | ||
| location = "asia-northeast1" | ||
| lifetime = "86400s" | ||
| type = "SELF_SIGNED" | ||
| deletion_protection = false | ||
feng-zhe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| skip_grace_period = true | ||
| ignore_active_certificates_on_deletion = true | ||
| config { | ||
| subject_config { | ||
| subject { | ||
| organization = "Test LLC" | ||
feng-zhe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| common_name = "my-ca" | ||
| } | ||
| } | ||
| x509_config { | ||
| ca_options { | ||
| is_ca = true | ||
| } | ||
| key_usage { | ||
| base_key_usage { | ||
| cert_sign = true | ||
| crl_sign = true | ||
| } | ||
| extended_key_usage { | ||
| server_auth = false | ||
| } | ||
| } | ||
| } | ||
| } | ||
| key_spec { | ||
| algorithm = "RSA_PKCS1_4096_SHA256" | ||
| } | ||
| } | ||
| # [END cloud_sql_mysql_instance_ca] | ||
|
|
||
| # [START cloud_sql_mysql_instance_iam_granting] | ||
| resource "google_privateca_ca_pool_iam_member" "granting" { | ||
| ca_pool = google_privateca_ca_pool.customer_ca_pool.id | ||
| role = "roles/privateca.certificateRequester" | ||
|
|
||
| member = "serviceAccount:${google_project_service_identity.gcp_sa_cloud_sql.email}" | ||
| } | ||
| # [END cloud_sql_mysql_instance_iam_granting] | ||
|
|
||
| # [START cloud_sql_mysql_instance_customer_managed_cas_ca] | ||
| resource "google_sql_database_instance" "mysql_instance" { | ||
| name = "mysql-instance" | ||
| region = "asia-northeast1" | ||
| database_version = "MYSQL_8_0" | ||
| settings { | ||
| tier = "db-f1-micro" | ||
| ip_configuration { | ||
| # The following server CA mode lets the instance use customer-managed CAS CA to issue server certificates. | ||
| # https://cloud.google.com/sql/docs/mysql/admin-api/rest/v1beta4/instances#ipconfiguration | ||
| server_ca_mode = "CUSTOMER_MANAGED_CAS_CA" | ||
| # This is the name of the customer-owned CAS CA pool. | ||
| server_ca_pool = google_privateca_ca_pool.customer_ca_pool.id | ||
| } | ||
| } | ||
| # set `deletion_protection` to true, will ensure that one cannot accidentally delete this instance by | ||
| # use of Terraform whereas `deletion_protection_enabled` flag protects this instance at the GCP level. | ||
| deletion_protection = false | ||
| } | ||
| # [END cloud_sql_mysql_instance_customer_managed_cas_ca] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /** | ||
| * Copyright 2022 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| # [START cloud_sql_mysql_instance_google_managed_cas_ca] | ||
| resource "google_sql_database_instance" "mysql_instance" { | ||
| name = "mysql-instance" | ||
| region = "asia-northeast1" | ||
| database_version = "MYSQL_8_0" | ||
feng-zhe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| settings { | ||
| tier = "db-f1-micro" | ||
| ip_configuration { | ||
| # The following server CA mode lets the instance use Google-managed CAS CA to issue server certificates. | ||
| # https://cloud.google.com/sql/docs/mysql/admin-api/rest/v1beta4/instances#ipconfiguration | ||
| server_ca_mode = "GOOGLE_MANAGED_CAS_CA" | ||
| } | ||
| } | ||
| # set `deletion_protection` to true, will ensure that one cannot accidentally delete this instance by | ||
| # use of Terraform whereas `deletion_protection_enabled` flag protects this instance at the GCP level. | ||
| deletion_protection = false | ||
| } | ||
| # [END cloud_sql_mysql_instance_google_managed_cas_ca] | ||
101 changes: 101 additions & 0 deletions
101
cloud_sql/postgres_instance_customer_managed_cas_ca/main.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /** | ||
| * Copyright 2022 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| # [START cloud_sql_instance_service_identity] | ||
| resource "google_project_service_identity" "gcp_sa_cloud_sql" { | ||
| provider = google-beta | ||
| service = "sqladmin.googleapis.com" | ||
| } | ||
| # [END cloud_sql_instance_service_identity] | ||
|
|
||
| # [START cloud_sql_postgres_instance_ca_pool] | ||
| resource "google_privateca_ca_pool" "customer_ca_pool" { | ||
| name = "tf-test-cap" | ||
| location = "asia-northeast1" | ||
| tier = "DEVOPS" | ||
| publishing_options { | ||
| publish_ca_cert = false | ||
| publish_crl = false | ||
| } | ||
| } | ||
| # [END cloud_sql_postgres_instance_ca_pool] | ||
|
|
||
| # [START cloud_sql_postgres_instance_ca] | ||
| resource "google_privateca_certificate_authority" "customer_ca" { | ||
| pool = google_privateca_ca_pool.customer_ca_pool.name | ||
| certificate_authority_id = "tf-test-ca" | ||
| location = "asia-northeast1" | ||
| lifetime = "86400s" | ||
| type = "SELF_SIGNED" | ||
| deletion_protection = false | ||
| skip_grace_period = true | ||
| ignore_active_certificates_on_deletion = true | ||
| config { | ||
| subject_config { | ||
| subject { | ||
| organization = "Test LLC" | ||
| common_name = "my-ca" | ||
| } | ||
| } | ||
| x509_config { | ||
| ca_options { | ||
| is_ca = true | ||
| } | ||
| key_usage { | ||
| base_key_usage { | ||
| cert_sign = true | ||
| crl_sign = true | ||
| } | ||
| extended_key_usage { | ||
| server_auth = false | ||
| } | ||
| } | ||
| } | ||
| } | ||
| key_spec { | ||
| algorithm = "RSA_PKCS1_4096_SHA256" | ||
| } | ||
| } | ||
| # [END cloud_sql_postgres_instance_ca] | ||
|
|
||
| # [START cloud_sql_postgres_instance_iam_granting] | ||
| resource "google_privateca_ca_pool_iam_member" "granting" { | ||
| ca_pool = google_privateca_ca_pool.customer_ca_pool.id | ||
| role = "roles/privateca.certificateRequester" | ||
|
|
||
| member = "serviceAccount:${google_project_service_identity.gcp_sa_cloud_sql.email}" | ||
| } | ||
| # [END cloud_sql_postgres_instance_iam_granting] | ||
|
|
||
| # [START cloud_sql_postgres_instance_google_managed_cas_ca] | ||
| resource "google_sql_database_instance" "postgres_instance" { | ||
| name = "postgres-instance" | ||
| region = "asia-northeast1" | ||
| database_version = "POSTGRES_14" | ||
| settings { | ||
| tier = "db-custom-2-7680" | ||
feng-zhe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ip_configuration { | ||
| # The following server CA mode lets the instance use customer-managed CAS CA to issue server certificates. | ||
| # https://cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances#ipconfiguration | ||
| server_ca_mode = "CUSTOMER_MANAGED_CAS_CA" | ||
| # This is the name of the customer-owned CAS CA pool. | ||
feng-zhe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| server_ca_pool = google_privateca_ca_pool.customer_ca_pool.id | ||
| } | ||
| } | ||
| # set `deletion_protection` to true, will ensure that one cannot accidentally delete this instance by | ||
| # use of Terraform whereas `deletion_protection_enabled` flag protects this instance at the GCP level. | ||
| deletion_protection = false | ||
| } | ||
| # [END cloud_sql_postgres_instance_google_managed_cas_ca] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /** | ||
| * Copyright 2022 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| # [START cloud_sql_postgres_instance_google_managed_cas_ca] | ||
| resource "google_sql_database_instance" "postgres_instance" { | ||
| name = "postgres-instance" | ||
| region = "asia-northeast1" | ||
| database_version = "POSTGRES_14" | ||
feng-zhe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| settings { | ||
| tier = "db-custom-2-7680" | ||
| ip_configuration { | ||
| # The following server CA mode lets the instance use Google-managed CAS CA to issue server certificates. | ||
| # https://cloud.google.com/sql/docs/postgres/admin-api/rest/v1beta4/instances#ipconfiguration | ||
| server_ca_mode = "GOOGLE_MANAGED_CAS_CA" | ||
| } | ||
| } | ||
| # set `deletion_protection` to true, will ensure that one cannot accidentally delete this instance by | ||
| # use of Terraform whereas `deletion_protection_enabled` flag protects this instance at the GCP level. | ||
| deletion_protection = false | ||
| } | ||
| # [END cloud_sql_postgres_instance_google_managed_cas_ca] | ||
102 changes: 102 additions & 0 deletions
102
cloud_sql/sqlserver_instance_customer_managed_cas_ca/main.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| /** | ||
| * Copyright 2022 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| # [START cloud_sql_instance_service_identity] | ||
| resource "google_project_service_identity" "gcp_sa_cloud_sql" { | ||
| provider = google-beta | ||
| service = "sqladmin.googleapis.com" | ||
| } | ||
| # [END cloud_sql_instance_service_identity] | ||
|
|
||
| # [START cloud_sql_sqlserver_instance_ca_pool] | ||
| resource "google_privateca_ca_pool" "customer_ca_pool" { | ||
| name = "tf-test-cap" | ||
| location = "asia-northeast1" | ||
| tier = "DEVOPS" | ||
| publishing_options { | ||
| publish_ca_cert = false | ||
| publish_crl = false | ||
| } | ||
| } | ||
| # [END cloud_sql_sqlserver_instance_ca_pool] | ||
|
|
||
| # [START cloud_sql_sqlserver_instance_ca] | ||
| resource "google_privateca_certificate_authority" "customer_ca" { | ||
| pool = google_privateca_ca_pool.customer_ca_pool.name | ||
| certificate_authority_id = "tf-test-ca" | ||
| location = "asia-northeast1" | ||
| lifetime = "86400s" | ||
| type = "SELF_SIGNED" | ||
| deletion_protection = false | ||
| skip_grace_period = true | ||
| ignore_active_certificates_on_deletion = true | ||
| config { | ||
| subject_config { | ||
| subject { | ||
| organization = "Test LLC" | ||
| common_name = "my-ca" | ||
| } | ||
| } | ||
| x509_config { | ||
| ca_options { | ||
| is_ca = true | ||
| } | ||
| key_usage { | ||
| base_key_usage { | ||
| cert_sign = true | ||
| crl_sign = true | ||
| } | ||
| extended_key_usage { | ||
| server_auth = false | ||
| } | ||
| } | ||
| } | ||
| } | ||
| key_spec { | ||
| algorithm = "RSA_PKCS1_4096_SHA256" | ||
| } | ||
| } | ||
| # [END cloud_sql_sqlserver_instance_ca] | ||
|
|
||
| # [START cloud_sql_sqlserver_instance_iam_granting] | ||
| resource "google_privateca_ca_pool_iam_member" "granting" { | ||
| ca_pool = google_privateca_ca_pool.customer_ca_pool.id | ||
| role = "roles/privateca.certificateRequester" | ||
|
|
||
| member = "serviceAccount:${google_project_service_identity.gcp_sa_cloud_sql.email}" | ||
| } | ||
| # [END cloud_sql_sqlserver_instance_iam_granting] | ||
|
|
||
| # [START cloud_sql_sqlserver_instance_require_ssl] | ||
| resource "google_sql_database_instance" "sqlserver_instance" { | ||
| name = "sqlserver-instance" | ||
| region = "asia-northeast1" | ||
| database_version = "SQLSERVER_2019_STANDARD" | ||
| root_password = "INSERT-PASSWORD-HERE" | ||
| settings { | ||
| tier = "db-custom-2-7680" | ||
| ip_configuration { | ||
| # The following server CA mode lets the instance use customer-managed CAS CA to issue server certificates. | ||
| # https://cloud.google.com/sql/docs/sqlserver/admin-api/rest/v1beta4/instances#ipconfiguration | ||
| server_ca_mode = "CUSTOMER_MANAGED_CAS_CA" | ||
| # This is the name of the customer-owned CAS CA pool. | ||
| server_ca_pool = google_privateca_ca_pool.customer_ca_pool.id | ||
| } | ||
| } | ||
| # set `deletion_protection` to true, will ensure that one cannot accidentally delete this instance by | ||
| # use of Terraform whereas `deletion_protection_enabled` flag protects this instance at the GCP level. | ||
| deletion_protection = false | ||
| } | ||
| # [END cloud_sql_sqlserver_instance_require_ssl] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.