Hi All, I am a newbie with the terraform. I keep getting the block definition error for line item 39 but there is no statement in line item 39. Please see the code and let me know what i am missing. Thank you in advance.
resource "aws_vpc" "fcloud"{
cidr_block = "10.10.0.0/16"
instance_tenancy = "default"
tags = {
Name = "fcloud"
}
resource "aws_subnet" "public_subnet"{
count = "${length(var.public_subnet_cidr_block)}"
vpc_id = "${aws_vpc.fcloud.id}"
cidr_block = "${element(var.public_subnet_cidr_block, count.index)}"
availability_zone = "${element(var.availability_zones, count.index)}"
tags = {
Name = "public_subnet_${count.index}"
}
resource "aws_subnet" "private_subnet"{
count = "${length(var.private_subnet_cidr_block)}"
vpc_id = "${aws_vpc.fcloud.id}"
cidr_block = "${element(var.private_subnet_cidr_block, count.index)}"
availability_zone = "${element(var.availability_zones, count.index)}"
tags = {
Name = "private_subnet_${count.index}"
}
resource "aws_subnet" "hr_subnet"{
count = "${length(var.hr_subnet_cidr_block)}"
vpc_id = "${aws_vpc.fcloud.id}"
cidr_block = "${element(var.hr_subnet_cidr_block, count.index)}"
availability_zone = "${element(var.availability_zones, count.index)}"
tags ={
Name = "hr_subnet_${count.index}"
}
Hi @razee1984,
not sure if this is just a copy / paste error however your resources lack ending bracket }
.
You might want to use an editor which supports tracking of such.
1 Like
hi i did add the ending bracket but i still get the same error for the last line when i execute terraform init command.
Did you check the brackets on all of your code?
yes even re-wrote it several times. can’t seem to figure out what’s wrong with it.
could you repost your code an format it properly in triple back-ticks?
no brackets required here:
vpc_id = aws_vpc.fcloud.id
While reformatting your code, I noticed that there were additional quoting characters, etc…
resource "aws_vpc" "fcloud" {
cidr_block = "10.10.0.0/16"
instance_tenancy = "default"
tags = {
Name = "fcloud"
}
}
resource "aws_subnet" "public_subnet" {
count = length(var.publicsubnetcidrblock)
vpc_id = aws_vpc.fcloud.id
cidr_block = element(var.publicsubnetcidrblock, count.index)
availability_zone = element(var.availability_zones, count.index)
tags = {
Name = "public_subnet_${count.index}"
}
}
resource "aws_subnet" "private_subnet" {
count = length(var.privatesubnetcidrblock)
vpc_id = aws_vpc.fcloud.id
cidr_block = element(var.privatesubnetcidrblock, count.index)
availability_zone = element(var.availability_zones, count.index)
tags = {
Name = "private_subnet_${count.index}"
}
}
resource "aws_subnet" "hr_subnet" {
count = length(var.hrsubnetcidrblock)
vpc_id = aws_vpc.fcloud.id
cidr_block = element(var.hrsubnetcidrblock, count.index)
availability_zone = element(var.availability_zones, count.index)
tags = {
Name = "hr_subnet_${count.index}"
}
}