-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathdata.tf
102 lines (89 loc) · 2.05 KB
/
data.tf
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Get account and region info
data "aws_caller_identity" "this" {
provider = aws.this
}
data "aws_region" "this" {
provider = aws.this
}
data "aws_caller_identity" "peer" {
provider = aws.peer
}
data "aws_region" "peer" {
provider = aws.peer
}
# Get vpc info
data "aws_vpc" "this_vpc" {
provider = aws.this
id = var.this_vpc_id
}
data "aws_vpc" "peer_vpc" {
provider = aws.peer
id = var.peer_vpc_id
}
# get subnets info
data "aws_subnet" "this" {
count = length(var.this_subnets_ids)
provider = aws.this
id = var.this_subnets_ids[count.index]
}
data "aws_subnet" "peer" {
count = length(var.peer_subnets_ids)
provider = aws.peer
id = var.peer_subnets_ids[count.index]
}
# Get subnets and route tables from this
# this vpc main route table
data "aws_route_table" "this_main_route_table" {
provider = aws.this
vpc_id = var.this_vpc_id
filter {
name = "association.main"
values = ["true"]
}
}
# this subnets
data "aws_subnets" "this" {
provider = aws.this
filter {
name = "vpc-id"
values = [var.this_vpc_id]
}
}
# get route tables associated with subnets
data "aws_route_tables" "this_associated_route_tables" {
for_each = { for subnet in data.aws_subnets.this.ids : subnet => subnet }
provider = aws.this
vpc_id = var.this_vpc_id
filter {
name = "association.subnet-id"
values = [each.key]
}
}
# Get subnets and route tables from peer
# peer vpc main route table
data "aws_route_table" "peer_main_route_table" {
provider = aws.peer
vpc_id = var.peer_vpc_id
filter {
name = "association.main"
values = ["true"]
}
}
# peer subnets
data "aws_subnets" "peer" {
provider = aws.peer
filter {
name = "vpc-id"
values = [var.peer_vpc_id]
}
}
# get route tables associated with subnets
data "aws_route_tables" "peer_associated_route_tables" {
for_each = { for subnet in data.aws_subnets.peer.ids : subnet => subnet }
provider = aws.peer
vpc_id = var.peer_vpc_id
filter {
name = "association.subnet-id"
values = [each.key]
}
}