Skip to content

Commit 0151cf3

Browse files
authored
Merge pull request #8 from 3scale-ops/fix/worker-security-group
Make creation of Vault's AppRole optional
2 parents 79c972b + 605954a commit 0151cf3

File tree

5 files changed

+36
-129
lines changed

5 files changed

+36
-129
lines changed

hosted-cluster.tf

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ data "template_file" "helm_values" {
3939
"worker_autoscaling" : var.worker_autoscaling
4040
"managedClusterSet" : var.managedclusterset
4141
"managedClusterExtraLabels" : var.managedcluster_extra_labels
42-
"vault" : {
43-
"roleID" : vault_approle_auth_backend_role.this.role_id
44-
"secretID" : vault_approle_auth_backend_role_secret_id.this.secret_id
45-
}
4642
})
4743
}
4844

@@ -84,6 +80,22 @@ resource "helm_release" "hosted_cluster" {
8480
}
8581
}
8682

83+
dynamic "set" {
84+
for_each = (var.deploy_vault_app_role ? ["apply"] : [])
85+
content {
86+
name = "vault.roleID"
87+
value = vault_approle_auth_backend_role.this[0].role_id
88+
}
89+
}
90+
91+
dynamic "set" {
92+
for_each = (var.deploy_vault_app_role ? ["apply"] : [])
93+
content {
94+
name = "vault.secretID"
95+
value = vault_approle_auth_backend_role_secret_id.this[0].secret_id
96+
}
97+
}
98+
8799
timeout = 900
88100

89101
depends_on = [

hosted-cluster/templates/vault-approle-secret.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- if .Values.vault }}
12
apiVersion: v1
23
kind: Secret
34
metadata:
@@ -7,3 +8,4 @@ type: Opaque
78
stringData:
89
"role_id": {{ .Values.vault.roleID }}
910
"secret_id": {{ .Values.vault.secretID }}
11+
{{ end }}

security_group.tf

Lines changed: 8 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,14 @@ resource "aws_security_group" "worker" {
77
name = format("%s-worker-sg", local.name)
88
description = "worker security group"
99
vpc_id = var.vpc_id
10-
tags = {
11-
Name = format("%s-worker-sg", local.name)
12-
format("kubernetes.io/cluster/%s", local.name) = "owned"
13-
}
1410

15-
lifecycle {
16-
ignore_changes = [
17-
# Ignore changes ingress rules, as they will be modified
18-
# by openshift controllers
19-
ingress,
20-
]
21-
}
11+
# lifecycle {
12+
# ignore_changes = [
13+
# # Ignore changes ingress rules, as they will be modified
14+
# # by openshift controllers
15+
# ingress,
16+
# ]
17+
# }
2218

2319
egress {
2420
cidr_blocks = ["0.0.0.0/0"]
@@ -27,115 +23,4 @@ resource "aws_security_group" "worker" {
2723
self = "false"
2824
to_port = "0"
2925
}
30-
31-
ingress {
32-
cidr_blocks = local.cidr_blocks
33-
from_port = "-1"
34-
protocol = "icmp"
35-
self = "false"
36-
to_port = "-1"
37-
}
38-
39-
ingress {
40-
cidr_blocks = local.cidr_blocks
41-
from_port = "22"
42-
protocol = "tcp"
43-
self = "false"
44-
to_port = "22"
45-
}
46-
47-
ingress {
48-
cidr_blocks = local.cidr_blocks
49-
from_port = "443"
50-
protocol = "tcp"
51-
self = "false"
52-
to_port = "443"
53-
}
54-
55-
ingress {
56-
cidr_blocks = local.cidr_blocks
57-
from_port = "443"
58-
protocol = "udp"
59-
self = "false"
60-
to_port = "443"
61-
}
62-
63-
ingress {
64-
cidr_blocks = local.cidr_blocks
65-
from_port = "6443"
66-
protocol = "tcp"
67-
self = "false"
68-
to_port = "6443"
69-
}
70-
71-
ingress {
72-
cidr_blocks = local.cidr_blocks
73-
from_port = "6443"
74-
protocol = "udp"
75-
self = "false"
76-
to_port = "6443"
77-
}
78-
79-
ingress {
80-
from_port = "10250"
81-
protocol = "tcp"
82-
self = "true"
83-
to_port = "10250"
84-
}
85-
86-
ingress {
87-
from_port = "30000"
88-
protocol = "tcp"
89-
self = "true"
90-
to_port = "32767"
91-
}
92-
93-
ingress {
94-
from_port = "30000"
95-
protocol = "udp"
96-
self = "true"
97-
to_port = "32767"
98-
}
99-
100-
ingress {
101-
from_port = "4500"
102-
protocol = "udp"
103-
self = "true"
104-
to_port = "4500"
105-
}
106-
107-
ingress {
108-
from_port = "4789"
109-
protocol = "udp"
110-
self = "true"
111-
to_port = "4789"
112-
}
113-
114-
ingress {
115-
from_port = "500"
116-
protocol = "udp"
117-
self = "true"
118-
to_port = "500"
119-
}
120-
121-
ingress {
122-
from_port = "6081"
123-
protocol = "udp"
124-
self = "true"
125-
to_port = "6081"
126-
}
127-
128-
ingress {
129-
from_port = "9000"
130-
protocol = "tcp"
131-
self = "true"
132-
to_port = "9999"
133-
}
134-
135-
ingress {
136-
from_port = "9000"
137-
protocol = "udp"
138-
self = "true"
139-
to_port = "9999"
140-
}
141-
}
26+
}

variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ variable "oauth_endpoint_certificate_secret" {
7878
default = ""
7979
}
8080

81+
variable "deploy_vault_app_role" {
82+
type = bool
83+
default = false
84+
}
85+
8186
variable "managedclusterset" {
8287
type = string
8388
default = "hypershift"

vault.tf

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# AppRole for externalsecrets within the hostedcluster
22
resource "vault_policy" "this" {
3+
count = var.deploy_vault_app_role ? 1 : 0
34
name = "${local.name}-vault-approle"
45
policy = <<EOT
56
path "secret/data/kubernetes/${var.environment}-${var.project}/common/*" {
@@ -12,14 +13,16 @@ EOT
1213
}
1314

1415
resource "vault_approle_auth_backend_role" "this" {
16+
count = var.deploy_vault_app_role ? 1 : 0
1517
backend = "approle"
1618
role_name = "${local.name}-vault-approle"
17-
token_policies = [vault_policy.this.name]
19+
token_policies = [vault_policy.this[count.index].name]
1820
}
1921

2022
resource "vault_approle_auth_backend_role_secret_id" "this" {
23+
count = var.deploy_vault_app_role ? 1 : 0
2124
backend = "approle"
22-
role_name = vault_approle_auth_backend_role.this.role_name
25+
role_name = vault_approle_auth_backend_role.this[count.index].role_name
2326
}
2427

2528
# Retrieve GitHub oauth credentials from vault

0 commit comments

Comments
 (0)