Created
July 24, 2019 21:59
-
-
Save HebertCL/082d744756cccdf195eb20d2244ffa42 to your computer and use it in GitHub Desktop.
Terraform config file provisioning SQL instance, Database and user
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
terraform { | |
required_version = ">=0.12.0" | |
} | |
provider "google" { | |
credentials = "${file("${var.gcp_credentials}")}" | |
project = var.gcp_project | |
region = var.gcp_region | |
} | |
resource "random_pet" "grafana_db" {} | |
resource "google_sql_database_instance" "gcp_sql_db_instance" { | |
name = random_pet.grafana_db.id | |
database_version = var.gcp_db_instance_version | |
settings { | |
tier = var.gcp_db_instance_tier | |
ip_configuration { | |
ipv4_enabled = var.gcp_db_instance_ipv4_enabled | |
dynamic "authorized_networks" { | |
for_each = var.gcp_db_instance_authorized_networks | |
content { | |
name = authorized_networks.key | |
value = authorized_networks.value | |
} | |
} | |
private_network = var.gcp_db_instance_private_network | |
} | |
} | |
} | |
resource "google_sql_database" "gcp_sql_database" { | |
name = var.gcp_sql_database_name | |
instance = google_sql_database_instance.gcp_sql_db_instance.self_link | |
} | |
resource "google_sql_user" "gcp_sql_user" { | |
instance = google_sql_database_instance.gcp_sql_db_instance.name | |
name = var.gcp_sql_user_name | |
password = base64encode(var.gcp_sql_user_password) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment