I am trying to replicate an aws demo via terraform which I previously did manually within the aws console and it worked fine. I have tried to compare it with code that I have deployed previously where the url also loaded and it seems to match but I am very new to this and simply trying to learn TF.` Once deployed via TF, I am able to use the connect button within the console and it seems to connect just fine but when I ping or enter in a url http://followed by public ip address it says:
Host Not Found DNS error (the host name of the page you are looking for does not exist) or Server did not accept the connection.***
provider "aws" {
region = "us-east-1"
access_key =
secret_key =
}
resource "aws_vpc" "vpclab2" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = "true"
tags = {
name = "vpclab2"
}
}
resource "aws_subnet" "pubsub1" {
vpc_id = aws_vpc.vpclab2.id
cidr_block = "10.0.0.0/24"
availability_zone = "us-east-1b"
map_public_ip_on_launch = true
tags = {
"name" = "pubsub1b"
}
}
resource "aws_subnet" "pubsub2" {
vpc_id = aws_vpc.vpclab2.id
cidr_block = "10.0.1.0/24"
availability_zone = "us-east-1c"
map_public_ip_on_launch = true
tags = {
"name" = "pubsub1c"
}
}
resource "aws_internet_gateway" "iglab2" {
vpc_id = aws_vpc.vpclab2.id
tags = {
"name" = "ig"
}
}
resource "aws_route_table" "rtpubsub1" {
vpc_id = aws_vpc.vpclab2.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.iglab2.id
}
}
resource "aws_route_table_association" "rtsub1" {
subnet_id = aws_subnet.pubsub1.id
route_table_id = aws_route_table.rtpubsub1.id
}
resource "aws_route_table" "rtpubsub2" {
vpc_id = aws_vpc.vpclab2.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.iglab2.id
}
}
resource "aws_route_table_association" "RT-sub2" {
subnet_id = aws_subnet.pubsub2.id
route_table_id = aws_route_table.rtpubsub2.id
}
resource "aws_security_group" "sg" {
name = "allow http"
vpc_id = aws_vpc.vpclab2.id
ingress {
description = "allow http"
from_port = "80"
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
cidr_blocks = [ "0.0.0.0/0" ]
from_port = 0
protocol = "-1"
to_port = 0
}
egress {
cidr_blocks = ["0.0.0.0/0"]
description = "all outbound traf"
from_port = 0
protocol = "-1"
to_port = 0
}
}
resource "aws_instance" "ec2ins" {
ami = "ami-02f3f602d23f1659d"
instance_type = "t2.micro"
subnet_id = aws_subnet.pubsub1.id
availability_zone = "us-east-1b"
associate_public_ip_address = "true"
vpc_security_group_ids = [aws_security_group.sg.id]
user_data = <<-EOF
#!/bin/bash
yum update
yum -y install httpd
chkconfig httpd on
service httpd start
EOF
}
provider "aws" {
region = "us-east-1"
access_key =
secret_key =
}
resource "aws_vpc" "vpclab2" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = "true"
tags = {
name = "vpclab2"
}
resource "aws_subnet" "pubsub1" {
vpc_id = aws_vpc.vpclab2.id
cidr_block = "10.0.0.0/24"
availability_zone = "us-east-1b"
map_public_ip_on_launch = true
tags = {
"name" = "pubsub1b"
}
resource "aws_subnet" "pubsub2" {
vpc_id = aws_vpc.vpclab2.id
cidr_block = "10.0.1.0/24"
availability_zone = "us-east-1c"
map_public_ip_on_launch = true
}
resource "aws_internet_gateway" "iglab2" {
vpc_id = aws_vpc.vpclab2.id
}
resource "aws_route_table" "rtpubsub1" {
vpc_id = aws_vpc.vpclab2.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.iglab2.id
}
resource "aws_route_table_association" "rtsub1" {
subnet_id = aws_subnet.pubsub1.id
route_table_id = aws_route_table.rtpubsub1.id
}
resource "aws_route_table" "rtpubsub2" {
vpc_id = aws_vpc.vpclab2.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.iglab2.id
}
resource "aws_route_table_association" "RT-sub2" {
subnet_id = aws_subnet.pubsub2.id
route_table_id = aws_route_table.rtpubsub2.id
}
resource "aws_security_group" "sg" {
name = "allow http"
vpc_id = aws_vpc.vpclab2.id
ingress {
description = "allow http"
from_port = "80"
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
cidr_blocks = [ "0.0.0.0/0" ]
from_port = 0
protocol = "-1"
to_port = 0
}
egress {
cidr_blocks = ["0.0.0.0/0"]
description = "all outbound traf"
from_port = 0
protocol = "-1"
to_port = 0
}
resource "aws_instance" "ec2ins" {
ami = "ami-02f3f602d23f1659d"
instance_type = "t2.micro"
subnet_id = aws_subnet.pubsub1.id
availability_zone = "us-east-1b"
associate_public_ip_address = "true"
vpc_security_group_ids = [aws_security_group.sg.id]
user_data = <<-EOF
#!/bin/bash
yum update
yum -y install httpd
chkconfig httpd on
service httpd start
EOF
}
}
on it. there are a number of resources like this. if you paste the terraform code you have put in th question into any IDE with a TF parser or run a terraform init you will get a message likeOn main.tf line 75: There is no closing brace for this block before the end of the file. This may be caused by incorrect brace nesting elsewhere in this file.
people are trying to help you but you claim they are wrong. clearly you must know more