forked from rahulwagh/Terraform-Topics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
48 lines (39 loc) · 982 Bytes
/
main.tf
File metadata and controls
48 lines (39 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
provider "aws" {
region = "eu-central-1"
shared_credentials_files = ["/Users/rahulwagh/.aws/credentials"]
}
resource "aws_instance" "ec2_example" {
ami = "ami-0767046d1677be5a0"
instance_type = "t2.micro"
count = 1
tags = {
Name = "Terraform EC2"
}
}
locals {
ingress_rules = [{
port = 443
description = "Ingress rules for port 443"
},
{
port = 80
description = "Ingree rules for port 80"
}]
}
resource "aws_security_group" "main" {
name = "resource_with_dynamic_block"
vpc_id = data.aws_vpc.main.id
dynamic "ingress" {
for_each = local.ingress_rules
content {
description = ingress.value.description
from_port = ingress.value.port
to_port = ingress.value.port
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
tags = {
Name = "AWS security group dynamic block"
}
}