1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- {% import 'variables.include' as var %}
- ###################
- # Web Server Instance
- resource "aws_instance" "webserver" {
- ami = "${data.aws_ami.ubuntu.id}"
- instance_type = "${var.Instance-Type}"
- availability_zone = "${data.aws_availability_zones.available.names[0]}"
- subnet_id = "${aws_subnet.subnet_public_a.id}"
- ebs_optimized = "${var.EBS-Optimized}"
- disable_api_termination = false
- associate_public_ip_address = true
- instance_initiated_shutdown_behavior = "terminate"
- key_name = "${var.AWS-Key-Pair-Name}"
- vpc_security_group_ids = ["${aws_security_group.sg_instance_access.id}"]
- depends_on = ["aws_internet_gateway.gw_primary"]
- tags {
- Name = "webserver"
- }
- root_block_device {
- volume_type = "standard"
- volume_size = "{{ var.Web_Volume_Size }}" # Gigabytes
- delete_on_termination = true
- }
- ebs_block_device {
- device_name = "/dev/sdd"
- volume_size = "${var.Swap-Volume-Size}"
- volume_type = "${var.Swap-Volume-Type}"
- delete_on_termination = true
- }
- user_data = <<EOF
- #cloud-config
- runcmd:
- - [ mkswap, /dev/xvdd ]
- - [ swapon, -a ]
- mounts:
- - [ xvdd, none, swap, sw, 0, 0 ]
- EOF
- # Fix issues with cached keys. Arguably less secure, but also way less annoying
- provisioner "local-exec" {
- command = "ssh-keygen -f ~/.ssh/known_hosts -R webserver.lab.${var.Domain-Name}"
- }
- }
- # Give me the IP Addresses
- output "webserver_ip" {
- value = "${aws_instance.webserver.public_ip}"
- }
- # Give me DNS entries
- resource "aws_route53_record" "webserver" {
- zone_id = "${var.Domain-Zone-ID}"
- name = "webserver.lab.${var.Domain-Name}"
- type = "A"
- ttl = "300"
- records = ["${aws_instance.webserver.public_ip}"]
- }
- resource "aws_route53_record" "webserver_pvt" {
- zone_id = "${var.Domain-Zone-ID}"
- name = "webserver_pvt.lab.${var.Domain-Name}"
- type = "A"
- ttl = "300"
- records = ["${aws_instance.webserver.private_ip}"]
- }
- output "webserver_dns" {
- value = "${aws_route53_record.webserver.name}"
- }
|