Skip to content

Push #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Update README.md
  • Loading branch information
pavankumar636 authored Nov 9, 2021
commit 58d57ff1e9608d085aaa7db145eac01fee444e37
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,26 @@ resource "aws_instance" "myec2vm" {
user_data = file("${path.module}/app1-install.sh")
key_name = var.instance_keypair
vpc_security_group_ids = [ aws_security_group.vpc-ssh.id, aws_security_group.vpc-web.id ]
# Create EC2 Instance in all Availabilty Zones of a VPC
for_each = toset(data.aws_availability_zones.my_azones.names) #toset: converts list into set, In set, removes duplicates,
changes either string or int to highest number of arguments form ( if more strings are present in the list,
it will convert number as well to string; arranges in order.
availability_zone = each.key # You can also use each.value because for list items each.key == each.value

# Create EC2 Instance in all Availabilty Zones of a VPC

for_each = toset(data.aws_availability_zones.my_azones.names)

#toset: converts list into set, In set, removes duplicates,
#changes either string or int to highest number of arguments form ( if more strings are present in the list,
#it will convert number as well to string; arranges in order.

availability_zone = each.key # You can also use each.value because for list items each.key == each.value

tags = {
"Name" = "For-Each-Demo-${each.key}"
}
}

#output: Will create instances in each availability zones and with name tag given and each.key, for every instance it will have name as, For-Each-Demo-ap-south-1, For-Each-Demo-ap-south-2....
#Note: Both meta-arguments cannot be used in one resource block, if for_each is used then count or any other meta-argument cannot be used.


```

## Step-04: c6-outputs.tf
Expand Down