Skip to content

Commit cbb52a9

Browse files
author
Sean Sundberg
committed
Fixes issue using an existing VPC
- Adds count to acl_rule resources using provision flag - count #63 - Updates workflows to use action-workflows - count #61 Signed-off-by: Sean Sundberg <[email protected]>
1 parent 5a52308 commit cbb52a9

File tree

8 files changed

+117
-127
lines changed

8 files changed

+117
-127
lines changed

.github/workflows/notify.yaml

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
1+
name: Notify
2+
13
on:
24
release:
35
types: [published]
46

57
jobs:
68
notify:
7-
runs-on: ubuntu-latest
8-
9-
strategy:
10-
matrix:
11-
repo:
12-
- cloud-native-toolkit/ibm-garage-iteration-zero
13-
- cloud-native-toolkit/garage-terraform-modules
14-
15-
steps:
16-
- name: Repository dispatch ${{ matrix.repo }}
17-
uses: cloud-native-toolkit/action-repository-dispatch@main
18-
with:
19-
notifyRepo: ${{ matrix.repo }}
20-
eventType: released
21-
env:
22-
GITHUB_TOKEN: ${{ secrets.TOKEN }}
9+
uses: cloud-native-toolkit/action-workflows/.github/workflows/notify.yaml@v1
10+
secrets:
11+
TOKEN: ${{ secrets.TOKEN }}

.github/workflows/publish-assets.yaml

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Publish metadata
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
jobs:
9+
publish-assets:
10+
uses: cloud-native-toolkit/action-workflows/.github/workflows/publish-metadata.yaml@v1
11+
secrets:
12+
TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/verify-pr.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Verify PR
2+
3+
# Controls when the action will run. Triggers the workflow on push or pull request
4+
# events but only for the main branch
5+
on:
6+
pull_request:
7+
branches: [ main ]
8+
9+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
10+
jobs:
11+
verify:
12+
if: ${{ !contains( github.event.pull_request.labels.*.name, 'skip ci' ) }}
13+
uses: ./.github/workflows/verify-workflow.yaml
14+
secrets:
15+
IBMCLOUD_API_KEY: ${{ secrets.IBMCLOUD_API_KEY }}
16+
17+
verifyMetadata:
18+
uses: cloud-native-toolkit/action-workflows/.github/workflows/verify-module-metadata.yaml@v1
19+
20+
securityScan:
21+
uses: cloud-native-toolkit/action-workflows/.github/workflows/gitguardian-scan.yaml@v1
22+
secrets:
23+
GITGUARDIAN_API_KEY: ${{ secrets.GITGUARDIAN_API_KEY }}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Verify
2+
3+
# Controls when the action will run.
4+
on:
5+
workflow_call:
6+
secrets:
7+
IBMCLOUD_API_KEY:
8+
required: true
9+
10+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
11+
jobs:
12+
verify:
13+
runs-on: ubuntu-latest
14+
container: quay.io/cloudnativetoolkit/terraform:v1.1
15+
16+
strategy:
17+
matrix:
18+
testcase:
19+
- vpc_count
20+
- vpc_count_cidr
21+
fail-fast: true
22+
max-parallel: 1
23+
24+
env:
25+
HOME: /home/devops
26+
27+
# Steps represent a sequence of tasks that will be executed as part of the job
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v1
31+
32+
- name: Verify deploy on ${{ matrix.testcase }}
33+
uses: cloud-native-toolkit/action-module-verify-deploy@main
34+
with:
35+
clusterId: ${{ matrix.testcase }}
36+
validateDeployScript: .github/scripts/validate-deploy.sh
37+
env:
38+
TF_VAR_ibmcloud_api_key: ${{ secrets.IBMCLOUD_API_KEY }}
39+
IBMCLOUD_API_KEY: ${{ secrets.IBMCLOUD_API_KEY }}
40+
41+
- name: Verify destroy on ${{ matrix.testcase }}
42+
uses: cloud-native-toolkit/action-module-verify-destroy@main
43+
if: ${{ always() }}
44+
with:
45+
clusterId: ${{ matrix.testcase }}
46+
env:
47+
TF_VAR_ibmcloud_api_key: ${{ secrets.IBMCLOUD_API_KEY }}
48+
IBMCLOUD_API_KEY: ${{ secrets.IBMCLOUD_API_KEY }}

.github/workflows/verify.yaml

Lines changed: 13 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,29 @@
1-
name: Verify and release module
1+
name: Verify
22

33
# Controls when the action will run. Triggers the workflow on push or pull request
44
# events but only for the main branch
55
on:
66
push:
77
branches: [ main ]
8-
pull_request:
9-
branches: [ main ]
108

