Skip to content

Commit fe13cfb

Browse files
authored
chore: added new example (#839)
1 parent efad046 commit fe13cfb

File tree

10 files changed

+170
-1
lines changed

10 files changed

+170
-1
lines changed

.secrets.baseline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"files": "go.sum|^.secrets.baseline$",
44
"lines": null
55
},
6-
"generated_at": "2023-12-19T10:03:18Z",
6+
"generated_at": "2024-08-29T15:52:09Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ This module creates the following IBM Cloud® Virtual Private Cloud (VPC) net
3333
* [Hub and Spoke VPC with manual DNS resolver Example](./examples/hub-spoke-manual-resolver)
3434
* [Landing Zone example](./examples/landing_zone)
3535
* [No Prefix Example](./examples/no-prefix)
36+
* [Specific Zone Only Example](./examples/specific-zone-only)
3637
* [Contributing](#contributing)
3738
<!-- END OVERVIEW HOOK -->
3839

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Specific Zone Only Example
2+
3+
A simple example to provision a Secure Landing Zone (SLZ) Virtual Private Cloud (VPC) in a specific zone other than Zone 1. Also, shows how to use public gateways with a specific zone. In this example Zone 2 is used. A network ACL is specifically defined to allow all internet traffic.
4+
5+
The following resources are provisioned by this example:
6+
7+
* A new resource group, if an existing one is not passed in.
8+
* An IBM Virtual Private Cloud (VPC) with a publicly exposed subnet.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
##############################################################################
2+
# Resource Group
3+
##############################################################################
4+
5+
module "resource_group" {
6+
source = "terraform-ibm-modules/resource-group/ibm"
7+
version = "1.1.6"
8+
# if an existing resource group is not set (null) create a new one using prefix
9+
resource_group_name = var.resource_group == null ? "${var.prefix}-resource-group" : null
10+
existing_resource_group_name = var.resource_group
11+
}
12+
13+
#############################################################################
14+
# Provision VPC
15+
#############################################################################
16+
17+
module "slz_vpc" {
18+
source = "../../"
19+
resource_group_id = module.resource_group.resource_group_id
20+
region = var.region
21+
name = var.name
22+
prefix = var.prefix
23+
tags = var.resource_tags
24+
subnets = {
25+
zone-1 = []
26+
zone-2 = [
27+
{
28+
name = "subnet-a"
29+
cidr = "10.10.10.0/24"
30+
public_gateway = true
31+
acl_name = "${var.prefix}-acl"
32+
}
33+
]
34+
}
35+
use_public_gateways = {
36+
zone-1 = false
37+
zone-2 = true
38+
zone-3 = false
39+
}
40+
network_acls = [{
41+
name = "${var.prefix}-acl"
42+
add_ibm_cloud_internal_rules = false
43+
add_vpc_connectivity_rules = false
44+
prepend_ibm_rules = false
45+
rules = [{
46+
name = "inbound"
47+
action = "allow"
48+
source = "0.0.0.0/0"
49+
destination = "0.0.0.0/0"
50+
direction = "inbound"
51+
},
52+
{
53+
name = "outbound"
54+
action = "allow"
55+
source = "0.0.0.0/0"
56+
destination = "0.0.0.0/0"
57+
direction = "outbound"
58+
}
59+
]
60+
}
61+
]
62+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
##############################################################################
2+
# Outputs
3+
##############################################################################
4+
5+
output "vpc_id" {
6+
value = module.slz_vpc.vpc_id
7+
description = "VPC id"
8+
}
9+
10+
output "vpc_crn" {
11+
value = module.slz_vpc.vpc_crn
12+
description = "VPC crn"
13+
}
14+
15+
output "network_acls" {
16+
value = module.slz_vpc.network_acls
17+
description = "VPC network ACLs"
18+
}
19+
20+
output "public_gateways" {
21+
value = module.slz_vpc.public_gateways
22+
description = "VPC public gateways"
23+
}
24+
25+
output "subnet_zone_list" {
26+
value = module.slz_vpc.subnet_zone_list
27+
description = "VPC subnet zone list"
28+
}
29+
30+
output "subnet_detail_map" {
31+
value = module.slz_vpc.subnet_detail_map
32+
description = "VPC subnet detail map"
33+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
provider "ibm" {
2+
ibmcloud_api_key = var.ibmcloud_api_key
3+
region = var.region
4+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
variable "ibmcloud_api_key" {
2+
description = "APIkey that's associated with the account to provision resources to"
3+
type = string
4+
sensitive = true
5+
}
6+
7+
variable "region" {
8+
description = "The region to which to deploy the VPC"
9+
type = string
10+
default = "us-south"
11+
}
12+
13+
variable "prefix" {
14+
description = "The prefix that you would like to append to your resources"
15+
type = string
16+
default = "basic-slz-vpc"
17+
}
18+
19+
variable "name" {
20+
description = "The name of the vpc"
21+
type = string
22+
default = "vpc"
23+
}
24+
25+
variable "resource_group" {
26+
type = string
27+
description = "An existing resource group name to use for this example, if unset a new resource group will be created"
28+
default = null
29+
}
30+
31+
variable "resource_tags" {
32+
description = "List of Tags for the resource created"
33+
type = list(string)
34+
default = null
35+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.3.0"
3+
required_providers {
4+
# Pin to the lowest provider version of the range defined in the main module's version.tf to ensure lowest version still works
5+
ibm = {
6+
source = "IBM-Cloud/ibm"
7+
version = "1.59.0"
8+
}
9+
}
10+
}

tests/other_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,18 @@ func TestRunHubAndSpokeDelegatedExample(t *testing.T) {
3939
assert.Nil(t, err, "This should not have errored")
4040
assert.NotNil(t, output, "Expected some output")
4141
}
42+
43+
func TestRunSpecificZoneExample(t *testing.T) {
44+
t.Parallel()
45+
46+
options := testhelper.TestOptionsDefaultWithVars(&testhelper.TestOptions{
47+
Testing: t,
48+
TerraformDir: specificZoneExampleTerraformDir,
49+
Prefix: "spec-zone-slz",
50+
ResourceGroup: resourceGroup,
51+
})
52+
53+
output, err := options.RunTestConsistency()
54+
assert.Nil(t, err, "This should not have errored")
55+
assert.NotNil(t, output, "Expected some output")
56+
}

tests/pr_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const defaultExampleTerraformDir = "examples/default"
2323
const landingZoneExampleTerraformDir = "examples/landing_zone"
2424
const hubAndSpokeDelegatedExampleTerraformDir = "examples/hub-spoke-delegated-resolver"
2525
const existingVPCExampleTerraformDir = "examples/existing_vpc"
26+
const specificZoneExampleTerraformDir = "examples/specific-zone-only"
2627
const noprefixExampleTerraformDir = "examples/no-prefix"
2728
const resourceGroup = "geretain-test-resources"
2829

0 commit comments

Comments
 (0)