data "template_file" "user_data" { template = file("launch-data.tpl") vars = { db_username = var.db_username db_user_password = var.db_password db_name = var.db_name db_URL = aws_db_instance.wp-db-instance.endpoint } } resource "aws_launch_template" "server" { name_prefix = "server" image_id = "ami-0557a15b87f6559cf" instance_type = var.server_instance_type network_interfaces { security_groups = [ "${aws_security_group.server_sg.id}" ] associate_public_ip_address = true } user_data = data.template_file.user_data.rendered lifecycle { create_before_destroy = true } depends_on = [aws_db_instance.wp-db-instance] }