Skip to content

Commit

Permalink
fix: Add outputs for the actual google_sql_database_instance resour…
Browse files Browse the repository at this point in the history
…ces (#193)

Co-authored-by: Andrey Kaipov <andreykaipov@users.noreply.github.com>
  • Loading branch information
andreykaipov and andreykaipov committed Apr 22, 2021
1 parent 4b787b2 commit 70205b0
Show file tree
Hide file tree
Showing 18 changed files with 124 additions and 1 deletion.
2 changes: 2 additions & 0 deletions examples/mysql-ha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ terraform destroy
| Name | Description |
|------|-------------|
| authorized\_network | n/a |
| instances | n/a |
| name | The name for Cloud SQL instance |
| project\_id | n/a |
| replicas | n/a |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
8 changes: 8 additions & 0 deletions examples/mysql-ha/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,11 @@ output "name" {
output "authorized_network" {
value = var.mysql_ha_external_ip_range
}

output "replicas" {
value = module.mysql.replicas
}

output "instances" {
value = module.mysql.instances
}
2 changes: 2 additions & 0 deletions examples/postgresql-ha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ terraform destroy
| Name | Description |
|------|-------------|
| authorized\_network | n/a |
| instances | n/a |
| name | The name for Cloud SQL instance |
| project\_id | n/a |
| replicas | n/a |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
8 changes: 8 additions & 0 deletions examples/postgresql-ha/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,11 @@ output "name" {
output "authorized_network" {
value = var.pg_ha_external_ip_range
}

output "replicas" {
value = module.pg.replicas
}

output "instances" {
value = module.pg.instances
}
1 change: 1 addition & 0 deletions modules/mssql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ The following dependency must be available for SQL Server module:
| instance\_self\_link | The URI of the master instance |
| instance\_server\_ca\_cert | The CA certificate information used to connect to the SQL instance via SSL |
| instance\_service\_account\_email\_address | The service account email address assigned to the master instance |
| primary | The `google_sql_database_instance` resource representing the primary instance |
| private\_address | The private IP address assigned for the master instance |
| root\_password | MSSERVER password for the root user. If not set, a random one will be generated and available in the root\_password output variable. |

Expand Down
6 changes: 6 additions & 0 deletions modules/mssql/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,9 @@ output "root_password" {
value = coalesce(var.root_password, random_password.root-password.result)
sensitive = true
}

// Resources
output "primary" {
value = google_sql_database_instance.default
description = "The `google_sql_database_instance` resource representing the primary instance"
}
3 changes: 3 additions & 0 deletions modules/mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq
| instance\_self\_link | The URI of the master instance |
| instance\_server\_ca\_cert | The CA certificate information used to connect to the SQL instance via SSL |
| instance\_service\_account\_email\_address | The service account email address assigned to the master instance |
| instances | A list of all `google_sql_database_instance` resources we've created |
| primary | The `google_sql_database_instance` resource representing the primary instance |
| private\_address | The private IP address assigned for the master instance |
| private\_ip\_address | The first private (PRIVATE) IPv4 address assigned for the master instance |
| public\_ip\_address | The first public (PRIMARY) IPv4 address assigned for the master instance |
| read\_replica\_instance\_names | The instance names for the read replica instances |
| replicas | A list of `google_sql_database_instance` resources representing the replicas |
| replicas\_instance\_connection\_names | The connection names of the replica instances to be used in connection strings |
| replicas\_instance\_first\_ip\_addresses | The first IPv4 addresses of the addresses assigned for the replica instances |
| replicas\_instance\_self\_links | The URIs of the replica instances |
Expand Down
16 changes: 16 additions & 0 deletions modules/mysql/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,19 @@ output "private_ip_address" {
description = "The first private (PRIVATE) IPv4 address assigned for the master instance"
value = google_sql_database_instance.default.private_ip_address
}

// Resources
output "primary" {
value = google_sql_database_instance.default
description = "The `google_sql_database_instance` resource representing the primary instance"
}

output "replicas" {
value = values(google_sql_database_instance.replicas)
description = "A list of `google_sql_database_instance` resources representing the replicas"
}

output "instances" {
value = concat([google_sql_database_instance.default], values(google_sql_database_instance.replicas))
description = "A list of all `google_sql_database_instance` resources we've created"
}
3 changes: 3 additions & 0 deletions modules/postgresql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq
| instance\_self\_link | The URI of the master instance |
| instance\_server\_ca\_cert | The CA certificate information used to connect to the SQL instance via SSL |
| instance\_service\_account\_email\_address | The service account email address assigned to the master instance |
| instances | A list of all `google_sql_database_instance` resources we've created |
| primary | The `google_sql_database_instance` resource representing the primary instance |
| private\_ip\_address | The first private (PRIVATE) IPv4 address assigned for the master instance |
| public\_ip\_address | The first public (PRIMARY) IPv4 address assigned for the master instance |
| read\_replica\_instance\_names | The instance names for the read replica instances |
| replicas | A list of `google_sql_database_instance` resources representing the replicas |
| replicas\_instance\_connection\_names | The connection names of the replica instances to be used in connection strings |
| replicas\_instance\_first\_ip\_addresses | The first IPv4 addresses of the addresses assigned for the replica instances |
| replicas\_instance\_self\_links | The URIs of the replica instances |
Expand Down
16 changes: 16 additions & 0 deletions modules/postgresql/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,19 @@ output "generated_user_password" {
value = random_id.user-password.hex
sensitive = true
}

// Resources
output "primary" {
value = google_sql_database_instance.default
description = "The `google_sql_database_instance` resource representing the primary instance"
}

output "replicas" {
value = values(google_sql_database_instance.replicas)
description = "A list of `google_sql_database_instance` resources representing the replicas"
}

output "instances" {
value = concat([google_sql_database_instance.default], values(google_sql_database_instance.replicas))
description = "A list of all `google_sql_database_instance` resources we've created"
}
3 changes: 3 additions & 0 deletions modules/safer_mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,12 @@ mysql -S $HOME/mysql_sockets/myproject:region:instance -u user -p
| instance\_name | The instance name for the master instance |
| instance\_self\_link | The URI of the master instance |
| instance\_service\_account\_email\_address | The service account email address assigned to the master instance |
| instances | A list of all `google_sql_database_instance` resources we've created |
| primary | The `google_sql_database_instance` resource representing the primary instance |
| private\_ip\_address | The first private (PRIVATE) IPv4 address assigned for the master instance |
| public\_ip\_address | The first public (PRIMARY) IPv4 address assigned for the master instance |
| read\_replica\_instance\_names | The instance names for the read replica instances |
| replicas | A list of `google_sql_database_instance` resources representing the replicas |
| replicas\_instance\_connection\_names | The connection names of the replica instances to be used in connection strings |
| replicas\_instance\_self\_links | The URIs of the replica instances |
| replicas\_instance\_service\_account\_email\_addresses | The service account email addresses assigned to the replica instances |
Expand Down
17 changes: 16 additions & 1 deletion modules/safer_mysql/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ output "instance_service_account_email_address" {
}

// Replicas

output "replicas_instance_connection_names" {
value = module.safer_mysql.replicas_instance_connection_names
description = "The connection names of the replica instances to be used in connection strings"
Expand Down Expand Up @@ -77,3 +76,19 @@ output "instance_ip_address" {
value = module.safer_mysql.instance_ip_address
description = "The IPv4 address assigned for the master instance"
}

// Resources
output "primary" {
value = module.safer_mysql.primary
description = "The `google_sql_database_instance` resource representing the primary instance"
}

output "replicas" {
value = module.safer_mysql.replicas
description = "A list of `google_sql_database_instance` resources representing the replicas"
}

output "instances" {
value = module.safer_mysql.instances
description = "A list of all `google_sql_database_instance` resources we've created"
}
8 changes: 8 additions & 0 deletions test/fixtures/mysql-ha/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@ output "name" {
output "authorized_network" {
value = module.example.authorized_network
}

output "replicas" {
value = module.example.replicas
}

output "instances" {
value = module.example.instances
}
8 changes: 8 additions & 0 deletions test/fixtures/postgresql-ha/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@ output "name" {
output "authorized_network" {
value = module.example.authorized_network
}

output "replicas" {
value = module.example.replicas
}

output "instances" {
value = module.example.instances
}
6 changes: 6 additions & 0 deletions test/integration/mysql-ha/controls/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
project_id = attribute('project_id')
basename = attribute('name')
authorized_network = attribute('authorized_network')
replicas = attribute('replicas')
instances = attribute('instances')

describe google_sql_database_instances(project: project_id).where(instance_name: /#{basename}/) do
its(:count) { should eq 4 }
its(:count) { should eq 1 + replicas.length }
its(:count) { should eq instances.length }
end

describe google_sql_database_instance(project: project_id, database: basename) do
Expand Down Expand Up @@ -61,6 +65,8 @@
%i[a b c].each_with_index do |zone, index|
name = "#{basename}-replica-test#{index}"
describe google_sql_database_instance(project: project_id, database: name) do
its(:name) { should eq replicas[index]['name'] }

let(:expected_settings) {
{
activation_policy: "ALWAYS",
Expand Down
6 changes: 6 additions & 0 deletions test/integration/mysql-ha/inspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ attributes:
- name: authorized_network
type: string
required: true
- name: replicas
type: array
required: true
- name: instances
type: array
required: true
6 changes: 6 additions & 0 deletions test/integration/postgresql-ha/controls/pg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
project_id = attribute('project_id')
basename = attribute('name')
authorized_network = attribute('authorized_network')
replicas = attribute('replicas')
instances = attribute('instances')

describe google_sql_database_instances(project: project_id).where(instance_name: /#{basename}/) do
its(:count) { should eq 4 }
its(:count) { should eq 1 + replicas.length }
its(:count) { should eq instances.length }
end

describe google_sql_database_instance(project: project_id, database: basename) do
Expand Down Expand Up @@ -61,6 +65,8 @@
%i[a b c].each_with_index do |zone, index|
name = "#{basename}-replica-test#{index}"
describe google_sql_database_instance(project: project_id, database: name) do
its(:name) { should eq replicas[index]['name'] }

let(:expected_settings) {
{
activation_policy: "ALWAYS",
Expand Down
6 changes: 6 additions & 0 deletions test/integration/postgresql-ha/inspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ attributes:
- name: authorized_network
type: string
required: true
- name: replicas
type: array
required: true
- name: instances
type: array
required: true

0 comments on commit 70205b0

Please sign in to comment.