From 20f141332c75184d271c137d7b153d3e69a829a8 Mon Sep 17 00:00:00 2001 From: Corey Date: Wed, 13 Sep 2023 13:14:39 -0700 Subject: [PATCH] Update main.tf From https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group#argument-reference "Can be specified multiple times for each [ingress/egress] rule" --- 010_provisioners-cloud-init/main.tf | 104 ++++++++++++++-------------- 1 file changed, 51 insertions(+), 53 deletions(-) diff --git a/010_provisioners-cloud-init/main.tf b/010_provisioners-cloud-init/main.tf index bba05bb..223cdc7 100644 --- a/010_provisioners-cloud-init/main.tf +++ b/010_provisioners-cloud-init/main.tf @@ -1,5 +1,5 @@ terraform { - /* +/* backend "remote" { organization = "ExamPro" @@ -7,7 +7,7 @@ terraform { name = "provisioners" } } - */ +*/ required_providers { aws = { source = "hashicorp/aws" @@ -30,44 +30,40 @@ resource "aws_security_group" "sg_my_server" { description = "MyServer Security Group" vpc_id = data.aws_vpc.main.id - ingress = [ - { - description = "HTTP" - from_port = 80 - to_port = 80 - protocol = "tcp" - cidr_blocks = ["0.0.0.0/0"] - ipv6_cidr_blocks = [] - prefix_list_ids = [] - security_groups = [] - self = false - }, - { - description = "SSH" - from_port = 22 - to_port = 22 - protocol = "tcp" - cidr_blocks = ["104.194.51.113/32"] - ipv6_cidr_blocks = [] - prefix_list_ids = [] - security_groups = [] - self = false - } - ] + ingress { + description = "HTTP" + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + ipv6_cidr_blocks = [] + prefix_list_ids = [] + security_groups = [] + self = false + } + ingress { + description = "SSH" + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["104.194.51.113/32"] + ipv6_cidr_blocks = [] + prefix_list_ids = [] + security_groups = [] + self = false + } - egress = [ - { - description = "outgoing traffic" - from_port = 0 - to_port = 0 - protocol = "-1" - cidr_blocks = ["0.0.0.0/0"] - ipv6_cidr_blocks = ["::/0"] - prefix_list_ids = [] - security_groups = [] - self = false - } - ] + egress { + description = "outgoing traffic" + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + ipv6_cidr_blocks = ["::/0"] + prefix_list_ids = [] + security_groups = [] + self = false + } } resource "aws_key_pair" "deployer" { @@ -76,25 +72,27 @@ resource "aws_key_pair" "deployer" { } data "template_file" "user_data" { - template = file("./userdata.yaml") + template = file("./userdata.yaml") } resource "aws_instance" "my_server" { - ami = "ami-087c17d1fe0178315" - instance_type = "t2.micro" - key_name = "${aws_key_pair.deployer.key_name}" - vpc_security_group_ids = [aws_security_group.sg_my_server.id] - user_data = data.template_file.user_data.rendered + ami = "ami-087c17d1fe0178315" + instance_type = "t2.micro" + key_name = "${aws_key_pair.deployer.key_name}" + vpc_security_group_ids = [aws_security_group.sg_my_server.id] + user_data = data.template_file.user_data.rendered + provisioner "file" { content = "mars" destination = "/home/ec2-user/barsoon.txt" - connection { - type = "ssh" - user = "ec2-user" - host = "${self.public_ip}" - private_key = "${file("/root/.ssh/terraform")}" - } + + connection { + type = "ssh" + user = "ec2-user" + host = "${self.public_ip}" + private_key = "${file("/root/.ssh/terraform")}" + } } tags = { @@ -103,5 +101,5 @@ resource "aws_instance" "my_server" { } output "public_ip"{ - value = aws_instance.my_server.public_ip -} \ No newline at end of file + value = aws_instance.my_server.public_ip +}