Skip to content

Commit 1d1d967

Browse files
author
Sean Sundberg
authored
Updates acl rules to use terraform provider (#48)
Signed-off-by: Sean Sundberg <[email protected]>
1 parent 48c4eb6 commit 1d1d967

File tree

6 files changed

+61
-48
lines changed

6 files changed

+61
-48
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ module "dev_vpc" {
5151
resource_group_name = module.resource_group.name
5252
region = var.region
5353
name_prefix = var.name_prefix
54-
ibmcloud_api_key = var.ibmcloud_api_key
5554
}
5655
```
5756

main.tf

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,64 @@ resource ibm_is_vpc_address_prefix cidr_prefix {
4343
is_default = count.index < local.zone_count
4444
}
4545

46-
resource null_resource setup_default_acl {
47-
depends_on = [ibm_is_vpc.vpc]
48-
count = false && var.provision ? 1 : 0
46+
resource ibm_is_network_acl_rule allow_internal_egress {
47+
network_acl = data.ibm_is_vpc.vpc.default_network_acl
48+
name = "allow-internal-egress"
49+
action = "allow"
50+
source = var.internal_cidr
51+
destination = var.internal_cidr
52+
direction = "outbound"
53+
}
4954

50-
provisioner "local-exec" {
51-
command = "${path.module}/scripts/setup-default-acl.sh ${data.ibm_is_vpc.vpc.default_network_acl} ${var.region} ${var.resource_group_name}"
55+
resource ibm_is_network_acl_rule allow_internal_ingress {
56+
network_acl = data.ibm_is_vpc.vpc.default_network_acl
57+
name = "allow-internal-ingress"
58+
action = "allow"
59+
source = var.internal_cidr
60+
destination = var.internal_cidr
61+
direction = "inbound"
62+
before = ibm_is_network_acl_rule.deny_external_ssh.rule_id
63+
}
5264

53-
environment = {
54-
IBMCLOUD_API_KEY = var.ibmcloud_api_key
55-
}
65+
resource ibm_is_network_acl_rule deny_external_ssh {
66+
network_acl = data.ibm_is_vpc.vpc.default_network_acl
67+
name = "deny-external-ssh"
68+
action = "deny"
69+
source = "0.0.0.0/0"
70+
destination = "0.0.0.0/0"
71+
direction = "inbound"
72+
tcp {
73+
port_max = 22
74+
port_min = 22
75+
source_port_max = 22
76+
source_port_min = 22
5677
}
78+
before = ibm_is_network_acl_rule.deny_external_rdp.rule_id
79+
}
80+
81+
resource ibm_is_network_acl_rule deny_external_rdp {
82+
network_acl = data.ibm_is_vpc.vpc.default_network_acl
83+
name = "deny-external-rdp"
84+
action = "deny"
85+
source = "0.0.0.0/0"
86+
destination = "0.0.0.0/0"
87+
direction = "inbound"
88+
tcp {
89+
port_max = 3389
90+
port_min = 3389
91+
source_port_max = 3389
92+
source_port_min = 3389
93+
}
94+
before = ibm_is_network_acl_rule.deny_external_ingress.rule_id
95+
}
96+
97+
resource ibm_is_network_acl_rule deny_external_ingress {
98+
network_acl = data.ibm_is_vpc.vpc.default_network_acl
99+
name = "deny-external-ingress"
100+
action = "deny"
101+
source = "0.0.0.0/0"
102+
destination = "0.0.0.0/0"
103+
direction = "inbound"
57104
}
58105

59106
resource ibm_is_security_group base {

module.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,3 @@ versions:
2929
scope: module
3030
- name: name_prefix
3131
scope: global
32-
- name: ibmcloud_api_key
33-
scope: global

scripts/setup-default-acl.sh

Lines changed: 0 additions & 31 deletions
This file was deleted.

test/stages/stage2-vpc.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ module "dev_vpc" {
55
resource_group_name = module.resource_group.name
66
region = var.region
77
name_prefix = var.name_prefix
8-
ibmcloud_api_key = var.ibmcloud_api_key
98
address_prefix_count = var.address_prefix_count
109
address_prefixes = jsondecode(var.address_prefixes)
1110
}

variables.tf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ variable "name_prefix" {
2626
default = ""
2727
}
2828

29-
variable "ibmcloud_api_key" {
30-
type = string
31-
description = "The IBM Cloud api token"
32-
}
33-
3429
variable "provision" {
3530
type = bool
3631
description = "Flag indicating that the instance should be provisioned. If false then an existing instance will be looked up"
@@ -54,3 +49,9 @@ variable "base_security_group_name" {
5449
description = "The name of the base security group. If not provided the name will be based on the vpc name"
5550
default = ""
5651
}
52+
53+
variable "internal_cidr" {
54+
type = string
55+
description = "The cidr range of the internal network"
56+
default = "10.0.0.0/8"
57+
}

0 commit comments

Comments
 (0)