-
Notifications
You must be signed in to change notification settings - Fork 151
/
Copy pathprivatelink.tf
125 lines (113 loc) · 3.48 KB
/
privatelink.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// VPC Endpoints
/*
module "vpc_endpoints" {
source = "terraform-aws-modules/vpc/aws//modules/vpc-endpoints"
version = "3.11.0"
vpc_id = aws_vpc.mainvpc.id
security_group_ids = [aws_security_group.sg.id]
endpoints = {
s3 = {
count = length(local.private_subnets_cidr)
service = "s3"
service_type = "Gateway"
route_table_ids = flatten([
aws_route_table.private_rt[*].id
])
tags = {
Name = "${local.prefix}-s3-vpc-endpoint"
}
},
sts = {
service = "sts"
private_dns_enabled = true
subnet_ids = aws_subnet.private[*].id
tags = {
Name = "${local.prefix}-sts-vpc-endpoint"
}
},
kinesis-streams = {
service = "kinesis-streams"
private_dns_enabled = true
subnet_ids = aws_subnet.private[*].id
tags = {
Name = "${local.prefix}-kinesis-vpc-endpoint"
}
}
}
}
*/
resource "aws_security_group" "privatelink" {
vpc_id = aws_vpc.mainvpc.id
ingress {
description = "Inbound rules"
from_port = 443
to_port = 443
protocol = "tcp"
security_groups = [aws_security_group.sg.id]
}
ingress {
description = "Inbound rules"
from_port = 6666
to_port = 6666
protocol = "tcp"
security_groups = [aws_security_group.sg.id]
}
egress {
description = "Outbound rules"
from_port = 443
to_port = 443
protocol = "tcp"
security_groups = [aws_security_group.sg.id]
}
egress {
description = "Outbound rules"
from_port = 6666
to_port = 6666
protocol = "tcp"
security_groups = [aws_security_group.sg.id]
}
tags = {
Name = "${local.prefix}-privatelink-sg"
}
}
resource "aws_vpc_endpoint" "backend_rest" {
vpc_id = aws_vpc.mainvpc.id
service_name = var.workspace_vpce_service
vpc_endpoint_type = "Interface"
security_group_ids = [aws_security_group.privatelink.id]
subnet_ids = aws_subnet.privatelink[*].id
private_dns_enabled = true // try to directly set this to true in the first apply
depends_on = [aws_subnet.privatelink]
tags = {
Name = "${local.prefix}-databricks-backend-rest"
}
}
resource "aws_vpc_endpoint" "backend_relay" {
vpc_id = aws_vpc.mainvpc.id
service_name = var.relay_vpce_service
vpc_endpoint_type = "Interface"
security_group_ids = [aws_security_group.privatelink.id]
subnet_ids = aws_subnet.privatelink[*].id
private_dns_enabled = true
depends_on = [aws_subnet.privatelink]
tags = {
Name = "${local.prefix}-databricks-backend-relay"
}
}
// from official guide
resource "databricks_mws_vpc_endpoint" "backend_rest_vpce" {
provider = databricks.mws
account_id = var.databricks_account_id
aws_vpc_endpoint_id = aws_vpc_endpoint.backend_rest.id
vpc_endpoint_name = "${local.prefix}-vpc-backend-${aws_vpc.mainvpc.id}"
region = var.region
depends_on = [aws_vpc_endpoint.backend_rest]
}
resource "databricks_mws_vpc_endpoint" "relay" {
provider = databricks.mws
account_id = var.databricks_account_id
aws_vpc_endpoint_id = aws_vpc_endpoint.backend_relay.id
vpc_endpoint_name = "${local.prefix}-vpc-relay-${aws_vpc.mainvpc.id}"
region = var.region
depends_on = [aws_vpc_endpoint.backend_relay]
}