https://github.com/pratikshinde55/terraform-aws-webserver
Create Webserver using Terraform for AWS provider using multiple subnet
https://github.com/pratikshinde55/terraform-aws-webserver
Last synced: 2 months ago
JSON representation
Create Webserver using Terraform for AWS provider using multiple subnet
- Host: GitHub
- URL: https://github.com/pratikshinde55/terraform-aws-webserver
- Owner: Pratikshinde55
- Created: 2025-01-04T13:09:36.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2025-01-07T13:03:38.000Z (5 months ago)
- Last Synced: 2025-01-21T14:36:15.225Z (4 months ago)
- Language: HCL
- Homepage:
- Size: 25.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Create Webserver using Terraform for AWS provider
## info
**element()** :- function to select one subnet from multiple subnets dynamically.
**subnet_id = element(aws_subnet.ps-subnet.*.id, 0)** --> this place the EC2 instance in the first subnet (count.index = 0), if want place in second then use 1.
**count** --> for dynamically creating multiple subnets
## Code explain:
## Step-1: [ aws_ami Data Source]
**most_recent:** Fetches the latest AMI.
**owners:** Filters defines use onlu amazon .
**filter:** Filters AMIs by name, root device type (ebs), and virtualization type (hvm), which are typical for most Amazon Linux images.
data "aws_ami" "ami-id-ec2" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["al2023-ami-*-x86_64"]
}
filter {
name = "root-device-type"
values = ["ebs"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
}## Step-: [aws_instance Resource]