-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add SQL Server support with new submodule (#112)
Co-authored-by: Andriy Kopachevskyy <kopachevsky@gmail.com> Co-authored-by: Morgante Pell <morgantep@google.com>
- Loading branch information
1 parent
d433995
commit 4a775fb
Showing
28 changed files
with
1,334 additions
and
122 deletions.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,44 @@ | ||
# Cloud MS SQL Server database Example | ||
|
||
This example shows how create MS SQL Server database using the Terraform module. | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|:----:|:-----:|:-----:| | ||
| name | The name for Cloud SQL instance | string | `"tf-mssql-public"` | no | | ||
| project\_id | The project to run tests against | string | n/a | yes | | ||
| region | | string | `"us-central1"` | no | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| instance\_name | | | ||
| mssql\_connection | The connection name of the master instance to be used in connection strings | | ||
| project\_id | | | ||
| public\_ip\_address | Public ip address | | ||
|
||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
|
||
## Run Terraform | ||
|
||
``` | ||
terraform init | ||
terraform plan | ||
terraform apply | ||
``` | ||
|
||
## Test connection to database | ||
|
||
```bash | ||
gcloud sql connect $(terraform output instance_name) --user=simpleuser | ||
``` | ||
## Cleanup | ||
|
||
Remove all resources created by terraform: | ||
|
||
```bash | ||
terraform destroy | ||
``` |
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 @@ | ||
/** | ||
* 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-beta" { | ||
version = "~> 3.1.0" | ||
region = var.region | ||
} | ||
|
||
resource "random_id" "instance_name_suffix" { | ||
byte_length = 5 | ||
} | ||
|
||
locals { | ||
/* | ||
Random instance name needed because: | ||
"You cannot reuse an instance name for up to a week after you have deleted an instance." | ||
See https://cloud.google.com/sql/docs/mysql/delete-instance for details. | ||
*/ | ||
instance_name = "${var.name}-${random_id.instance_name_suffix.hex}" | ||
} | ||
|
||
module "mssql" { | ||
source = "../../modules/mssql" | ||
name = local.instance_name | ||
project_id = var.project_id | ||
user_name = "simpleuser" | ||
user_password = "foobar" | ||
} |
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,33 @@ | ||
/** | ||
* 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 | ||
} | ||
|
||
output "instance_name" { | ||
value = local.instance_name | ||
} | ||
|
||
output "mssql_connection" { | ||
value = module.mssql.instance_connection_name | ||
description = "The connection name of the master instance to be used in connection strings" | ||
} | ||
|
||
output "public_ip_address" { | ||
value = module.mssql.instance_first_ip_address | ||
description = "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,31 @@ | ||
/** | ||
* 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" { | ||
type = string | ||
description = "The project to run tests against" | ||
} | ||
|
||
variable "name" { | ||
type = string | ||
description = "The name for Cloud SQL instance" | ||
default = "tf-mssql-public" | ||
} | ||
|
||
variable "region" { | ||
default = "us-central1" | ||
type = string | ||
} |
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" | ||
} |
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,59 @@ | ||
# terraform-google-sql for MSSQL Server | ||
|
||
The following dependency must be available for SQL Server module: | ||
|
||
- [Terraform Provider Beta for GCP](https://github.com/terraform-providers/terraform-provider-google-beta) plugin v3.10 | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|:----:|:-----:|:-----:| | ||
| activation\_policy | The activation policy for the master instance.Can be either `ALWAYS`, `NEVER` or `ON_DEMAND`. | string | `"ALWAYS"` | no | | ||
| additional\_databases | A list of databases to be created in your cluster | object | `<list>` | no | | ||
| additional\_users | A list of users to be created in your cluster | object | `<list>` | no | | ||
| authorized\_gae\_applications | The authorized gae applications for the Cloud SQL instances | list(string) | `<list>` | no | | ||
| availability\_type | The availability type for the master instance.This is only used to set up high availability for the MSSQL instance. Can be either `ZONAL` or `REGIONAL`. | string | `"ZONAL"` | no | | ||
| create\_timeout | The optional timout that is applied to limit long database creates. | string | `"15m"` | no | | ||
| database\_flags | The database flags for the master instance. See [more details](https://cloud.google.com/sql/docs/sqlserver/flags) | object | `<list>` | no | | ||
| database\_version | The database version to use: SQLSERVER_2017_STANDARD, SQLSERVER_2017_ENTERPRISE, SQLSERVER_2017_EXPRESS, or SQLSERVER_2017_WEB | string | `"SQLSERVER_2017_STANDARD"` | no | | ||
| db\_charset | The charset for the default database | string | `""` | no | | ||
| db\_collation | The collation for the default database. Example: 'en_US.UTF8' | string | `""` | no | | ||
| db\_name | The name of the default database to create | string | `"default"` | no | | ||
| delete\_timeout | The optional timout that is applied to limit long database deletes. | string | `"30m"` | no | | ||
| disk\_autoresize | Configuration to increase storage size. | bool | `"true"` | no | | ||
| disk\_size | The disk size for the master instance. | string | `"10"` | no | | ||
| disk\_type | The disk type for the master instance. | string | `"PD_SSD"` | no | | ||
| ip\_configuration | The ip configuration for the master instances. | object | `<map>` | no | | ||
| maintenance\_window\_day | The day of week (1-7) for the master instance maintenance. | number | `"1"` | no | | ||
| maintenance\_window\_hour | The hour of day (0-23) maintenance window for the master instance maintenance. | number | `"23"` | no | | ||
| maintenance\_window\_update\_track | The update track of maintenance window for the master instance maintenance.Can be either `canary` or `stable`. | string | `"canary"` | no | | ||
| name | The name of the Cloud SQL resources | string | n/a | yes | | ||
| peering\_completed | Optional. This is used to ensure that resources are created in the proper order when using private IPs and service network peering. | string | `""` | no | | ||
| pricing\_plan | The pricing plan for the master instance. | string | `"PER_USE"` | no | | ||
| project\_id | The project ID to manage the Cloud SQL resources | string | n/a | yes | | ||
| region | The region of the Cloud SQL resources | string | `"us-central1"` | no | | ||
| 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. | string | `""` | no | | ||
| tier | The tier for the master instance. | string | `"db-custom-2-3840"` | no | | ||
| update\_timeout | The optional timout that is applied to limit long database updates. | string | `"15m"` | no | | ||
| user\_labels | The key/value labels for the master instances. | map(string) | `<map>` | no | | ||
| user\_name | The name of the default user | string | `"default"` | no | | ||
| user\_password | The password for the default user. If not set, a random one will be generated and available in the generated_user_password output variable. | string | `""` | no | | ||
| zone | The zone for the master instance. | string | `"us-central1-a"` | no | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| generated\_user\_password | The auto generated default user password if not input password was provided | | ||
| instance\_address | The IPv4 addesses assigned for the master instance | | ||
| instance\_connection\_name | The connection name of the master instance to be used in connection strings | | ||
| instance\_first\_ip\_address | The first IPv4 address of the addresses assigned. | | ||
| instance\_name | The instance name for the master instance | | ||
| 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 | | ||
| 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. | | ||
|
||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
Oops, something went wrong.