-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: extended the postgresql module to accept IAM users and services…
… accounts (#218) * feat: extended the postgresql module to accept IAM users and services accounts. * feat: extended the postgresql module to accept IAM users and services accounts.
- Loading branch information
Showing
18 changed files
with
571 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,41 @@ | ||
# Cloud SQL Database Example | ||
|
||
This example shows how to create the public Postgres Cloud SQL database using the Terraform module with IAM accounts. | ||
|
||
## Run Terraform | ||
|
||
Create resources with terraform: | ||
|
||
```bash | ||
terraform init | ||
terraform plan | ||
terraform apply | ||
``` | ||
|
||
To remove all resources created by terraform: | ||
|
||
```bash | ||
terraform destroy | ||
``` | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| authorized\_networks | List of mapped public networks authorized to access to the instances. Default - short range of GCP health-checkers IPs | `list(map(string))` | <pre>[<br> {<br> "name": "sample-gcp-health-checkers-range",<br> "value": "130.211.0.0/28"<br> }<br>]</pre> | no | | ||
| cloudsql\_pg\_sa | IAM service account user created for Cloud SQL. | `string` | n/a | yes | | ||
| db\_name | The name of the SQL Database instance | `string` | `"example-postgres-public"` | no | | ||
| project\_id | The ID of the project in which resources will be provisioned. | `string` | n/a | yes | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| name | The name for Cloud SQL instance | | ||
| project\_id | The project to run tests against | | ||
| psql\_conn | The connection name of the master instance to be used in connection strings | | ||
| psql\_user\_pass | The password for the default user. If not set, a random one will be generated and available in the generated\_user\_password output variable. | | ||
| public\_ip\_address | The first public (PRIMARY) IPv4 address assigned for the master instance | | ||
|
||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
This file contains 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,77 @@ | ||
/** | ||
* Copyright 2019 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. | ||
*/ | ||
|
||
provider "google" { | ||
version = "~> 3.22" | ||
} | ||
|
||
provider "google-beta" { | ||
version = "~> 3.5" | ||
} | ||
|
||
provider "null" { | ||
version = "~> 2.1" | ||
} | ||
|
||
provider "random" { | ||
version = "~> 2.2" | ||
} | ||
|
||
module "postgresql-db" { | ||
source = "../../modules/postgresql" | ||
name = var.db_name | ||
random_instance_name = true | ||
database_version = "POSTGRES_9_6" | ||
project_id = var.project_id | ||
zone = "us-central1-c" | ||
region = "us-central1" | ||
tier = "db-f1-micro" | ||
|
||
deletion_protection = false | ||
|
||
ip_configuration = { | ||
ipv4_enabled = true | ||
private_network = null | ||
require_ssl = true | ||
authorized_networks = var.authorized_networks | ||
} | ||
|
||
database_flags = [ | ||
{ | ||
name = "cloudsql.iam_authentication" | ||
value = "On" | ||
}, | ||
] | ||
|
||
additional_users = [ | ||
{ | ||
name = "tftest2" | ||
password = "abcdefg" | ||
host = "localhost" | ||
}, | ||
{ | ||
name = "tftest3" | ||
password = "abcdefg" | ||
host = "localhost" | ||
}, | ||
] | ||
|
||
# Supports creation of both IAM Users and IAM Service Accounts with provided emails | ||
iam_user_emails = [ | ||
var.cloudsql_pg_sa, | ||
"[email protected]", | ||
] | ||
} |
This file contains 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,40 @@ | ||
/** | ||
* Copyright 2019 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. | ||
*/ | ||
|
||
output "project_id" { | ||
value = var.project_id | ||
description = "The project to run tests against" | ||
} | ||
|
||
output "name" { | ||
description = "The name for Cloud SQL instance" | ||
value = module.postgresql-db.instance_name | ||
} | ||
|
||
output "psql_conn" { | ||
value = module.postgresql-db.instance_connection_name | ||
description = "The connection name of the master instance to be used in connection strings" | ||
} | ||
|
||
output "psql_user_pass" { | ||
value = module.postgresql-db.generated_user_password | ||
description = "The password for the default user. If not set, a random one will be generated and available in the generated_user_password output variable." | ||
} | ||
|
||
output "public_ip_address" { | ||
description = "The first public (PRIMARY) IPv4 address assigned for the master instance" | ||
value = module.postgresql-db.public_ip_address | ||
} |
This file contains 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,39 @@ | ||
/** | ||
* Copyright 2019 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. | ||
*/ | ||
|
||
variable "project_id" { | ||
description = "The ID of the project in which resources will be provisioned." | ||
type = string | ||
} | ||
|
||
variable "authorized_networks" { | ||
default = [{ | ||
name = "sample-gcp-health-checkers-range" | ||
value = "130.211.0.0/28" | ||
}] | ||
type = list(map(string)) | ||
description = "List of mapped public networks authorized to access to the instances. Default - short range of GCP health-checkers IPs" | ||
} | ||
|
||
variable "db_name" { | ||
description = "The name of the SQL Database instance" | ||
default = "example-postgres-public" | ||
} | ||
|
||
variable "cloudsql_pg_sa" { | ||
type = string | ||
description = "IAM service account user created for Cloud SQL." | ||
} |
This file contains 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,19 @@ | ||
/** | ||
* Copyright 2019 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. | ||
*/ | ||
|
||
terraform { | ||
required_version = ">=0.12.6" | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,24 @@ | ||
/** | ||
* Copyright 2019 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. | ||
*/ | ||
|
||
module "example" { | ||
source = "../../../examples/postgresql-public-iam" | ||
|
||
project_id = var.project_id | ||
authorized_networks = var.authorized_networks | ||
db_name = var.db_name | ||
cloudsql_pg_sa = var.cloudsql_pg_sa | ||
} |
This file contains 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,40 @@ | ||
/** | ||
* Copyright 2019 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. | ||
*/ | ||
|
||
output "project_id" { | ||
value = module.example.project_id | ||
description = "The project to run tests against" | ||
} | ||
|
||
output "name" { | ||
value = module.example.name | ||
description = "The name for Cloud SQL instance" | ||
} | ||
|
||
output "psql_conn" { | ||
value = module.example.psql_conn | ||
description = "The connection name of the master instance to be used in connection strings" | ||
} | ||
|
||
output "psql_user_pass" { | ||
value = module.example.psql_user_pass | ||
description = "The password for the default user. If not set, a random one will be generated and available in the generated_user_password output variable." | ||
} | ||
|
||
output "public_ip_address" { | ||
description = "The first public (PRIMARY) IPv4 address assigned for the master instance" | ||
value = module.example.public_ip_address | ||
} |
Oops, something went wrong.