119
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
1210
jobs:
1311
verify:
1412
if: ${{ !contains( github.event.pull_request.labels.*.name, 'skip ci' ) }}
15-
runs-on: ubuntu-latest
16-
container: quay.io/cloudnativetoolkit/terraform:v1.1
17-
18-
strategy:
19-
matrix:
20-
platform:
21-
- vpc_count
22-
- vpc_count_cidr
23-
max-parallel: 1
24-
fail-fast: true
25-
26-
env:
27-
HOME: /home/devops
28-
29-
# Steps represent a sequence of tasks that will be executed as part of the job
30-
steps:
31-
- name: Checkout
32-
uses: actions/checkout@v1
33-
34-
- name: Verify deploy on ${{ matrix.platform }}
35-
uses: ibm-garage-cloud/action-module-verify-deploy@main
36-
with:
37-
clusterId: ${{ matrix.platform }}
38-
validateDeployScript: .github/scripts/validate-deploy.sh
39-
env:
40-
TF_VAR_ibmcloud_api_key: ${{ secrets.IBMCLOUD_API_KEY }}
41-
IBMCLOUD_API_KEY: ${{ secrets.IBMCLOUD_API_KEY }}
42-
43-
- name: Verify destroy on ${{ matrix.platform }}
44-
uses: ibm-garage-cloud/action-module-verify-destroy@main
45-
if: ${{ always() }}
46-
with:
47-
clusterId: ${{ matrix.platform }}
48-
env:
49-
TF_VAR_ibmcloud_api_key: ${{ secrets.IBMCLOUD_API_KEY }}
50-
IBMCLOUD_API_KEY: ${{ secrets.IBMCLOUD_API_KEY }}
13+
uses: ./.github/workflows/verify-workflow.yaml
14+
secrets:
15+
IBMCLOUD_API_KEY: ${{ secrets.IBMCLOUD_API_KEY }}
5116

5217
verifyMetadata:
53-
runs-on: ubuntu-latest
54-
55-
env:
56-
DIST_DIR: ./dist
57-
PUBLISH_BRANCH: gh-pages
18+
uses: cloud-native-toolkit/action-workflows/.github/workflows/verify-module-metadata.yaml@v1
5819

59-
steps:
60-
- name: Checkout
61-
uses: actions/checkout@v2
62-
63-
- uses: cloud-native-toolkit/action-module-metadata-create@v1
64-
with:
65-
strict: true
66-
validate: true
20+
securityScan:
21+
uses: cloud-native-toolkit/action-workflows/.github/workflows/gitguardian-scan.yaml@v1
22+
secrets:
23+
GITGUARDIAN_API_KEY: ${{ secrets.GITGUARDIAN_API_KEY }}
6724

6825
release:
69-
needs: [verify, verifyMetadata]
70-
runs-on: ubuntu-latest
71-
if: ${{ github.event_name == 'push' }}
72-
73-
# Steps represent a sequence of tasks that will be executed as part of the job
74-
steps:
75-
# Drafts your next Release notes as Pull Requests are merged into "main"
76-
- uses: release-drafter/release-drafter@v5
77-
with:
78-
# (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
79-
config-name: release-drafter.yaml
80-
publish: true
81-
env:
82-
GITHUB_TOKEN: ${{ secrets.TOKEN }}
26+
needs: [verify, verifyMetadata, securityScan]
27+
uses: cloud-native-toolkit/action-workflows/.github/workflows/release-module.yaml@v1
28+
secrets:
29+
TOKEN: ${{ secrets.TOKEN }}

main.tf

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ data ibm_is_vpc vpc {
4848
}
4949

