Skip to content

Instantly share code, notes, and snippets.

@xynova
Created August 18, 2018 06:53
Show Gist options
  • Save xynova/0ef73fe828e7adfc48e843e2644266f7 to your computer and use it in GitHub Desktop.
Save xynova/0ef73fe828e7adfc48e843e2644266f7 to your computer and use it in GitHub Desktop.
openvpn-launch-config.tf
data "template_file" "ovpn_ext_tpl" {
template = "${file("${path.module}/vm_openvpn.tpl")}"
vars {
tf_r53_zone_id = "${data.aws_route53_zone.openvpn_ext_dns_zone.zone_id}"
tf_r53_fqdn = "${data.aws_route53_zone.openvpn_ext_dns_zone.name}"
tf_rds_fqdn = "${aws_route53_record.openvpn_db.fqdn}"
tf_db_enc = "${var.account_nfo["db_enc_password"]}"
tf_db_prefix = "ext_"
}
}
resource "aws_launch_configuration" "ovpn_ext_launch" {
name_prefix = "${aws_security_group.ovpn_ext_sg.name}-"
image_id = "${var.account_nfo["ami_id_ovpn_ext"]}"
instance_type = "t2.small"
iam_instance_profile = "${data.aws_iam_instance_profile.ovpn_role.name}"
security_groups = [
"${data.aws_security_group.managed.id}",
"${aws_security_group.ovpn_ext_sg.id}",
]
user_data_base64 = "${base64encode(data.template_file.ovpn_ext_tpl.rendered)}"
root_block_device {
volume_size = "30"
volume_type = "gp2"
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_autoscaling_group" "ovpn_ext_asg" {
name = "${aws_security_group.ovpn_ext_sg.name}"
launch_configuration = "${aws_launch_configuration.ovpn_ext_launch.name}"
vpc_zone_identifier = [
"${data.aws_subnet_ids.pub_subnet_ids.ids}",
]
min_size = 1
max_size = 1
tags = [
"${map("key", "App", "value", "OpenVpn", "propagate_at_launch", true)}",
"${map("key", "Name", "value",aws_security_group.ovpn_ext_sg.name, "propagate_at_launch", true)}",
"${map("key", "ProjectRef", "value", local.project_ref, "propagate_at_launch", true)}",
"${map("key", "Role", "value", "EXT", "propagate_at_launch", true)}",
]
lifecycle {
create_before_destroy = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment