Created
September 9, 2019 02:53
-
-
Save Bharathkumarraju/49e3501ca9a191b1ea23467293b40aa2 to your computer and use it in GitHub Desktop.
Terraform - Create database password securely and store in remote-state
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
provider "aws" { | |
region = var.aws_region | |
profile = var.aws_profile | |
} | |
terraform { | |
backend "s3" { | |
bucket = "bharaths-terraform-up-and-running" | |
key = "development/data-stores/mysql/terraform.tfstate" | |
region = "us-east-2" | |
dynamodb_table = "bharaths-terraform-up-and-running-locks" | |
encrypt = true | |
} | |
} | |
resource "random_string" "db_password" { | |
length = 16 | |
special = true | |
override_special = "!#()-[]<>" | |
} | |
resource "aws_db_instance" "bharaths_mysql" { | |
instance_class = "db.t2.micro" | |
identifier_prefix = "bharaths-terraform-up-and-running" | |
engine = "mysql" | |
allocated_storage = 10 | |
name = "bharaths_example_database" | |
username = "bharath_admin" | |
skip_final_snapshot = true | |
apply_immediately = true | |
password = random_string.db_password.result | |
lifecycle { | |
ignore_changes = ["password"] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment