In this example, the security_groups variable is defined with a type of list(string), and it is given a default value of ["default"]. The AWS provider is then configured to use the us-west-2 region.
The aws_instance resource is used to launch Amazon EC2 instances. The vpc_security_group_ids argument is used to specify the security groups for the instance, and it is set to the value of the security_groups variable.
You can change the value of security_groups by modifying the default value in the variable definition, or you can specify a different value when you run Terraform by using the -var flag. For example, if you want to launch an instance with security groups ["default", "web-security-group"], you can run the following command:
$ terraform apply -var ‘security_groups=[“default”, “web-security-group”]’
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services — all in one place.
Explore Hospitals