Skip to content

Commit 0f9bae1

Browse files
jvallexmterraform-ibm-modules-opsrenovate-bot
authored
feat: initial commit (#126)
* feat: initial commit * fix: tests * fix: testOptions * chore(deps): update module github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper to v1.3.2 (#101) Co-authored-by: Renovate Bot <[email protected]> * chore(deps): update module github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper to v1.3.4 (#102) Co-authored-by: Renovate Bot <[email protected]> * chore(deps): update module github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper to v1.3.5 (#104) Co-authored-by: Renovate Bot <[email protected]> * chore(deps): update module github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper to v1.3.7 (#107) Co-authored-by: Renovate Bot <[email protected]> * chore(deps): update module github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper to v1.3.8 (#108) Co-authored-by: Renovate Bot <[email protected]> * chore(deps): update module github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper to v1.4.0 (#115) Co-authored-by: Renovate Bot <[email protected]> * chore(deps): update module github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper to v1.4.1 (#116) Co-authored-by: Renovate Bot <[email protected]> * chore(deps): update module github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper to v1.4.2 (#124) Co-authored-by: Renovate Bot <[email protected]> * feat: initial commit Co-authored-by: Terraform IBM Modules Operations <[email protected]> Co-authored-by: Renovate Bot <[email protected]>
1 parent 0ec424e commit 0f9bae1

28 files changed

+594
-222
lines changed

README.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,28 +128,42 @@ statement instead the previous block.
128128
<!-- BEGIN EXAMPLES HOOK -->
129129
## Examples
130130

131-
- [ Default example](examples/default)
132-
- [ Example that uses existing resources](examples/existing-resources)
133-
- [ Non default example](examples/non-default)
131+
- [Examples](examples)
134132
<!-- END EXAMPLES HOOK -->
135133
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
136134
## Requirements
137135

138136
| Name | Version |
139137
|------|---------|
140-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.0 |
138+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >=1.2 |
139+
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | ~>1.43.0 |
141140

142141
## Modules
143142

144143
No modules.
145144

146145
## Resources
147146

148-
No resources.
147+
| Name | Type |
148+
|------|------|
149+
| [ibm_is_subnet_reserved_ip.ip](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/is_subnet_reserved_ip) | resource |
150+
| [ibm_is_virtual_endpoint_gateway.vpe](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/is_virtual_endpoint_gateway) | resource |
151+
| [ibm_is_virtual_endpoint_gateway_ip.endpoint_gateway_ip](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/is_virtual_endpoint_gateway_ip) | resource |
149152

150153
## Inputs
151154

152-
No inputs.
155+
| Name | Description | Type | Default | Required |
156+
|------|-------------|------|---------|:--------:|
157+
| <a name="input_cloud_service_by_crn"></a> [cloud\_service\_by\_crn](#input\_cloud\_service\_by\_crn) | List of cloud service CRNs. Each CRN will have a unique endpoint gateways created. For a list of supported services, see the docs [here](https://cloud.ibm.com/docs/vpc?topic=vpc-vpe-supported-services). | <pre>list(<br> object({<br> name = string # service name<br> crn = string # service crn<br> })<br> )</pre> | `[]` | no |
158+
| <a name="input_cloud_services"></a> [cloud\_services](#input\_cloud\_services) | List of cloud services to create an endpoint gateway. | `list(string)` | <pre>[<br> "kms",<br> "cloud-object-storage"<br>]</pre> | no |
159+
| <a name="input_prefix"></a> [prefix](#input\_prefix) | The prefix that you would like to append to your resources | `string` | `"vpe"` | no |
160+
| <a name="input_region"></a> [region](#input\_region) | The region where VPC and services are deployed | `string` | `"us-south"` | no |
161+
| <a name="input_resource_group_id"></a> [resource\_group\_id](#input\_resource\_group\_id) | ID of the resource group where endpoint gateways will be provisioned | `string` | `null` | no |
162+
| <a name="input_security_group_ids"></a> [security\_group\_ids](#input\_security\_group\_ids) | List of security group ids to attach to each endpoint gateway. | `list(string)` | `null` | no |
163+
| <a name="input_service_endpoints"></a> [service\_endpoints](#input\_service\_endpoints) | Service endpoints to use to create endpoint gateways. Can be `public`, or `private`. | `string` | `"private"` | no |
164+
| <a name="input_subnet_zone_list"></a> [subnet\_zone\_list](#input\_subnet\_zone\_list) | List of subnets in the VPC where gateways and reserved IPs will be provisioned. This value is intended to use the `subnet_zone_list` output from the ICSE VPC Subnet Module (https://github.com/Cloud-Schematics/vpc-subnet-module) or from templates using that module for subnet creation. | <pre>list(<br> object({<br> name = string<br> id = string<br> zone = optional(string)<br> cidr = optional(string)<br> })<br> )</pre> | `[]` | no |
165+
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | ID of the VPC where the Endpoint Gateways will be created | `string` | `null` | no |
166+
| <a name="input_vpc_name"></a> [vpc\_name](#input\_vpc\_name) | Name of the VPC where the Endpoint Gateways will be created. This value is used to dynamically generate VPE names. | `string` | `"vpc"` | no |
153167

154168
## Outputs
155169

examples/default/README.md

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

examples/default/main.tf

Lines changed: 94 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,103 @@
11
##############################################################################
2-
# Resource Group
2+
# VPE Locals
33
##############################################################################
44

5-
module "resource_group" {
6-
source = "git::https://github.com/terraform-ibm-modules/terraform-ibm-resource-group.git?ref=v1.0.5"
7-
# if an existing resource group is not set (null) create a new one using prefix
8-
resource_group_name = var.resource_group == null ? "${var.prefix}-resource-group" : null
9-
existing_resource_group_name = var.resource_group
5+
locals {
6+
# List of Gateways to create
7+
gateway_list = var.vpc_id == null ? [] : concat([
8+
# Create object for each service
9+
for service in var.cloud_services :
10+
{
11+
name = "${var.vpc_name}-${service}"
12+
service = service
13+
crn = null
14+
}
15+
],
16+
[
17+
for service in var.cloud_service_by_crn :
18+
{
19+
name = "${var.vpc_name}-${service.name}"
20+
service = null
21+
crn = service.crn
22+
}
23+
]
24+
)
25+
26+
# List of IPs to create
27+
endpoint_ip_list = var.vpc_id == null ? [] : flatten([
28+
# Create object for each subnet
29+
for subnet in var.subnet_zone_list :
30+
[
31+
for service in var.cloud_services :
32+
{
33+
ip_name = "${subnet.name}-${service}-gateway-${replace(subnet.zone, "/${var.region}-/", "")}-ip"
34+
subnet_id = subnet.id
35+
gateway_name = "${var.vpc_name}-${service}"
36+
}
37+
]
38+
])
39+
40+
# Map of Services to endpoints
41+
service_to_endpoint_map = {
42+
kms = "crn:v1:bluemix:public:kms:${var.region}:::endpoint:${var.service_endpoints}.${var.region}.kms.cloud.ibm.com"
43+
hs-crypt = "crn:v1:bluemix:public:hs-crypto:${var.region}:::endpoint:api.${var.service_endpoints}.${var.region}.hs-crypto.cloud.ibm.com"
44+
cloud-object-storage = "crn:v1:bluemix:public:cloud-object-storage:global:::endpoint:s3.direct.${var.region}.cloud-object-storage.appdomain.cloud"
45+
container-registry = "crn:v1:bluemix:public:container-registry:${var.region}:::endpoint:vpe.${var.region}.container-registry.cloud.ibm.com"
46+
}
1047
}
1148

1249
##############################################################################
13-
# VPC
50+
51+
##############################################################################
52+
# Create Reserved IPs
1453
##############################################################################
1554

16-
resource "ibm_is_vpc" "vpc" {
17-
name = "${var.prefix}-vpc"
18-
resource_group = module.resource_group.resource_group_id
19-
tags = var.resource_tags
55+
resource "ibm_is_subnet_reserved_ip" "ip" {
56+
for_each = {
57+
# Create a map based on endpoint IP name
58+
for gateway_ip in local.endpoint_ip_list :
59+
(gateway_ip.ip_name) => gateway_ip
60+
}
61+
subnet = each.value.subnet_id
2062
}
63+
64+
##############################################################################
65+
66+
##############################################################################
67+
# Create Endpoint Gateways
68+
##############################################################################
69+
70+
resource "ibm_is_virtual_endpoint_gateway" "vpe" {
71+
for_each = {
72+
# Create map based on gateway name if enabled
73+
for gateway in local.gateway_list :
74+
(gateway.name) => gateway
75+
}
76+
77+
name = "${var.prefix}-${each.key}-endpoint-gateway"
78+
vpc = var.vpc_id
79+
resource_group = var.resource_group_id
80+
security_groups = var.security_group_ids
81+
target {
82+
crn = each.value.service == null ? each.value.crn : local.service_to_endpoint_map[each.value.service]
83+
resource_type = "provider_cloud_service"
84+
}
85+
}
86+
87+
##############################################################################
88+
89+
##############################################################################
90+
# Attach Endpoint Gateways to Reserved IPs
91+
##############################################################################
92+
93+
resource "ibm_is_virtual_endpoint_gateway_ip" "endpoint_gateway_ip" {
94+
for_each = {
95+
# Create a map based on endpoint IP
96+
for gateway_ip in local.endpoint_ip_list :
97+
(gateway_ip.ip_name) => gateway_ip
98+
}
99+
gateway = ibm_is_virtual_endpoint_gateway.vpe[each.value.gateway_name].id
100+
reserved_ip = ibm_is_subnet_reserved_ip.ip[each.key].reserved_ip
101+
}
102+
103+
##############################################################################

examples/default/outputs.tf

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
11
##############################################################################
2-
# Outputs
2+
# Please open an issue to suggest outputs for this module
33
##############################################################################
4-
5-
output "vpc_id" {
6-
description = "ID of VPC created"
7-
value = ibm_is_vpc.vpc.id
8-
}
9-
10-
output "resource_group_name" {
11-
description = "Resource group name"
12-
value = module.resource_group.resource_group_name
13-
}
14-
15-
output "resource_group_id" {
16-
description = "Resource group ID"
17-
value = module.resource_group.resource_group_id
18-
}

examples/default/provider.tf

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

examples/default/variables.tf

Lines changed: 86 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,102 @@
1-
variable "ibmcloud_api_key" {
2-
type = string
3-
description = "The IBM Cloud API Key"
4-
sensitive = true
5-
}
1+
##############################################################################
2+
# VPC Variables
3+
##############################################################################
64

75
variable "region" {
6+
description = "The region where VPC and services are deployed"
87
type = string
9-
description = "Region to provision all resources created by this example"
108
default = "us-south"
119
}
1210

1311
variable "prefix" {
12+
description = "The prefix that you would like to append to your resources"
1413
type = string
15-
description = "Prefix to append to all resources created by this example"
16-
default = "terraform"
14+
default = "vpe"
1715
}
1816

19-
variable "resource_group" {
17+
variable "vpc_name" {
18+
description = "Name of the VPC where the Endpoint Gateways will be created. This value is used to dynamically generate VPE names."
19+
type = string
20+
default = "vpc"
21+
}
22+
23+
variable "vpc_id" {
24+
description = "ID of the VPC where the Endpoint Gateways will be created"
25+
type = string
26+
default = null
27+
}
28+
29+
variable "subnet_zone_list" {
30+
description = "List of subnets in the VPC where gateways and reserved IPs will be provisioned. This value is intended to use the `subnet_zone_list` output from the ICSE VPC Subnet Module (https://github.com/Cloud-Schematics/vpc-subnet-module) or from templates using that module for subnet creation."
31+
type = list(
32+
object({
33+
name = string
34+
id = string
35+
zone = optional(string)
36+
cidr = optional(string)
37+
})
38+
)
39+
default = []
40+
}
41+
42+
##############################################################################
43+
44+
##############################################################################
45+
# VPE Variables
46+
##############################################################################
47+
48+
variable "resource_group_id" {
49+
description = "ID of the resource group where endpoint gateways will be provisioned"
2050
type = string
21-
description = "An existing resource group name to use for this example, if unset a new resource group will be created"
2251
default = null
2352
}
2453

25-
variable "resource_tags" {
54+
variable "security_group_ids" {
55+
description = "List of security group ids to attach to each endpoint gateway."
2656
type = list(string)
27-
description = "Optional list of tags to be added to created resources"
28-
default = []
57+
default = null
2958
}
59+
60+
61+
variable "cloud_services" {
62+
description = "List of cloud services to create an endpoint gateway."
63+
type = list(string)
64+
default = ["kms", "cloud-object-storage"]
65+
66+
validation {
67+
error_message = "Currently the only supported services are Key Protect (`kms`), Cloud Object Storage (`cloud-object-storage`), Container Registry (`container-registry`), and Hyper Protect Crypto Services (`hs-crypto`). Any other VPE services must be added using `cloud_service_by_crn`."
68+
condition = length(var.cloud_services) == 0 ? true : length([
69+
for service in var.cloud_services :
70+
service if !contains([
71+
"kms",
72+
"hs-crypto",
73+
"cloud-object-storage",
74+
"container-registry"
75+
], service)
76+
]) == 0
77+
}
78+
}
79+
80+
variable "cloud_service_by_crn" {
81+
description = "List of cloud service CRNs. Each CRN will have a unique endpoint gateways created. For a list of supported services, see the docs [here](https://cloud.ibm.com/docs/vpc?topic=vpc-vpe-supported-services)."
82+
type = list(
83+
object({
84+
name = string # service name
85+
crn = string # service crn
86+
})
87+
)
88+
default = []
89+
}
90+
91+
variable "service_endpoints" {
92+
description = "Service endpoints to use to create endpoint gateways. Can be `public`, or `private`."
93+
type = string
94+
default = "private"
95+
96+
validation {
97+
error_message = "Service endpoints can only be `public` or `private`."
98+
condition = contains(["public", "private"], var.service_endpoints)
99+
}
100+
}
101+
102+
##############################################################################

examples/default/version.tf

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

examples/default/versions.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
##############################################################################
2+
# Terraform Providers
3+
##############################################################################
4+
5+
terraform {
6+
required_providers {
7+
ibm = {
8+
source = "IBM-Cloud/ibm"
9+
version = "~>1.43.0"
10+
}
11+
}
12+
required_version = ">=1.2"
13+
experiments = [module_variable_optional_attrs]
14+
}
15+
16+
##############################################################################

examples/existing-resources/README.md

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

examples/existing-resources/main.tf

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

0 commit comments

Comments
 (0)