QT-DevOps / AWSIssues

Issues with AWS
Apache License 2.0
3 stars 26 forks source link

Terraform issue while trying to create EC2 machine with mentioned script , attaching scripts #41

Closed kishoregudidha closed 4 years ago

kishoregudidha commented 5 years ago

resource "aws_vpc" "First" { cidr_block = "10.10.0.0/16" enable_dns_hostnames = true tags = { Name = "First Lab" } } resource "aws_subnet" "First" { vpc_id = "${aws_vpc.First.id}" availability_zone = "${var.subnetaz1}" cidr_block = "10.10.0.0/24"

tags = { Name = "First Lab" } }

resource "aws_subnet" "second" { vpc_id = "${aws_vpc.First.id}" cidr_block = "10.10.1.0/24" availability_zone = "${var.subnetaz2}" tags = { Name = "First Lab" } } resource "aws_internet_gateway" "First"{ vpc_id = "${aws_vpc.First.id}" tags = { Name = "First Lab" } } resource "aws_route_table" "first"{ vpc_id = "${aws_vpc.First.id}" route { cidr_block = "0.0.0.0/0" gateway_id = "${aws_internet_gateway.First.id}" } tags = { Name = "first Lab"
} }

resource "aws_route_table_association" "firsttest" { subnet_id = "${aws_subnet.First.id}" route_table_id = "${aws_route_table.first.id}"

}

resource "aws_route_table_association" "secondtest" { subnet_id = "${aws_subnet.second.id}" route_table_id = "${aws_route_table.first.id}"

} resource "aws_security_group" "firstgroup" { name = "first group" description = "awssecutity group by terraform" vpc_id = "${aws_vpc.First.id}" ingress { cidr_blocks = ["0.0.0.0/0"] from_port = "0" to_port = "0" protocol = "-1" } egress { cidr_blocks = ["0.0.0.0/0"] from_port = "0" to_port = "0" protocol = "-1" } tags ={ Name = "First Lab" } } resource "aws_instance" "firstinstance" { ami = "${var.appserverami}" subnet_id = "${aws_subnet.First.id}" instance_type = "t2.micro" vpc_security_group_ids = [ "${aws_security_group.firstgroup.id}" ] key_name = "${var.awskeypair}" associate_public_ip_address = true tags = { Name = "Firstin TF" }

connection {
  type = "ssh"
  user = "${var.sshusername}"
  private_key = "${file(var.sshkeypath)}"
  host = "${aws_instance.firstinstance.public_ip}"
}
 provisioner "remote_exec" {
   inline = [
     "sudo apt-get update",
     "sudo apt-get install  openjdk-8-jdk -y",
     "sudo apt-get install tomcat8 -y"
   ]
 }

} resource "aws_instance" "secondinstance" { ami = "${var.appserverami}" subnet_id = "${aws_subnet.second.id}" instance_type = "t2.micro" vpc_security_group_ids = [ "${aws_security_group.firstgroup.id}" ] key_name = "${var.awskeypair}" associate_public_ip_address = true tags = { Name = "Secondins TF" }

  connection {
  type = "ssh"
  user = "${var.sshusername}"
  private_key = "${file(var.sshkeypath)}"
  host = "${aws_instance.secondinstance.public_ip}"
}
 provisioner "remote_exec" {
   inline = [
     "sudo apt-get update",
     "sudo apt-get install  openjdk-8-jdk -y",
     "sudo apt-get install tomcat8 -y"
   ]
 }

}

lakshmivennapusa commented 5 years ago

write and execute the code step by step then u will get to know the error .

ghost commented 5 years ago

please share logs also