diff --git a/ami-list.md b/ami-list.md index fbffb72..2b400a0 100644 --- a/ami-list.md +++ b/ami-list.md @@ -1,4 +1,5 @@ ## Amazon AMIs +### Region: us-east-2 | Image name |Architecture| AMI ID | |---------------------|------------|---------------------| diff --git a/chapterone/main.tf.basics b/chapterone/main.tf.basics new file mode 100644 index 0000000..92e1de6 --- /dev/null +++ b/chapterone/main.tf.basics @@ -0,0 +1,32 @@ +provider "aws" { + region = "us-east-2" +} + +resource "aws_instance" "cloudbuntu" { + ami = "ami-0862be96e41dcbf74" + instance_type = "t2.micro" + vpc_security_group_ids = [aws_security_group.cloudwall.id] + + user_data = <<-EOF + #!/bin/bash + echo "Hello, World! I'm $(hostname)!" > index.html + nohup busybox httpd -f -p 8080 & + EOF + + user_data_replace_on_change = true + + tags = { + Name = "terraform-example" + } +} + +resource "aws_security_group" "cloudwall" { + name = "terraform-example.instance" + + ingress { + from_port = 8080 + to_port = 8080 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } +} diff --git a/chapterone/main.tf.variables b/chapterone/main.tf.variables new file mode 100644 index 0000000..68de357 --- /dev/null +++ b/chapterone/main.tf.variables @@ -0,0 +1,43 @@ +variable "http_port" { + description = "Port to listen for HTTP requests on" + default = 8080 + type = number +} + +output "public_ip" { + value = aws_instance.cloudbuntu.public_ip + description = "The public IP of our new cloudbuntu!" +} + +provider "aws" { + region = "us-east-2" +} + +resource "aws_instance" "cloudbuntu" { + ami = "ami-0862be96e41dcbf74" + instance_type = "t2.micro" + vpc_security_group_ids = [aws_security_group.cloudwall.id] + + user_data = <<-EOF + #!/bin/bash + echo "Hello, World! I'm $(hostname)!" > index.html + nohup busybox httpd -f -p ${var.http_port} & + EOF + + user_data_replace_on_change = true + + tags = { + Name = "terraform-example" + } +} + +resource "aws_security_group" "cloudwall" { + name = "terraform-example.instance" + + ingress { + from_port = var.http_port + to_port = var.http_port + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } +}