Terraform : AWS : Terraform on AWS | Section :5 Terraform Loops, Meta Arguments, Splat
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33. Step-01: Implement Variable Lists, Maps and also Meta-Argument
No changes to c1-version.tf
c2-variables.tf
We are going to define an instance type whos instance type is going to be list
# AWS EC2 Instance Type - List variable "instance_type_list" { description = "EC2 Instnace Type" type = list(string) default = ["t3.micro", "t3.small"] } # AWS EC2 Instance Type - Map variable "instance_type_map" { description = "EC2 Instnace Type" type = map(string) default = { "dev" = "t3.micro" "qa" = "t3.small" "prod" = "t3.large" } }
---
Step-04: c3-ec2securitygroups.tf and c4-ami-datasource.tf
- No changes to both files
https://github.com/stacksimplify/terraform-on-aws-ec2/tree/main/05-Terraform-Loops-MetaArguments-SplatOperator/05-01-MetaArgument-Count-For-Loops-Lists-Maps
Go to ec2-instance.tf
Here you are going to say which value you want , refer from the list variable to add it here.
default = [0, 1] -- here the values are going to be so as give here as if in index
Count is nothing but a Meta-Aurgument , which is not your original resource parameter , but is a resource parameter of your AWS instance .
There are some additional Meta-Arugements present in out of which "Count" , "for_each" these can be used to change the behavior of your resource . one of them is Count
count = 5 -- which will create 5 instances of aws instances
Comments
Post a Comment