Skip to content

Instantly share code, notes, and snippets.

@dalethestirling
Created September 10, 2017 22:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dalethestirling/ce4b61d4b3e1f9c5007920d32f57d8ae to your computer and use it in GitHub Desktop.
Save dalethestirling/ce4b61d4b3e1f9c5007920d32f57d8ae to your computer and use it in GitHub Desktop.
Using provisioner for RDS password generation
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