Skip to content
This repository was archived by the owner on Aug 12, 2024. It is now read-only.

Commit f1669be

Browse files
author
Sean Sundberg
authored
Adds login for ibmcloud cli before creating acl rules (#37)
Signed-off-by: Sean Sundberg <[email protected]>
1 parent 98a4cbb commit f1669be

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

main.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ resource null_resource open_acl_rules {
128128
count = !var.exists && var.vpc_subnet_count > 0 ? 1 : 0
129129

130130
provisioner "local-exec" {
131-
command = "${path.module}/scripts/open-acl-rules.sh ${data.ibm_is_subnet.vpc_subnet[0].network_acl}"
131+
command = "${path.module}/scripts/open-acl-rules.sh '${data.ibm_is_subnet.vpc_subnet[0].network_acl}' '${var.region}' '${var.resource_group_name}'"
132+
133+
environment = {
134+
IBMCLOUD_API_KEY = var.ibmcloud_api_key
135+
}
132136
}
133137
}
134138

scripts/open-acl-rules.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
#!/usr/bin/env bash
22

33
NETWORK_ACL="$1"
4+
REGION="$2"
5+
RESOURCE_GROUP="$3"
46

5-
## TODO more sophisiticated logic needed to 1) test for existing rules and 2) place this rule in the right order
7+
if [[ -z "${NETWORK_ACL}" ]] || [[ -z "${REGION}" ]] || [[ -z "${RESOURCE_GROUP}" ]]; then
8+
echo "Usage: open-acl-rules.sh NETWORK_ACL REGION RESOURCE_GROUP"
9+
exit 1
10+
fi
11+
12+
if [[ -z "${IBMCLOUD_API_KEY}" ]]; then
13+
echo "IBMCLOUD_API_KEY environment variable must be set"
14+
exit 1
15+
fi
16+
17+
ibmcloud login --apikey "${IBMCLOUD_API_KEY}" -g "${RESOURCE_GROUP}" -r "${REGION}"
618

719
ibmcloud is network-acl-rule-add "${NETWORK_ACL}" allow inbound all "0.0.0.0/0" "0.0.0.0/0" --name allow-all-ingress
820
ibmcloud is network-acl-rule-add "${NETWORK_ACL}" allow outbound all "0.0.0.0/0" "0.0.0.0/0" --name allow-all-egress

0 commit comments

Comments
 (0)