Created
September 10, 2017 22:41
-
-
Save dalethestirling/ce4b61d4b3e1f9c5007920d32f57d8ae to your computer and use it in GitHub Desktop.
Using provisioner for RDS password generation
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
resource "aws_db_instance" "postgres" { | |
identifier = "${var.postgres_id}" | |
name = "${var.postgres_name}" | |
engine = "${var.postgres_engine}" | |
engine_version = "${var.postgres_version}" | |
multi_az = "${var.postgres_multi_az}" | |
instance_class = "${var.postgres_class}" | |
db_subnet_group_name = "${var.postgres_subnet_group}" | |
username = "${var.postgres_username}" | |
password = "temporaryPasswordOverriddenBelowOnFirstApply" | |
provisioner "local-exec" { | |
command = "bash -c 'DBPASS=$$(openssl rand -base64 16) && echo $${DBPASS} >> ${self.id}.passwd && aws --region ${var.provider_settings["region"]} rds modify-db-instance --db-instance-identifier ${self.id} --master-user-password $${DBPASS} --apply-immediately'" | |
} | |
storage_type = "${var.postgres_storage_type}" | |
allocated_storage = "${var.postgres_storage_capacity}" | |
vpc_security_group_ids = ["${aws_security_group.postgres_security_group.id}"] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment