-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpc.tf
58 lines (51 loc) · 2.04 KB
/
vpc.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
# see https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws
# see https://github.com/terraform-aws-modules/terraform-aws-vpc
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "5.8.1"
name = var.name_prefix
azs = ["${var.region}a", "${var.region}b"]
cidr = "10.0.0.0/16"
public_subnets = ["10.0.10.0/24", "10.0.11.0/24"]
private_subnets = ["10.0.20.0/24", "10.0.21.0/24"]
database_subnets = ["10.0.30.0/24", "10.0.31.0/24"]
intra_subnets = ["10.0.40.0/24", "10.0.41.0/24"]
}
# see https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws/latest/submodules/vpc-endpoints
# see https://github.com/terraform-aws-modules/terraform-aws-vpc/blob/master/modules/vpc-endpoints
module "vpc_endpoints" {
source = "terraform-aws-modules/vpc/aws//modules/vpc-endpoints"
version = "5.8.1"
vpc_id = module.vpc.vpc_id
endpoints = {
secretsmanager = {
service = "secretsmanager"
private_dns_enabled = true
security_group_ids = [aws_security_group.aws_secretsmanager.id]
subnet_ids = module.vpc.intra_subnets
tags = {
Name = "${var.name_prefix}-aws-secretsmanager"
}
}
}
}
# see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group
resource "aws_security_group" "aws_secretsmanager" {
vpc_id = module.vpc.vpc_id
name = "aws-secretsmanager"
tags = {
Name = "${var.name_prefix}-aws-secretsmanager"
}
}
# see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_security_group_ingress_rule
resource "aws_vpc_security_group_ingress_rule" "aws_secretsmanager_intra" {
for_each = { for i, cidr_block in module.vpc.intra_subnets_cidr_blocks : module.vpc.azs[i] => cidr_block }
security_group_id = aws_security_group.aws_secretsmanager.id
cidr_ipv4 = each.value
ip_protocol = "tcp"
from_port = 443
to_port = 443
tags = {
Name = "${var.name_prefix}-aws-secretsmanager-intra-${each.key}"
}
}