5050
resource ibm_is_vpc_address_prefix cidr_prefix {
51-
count = local.provision_cidr ? var.address_prefix_count : 0
51+
count = var.provision && local.provision_cidr ? var.address_prefix_count : 0
5252

5353
name = "${local.vpc_name}-cidr-${format("%02s", count.index)}"
5454
zone = local.vpc_zone_names[count.index]
@@ -58,6 +58,7 @@ resource ibm_is_vpc_address_prefix cidr_prefix {
5858
}
5959

6060
resource ibm_is_network_acl_rule allow_internal_egress {
61+
count = var.provision ? 1 : 0
6162

6263
network_acl = lookup(local.vpc, "default_network_acl", "")
6364
name = "allow-internal-egress"
@@ -68,17 +69,19 @@ resource ibm_is_network_acl_rule allow_internal_egress {
6869
}
6970

7071
resource ibm_is_network_acl_rule allow_internal_ingress {
72+
count = var.provision ? 1 : 0
7173

7274
network_acl = lookup(local.vpc, "default_network_acl", "")
7375
name = "allow-internal-ingress"
7476
action = "allow"
7577
source = var.internal_cidr
7678
destination = var.internal_cidr
7779
direction = "inbound"
78-
before = lookup(ibm_is_network_acl_rule.deny_external_ssh, "rule_id", "")
80+
before = lookup(ibm_is_network_acl_rule.deny_external_ssh[0], "rule_id", "")
7981
}
8082

8183
resource ibm_is_network_acl_rule deny_external_ssh {
84+
count = var.provision ? 1 : 0
8285

8386
network_acl = lookup(local.vpc, "default_network_acl", "")
8487
name = "deny-external-ssh"
@@ -92,10 +95,11 @@ resource ibm_is_network_acl_rule deny_external_ssh {
9295
source_port_max = 22
9396
source_port_min = 22
9497
}
95-
before = lookup(ibm_is_network_acl_rule.deny_external_rdp, "rule_id", "")
98+
before = lookup(ibm_is_network_acl_rule.deny_external_rdp[0], "rule_id", "")
9699
}
97100

98101
resource ibm_is_network_acl_rule deny_external_rdp {
102+
count = var.provision ? 1 : 0
99103

100104
network_acl = lookup(local.vpc, "default_network_acl", "")
101105
name = "deny-external-rdp"
@@ -109,10 +113,11 @@ resource ibm_is_network_acl_rule deny_external_rdp {
109113
source_port_max = 3389
110114
source_port_min = 3389
111115
}
112-
before = lookup(ibm_is_network_acl_rule.deny_external_ingress, "rule_id", "")
116+
before = lookup(ibm_is_network_acl_rule.deny_external_ingress[0], "rule_id", "")
113117
}
114118

115119
resource ibm_is_network_acl_rule deny_external_ingress {
120+
count = var.provision ? 1 : 0
116121

117122
network_acl = lookup(local.vpc, "default_network_acl", "")
118123
name = "deny-external-ingress"
@@ -138,6 +143,7 @@ data ibm_is_security_group base {
138143

139144
# from https://cloud.ibm.com/docs/vpc?topic=vpc-service-endpoints-for-vpc
140145
resource ibm_is_security_group_rule default_inbound_ping {
146+
count = var.provision ? 1 : 0
141147

142148
group = lookup(local.vpc, "default_security_group", "")
143149
direction = "inbound"
@@ -149,6 +155,7 @@ resource ibm_is_security_group_rule default_inbound_ping {
149155
}
150156

151157
resource ibm_is_security_group_rule default_inbound_http {
158+
count = var.provision ? 1 : 0
152159

153160
group = lookup(local.vpc, "default_security_group", "")
154161
direction = "inbound"
@@ -161,7 +168,7 @@ resource ibm_is_security_group_rule default_inbound_http {
161168
}
162169

163170
resource ibm_is_security_group_rule cse_dns_1 {
164-
count = local.security_group_count
171+
count = var.provision ? local.security_group_count : 0
165172

166173
group = local.security_group_ids[count.index]
167174
direction = "outbound"
@@ -173,7 +180,7 @@ resource ibm_is_security_group_rule cse_dns_1 {
173180
}
174181

175182
resource ibm_is_security_group_rule cse_dns_2 {
176-
count = local.security_group_count
183+
count = var.provision ? local.security_group_count : 0
177184

178185
group = local.security_group_ids[count.index]
179186
direction = "outbound"
@@ -185,7 +192,7 @@ resource ibm_is_security_group_rule cse_dns_2 {
185192
}
186193

187194
resource ibm_is_security_group_rule private_dns_1 {
188-
count = local.security_group_count
195+
count = var.provision ? local.security_group_count : 0
189196

190197
group = local.security_group_ids[count.index]
191198
direction = "outbound"
@@ -197,7 +204,7 @@ resource ibm_is_security_group_rule private_dns_1 {
197204
}
198205

199206
resource ibm_is_security_group_rule private_dns_2 {
200-
count = local.security_group_count
207+
count = var.provision ? local.security_group_count : 0
201208

202209
group = local.security_group_ids[count.index]
203210
direction = "outbound"

test/stages/stage1-resource-group.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ module "resource_group" {
22
source = "github.com/cloud-native-toolkit/terraform-ibm-resource-group.git"
33

44
resource_group_name = var.resource_group_name
5-
provision = false
5+
ibmcloud_api_key = var.ibmcloud_api_key
66
}

0 commit comments

Comments
 (0)