Skip to content

Commit 1c89a2a

Browse files
authored
tests: run sg example & update readme (#292)
1 parent 3d3ba50 commit 1c89a2a

File tree

8 files changed

+90
-135
lines changed

8 files changed

+90
-135
lines changed

README.md

Lines changed: 51 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,76 @@
1-
<!-- BEGIN MODULE HOOK -->
1+
# IBM Virtual Private Endpoints module
22

3-
<!-- Update the title to match the module name and add a description -->
4-
# Terraform Modules Template Project
5-
<!-- UPDATE BADGE: Update the link for the following badge-->
63
[![Incubating (Not yet consumable)](https://img.shields.io/badge/status-Incubating%20(Not%20yet%20consumable)-red)](https://terraform-ibm-modules.github.io/documentation/#/badge-status)
7-
[![Build status](https://github.com/terraform-ibm-modules/terraform-ibm-module-template/actions/workflows/ci.yml/badge.svg)](https://github.com/terraform-ibm-modules/terraform-ibm-module-template/actions/workflows/ci.yml)
4+
[![Build status](https://github.com/terraform-ibm-modules/terraform-ibm-vpe-module/actions/workflows/ci.yml/badge.svg)](https://github.com/terraform-ibm-modules/terraform-ibm-vpe-module/actions/workflows/ci.yml)
85
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
96
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
10-
[![latest release](https://img.shields.io/github/v/release/terraform-ibm-modules/terraform-ibm-module-template?logo=GitHub&sort=semver)](https://github.com/terraform-ibm-modules/terraform-ibm-module-template/releases/latest)
7+
[![latest release](https://img.shields.io/github/v/release/terraform-ibm-modules/terraform-ibm-vpe-module?logo=GitHub&sort=semver)](https://github.com/terraform-ibm-modules/terraform-ibm-vpe-module/releases/latest)
118

12-
<!-- Remove the content in this H2 heading after completing the steps -->
9+
You can use this module to create and configure virtual private endpoint gateways (https://cloud.ibm.com/docs/vpc?topic=vpc-ordering-endpoint-gateway) for an IBM Cloud service.
1310

14-
## Submit a new module
15-
16-
:+1::tada: Thank you for taking the time to contribute! :tada::+1:
17-
18-
This template repository exists to help you create Terraform modules for IBM Cloud.
19-
20-
The default structure includes the following files:
21-
22-
- `README.md`: A description of the module
23-
- `main.tf`: The logic for the module
24-
- `version.tf`: The required terraform and provider versions
25-
- `variables.tf`: The input variables for the module
26-
- `outputs.tf`: The values that are output from the module
27-
For more information, see [Module structure](https://terraform-ibm-modules.github.io/documentation/#/module-structure) in the project documentation.
28-
29-
You can add other content to support what your module does and how it works. For example, you might add a `scripts/` directory that contains shell scripts that are run by a `local-exec` `null_resource` in the Terraform module.
30-
31-
Follow this process to create and submit a Terraform module.
32-
33-
### Create a repo from this repo template
34-
35-
1. Create a repository from this repository template by clicking `Use this template` in the upper right of the GitHub UI.
36-
&emsp;&emsp;&emsp;&emsp;<br>For more information about creating a repository from a template, see the [GitHub docs](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template).
37-
1. Select `terraform-ibm-modules` as the owner.
38-
1. Enter a name for the module in format `terraform-ibm-<NAME>`, where `<NAME>` reflects the type of infrastructure that the module manages.
39-
&emsp;&emsp;&emsp;&emsp;<br>Use hyphens as delimiters for names with multiple words (for example, terraform-ibm-`activity-tracker`).
40-
1. Provide a short description of the module.
41-
&emsp;&emsp;&emsp;&emsp;<br>The description is displayed under the repository name on the [organization page](https://github.com/terraform-ibm-modules) and in the **About** section of the repository. Use the description to help users understand the purpose of your module. For more information, see [module names and descriptions](https://terraform-ibm-modules.github.io/documentation/#/implementation-guidelines?id=module-names-and-descriptions) in the docs.
42-
43-
### Clone the repo and set up your development environment
44-
45-
Locally clone the new repository and set up your development environment by completing the tasks in [Local development setup](https://terraform-ibm-modules.github.io/documentation/#/local-dev-setup) in the project documentation.
46-
47-
### Update the repo name and description in source control
48-
49-
To help make sure that the repo name and description are not changed except through pull requests, they are defined in the `settings.yml` file.
50-
51-
Check to make sure that values are uncommented and correct:
52-
53-
1. Open the [settings.yml](.github/settings.yml) file.
54-
1. If not already updated, uncomment the `name` and `description` properties and set the values to what you specified when you requested the repo.
55-
56-
### Update the Terraform files
57-
58-
Implement the logic for your module by updating the `main.tf`, `version.tf`, `variables.tf`, and `outputs.tf` Terraform files. For more information, see [Creating Terraform on IBM Cloud templates](https://cloud.ibm.com/docs/ibm-cloud-provider-for-terraform?topic=ibm-cloud-provider-for-terraform-create-tf-config).
59-
60-
### Create examples and tests
61-
62-
Add one or more examples in the `examples` directory that consume your new module, and configure tests for them in the `tests` directory. For more information about tests, see [Tests](https://terraform-ibm-modules.github.io/documentation/#/tests).
63-
64-
### Update the content in the readme file
65-
66-
After you implement the logic for your module and create examples and tests, update this readme file in your repository by following these steps:
67-
68-
1. Update the title heading and add a description about your module.
69-
1. Update the badge links.
70-
1. Remove all the content in this H2 heading section.
71-
1. Complete the [Usage](#usage) and [Required IAM access policies](#required-iam-access-policies) sections. The [Examples](#examples) and [Requirements](#requirements) section are populated by a pre-commit hook.
72-
73-
### Commit your code and submit your module for review
74-
75-
1. Before you commit any code, review [Contributing to the IBM Cloud Terraform modules project](https://terraform-ibm-modules.github.io/documentation/#/contribute-module) in the project documentation.
76-
1. Create a pull request for review.
77-
78-
### Post-merge steps
79-
80-
After the first PR for your module is merged, follow these post-merge steps:
81-
82-
1. Create a PR to enable the upgrade test by removing the `t.Skip` line in `tests/pr_test.go`.
83-
84-
<!-- Remove the content in this previous H2 heading -->
11+
The module supports the following actions:
12+
- Create reserved IP addresses and endpoint gateways
13+
- Attach endpoint gateways to reserved IP addresses
8514

8615
## Usage
8716

88-
<!--
89-
Add an example of the use of the module in the following code block.
90-
91-
Use real values instead of "var.<var_name>" or other placeholder values
92-
unless real values don't help users know what to change.
93-
-->
94-
9517
```hcl
96-
18+
provider "ibm" {
19+
ibmcloud_api_key = "XXXXXXXXXX" # pragma: allowlist secret
20+
region = "us-south"
21+
}
22+
23+
# Creates:
24+
# - VPE
25+
module "vpes" {
26+
source = "git::https://github.com/terraform-ibm-modules/terraform-ibm-vpe-module?ref=main"
27+
region = "us-south"
28+
prefix = "vpe"
29+
vpc_name = "my-vpc-instance"
30+
vpc_id = "r022-ae2a6785-gd62-7d4j-af62-b4891e949345"
31+
subnet_zone_list = [
32+
{
33+
name = "subnet-1"
34+
cidr = "10.0.10.0/24"
35+
public_gateway = true
36+
acl_name = "acl"
37+
},
38+
{
39+
name = "subnet-2"
40+
cidr = "10.0.11.0/24"
41+
acl_name = "acl"
42+
public_gateway = null
43+
}
44+
]
45+
resource_group_id = "00ae4b38253f43a3acd14619dd385632" # pragma: allowlist secret
46+
security_group_ids = ["r014-2d4f8cd6-6g3s-4ab5-ac3f-8fc717ce2a1f"]
47+
cloud_services = ["kms", "cloud-object-storage"]
48+
cloud_service_by_crn = [
49+
{
50+
name = "subnet-1"
51+
crn = "crn:v1:bluemix:public:kms:au-syd:a/abac0df06b644a9cabc6e44f55b3880e:12d2244b-g3d3-4978-7s3f-81b60a1fb7a4::"
52+
},
53+
]
54+
service_endpoints = "private"
55+
}
9756
```
9857

9958
## Required IAM access policies
100-
101-
<!-- PERMISSIONS REQUIRED TO RUN MODULE
102-
If this module requires permissions, uncomment the following block and update
103-
the sample permissions, following the format.
104-
Replace the sample Account and IBM Cloud service names and roles with the
105-
information in the console at
106-
Manage > Access (IAM) > Access groups > Access policies.
107-
-->
108-
109-
<!--
11059
You need the following permissions to run this module.
11160

11261
- Account Management
113-
- **Sample Account Service** service
62+
- **Resource Group** service
63+
- `Viewer` platform access
64+
- IAM services
65+
- **VPE Infrastructure** services
11466
- `Editor` platform access
115-
- `Manager` service access
116-
- IAM Services
117-
- **Sample Cloud Service** service
118-
- `Administrator` platform access
119-
-->
120-
121-
<!-- NO PERMISSIONS FOR MODULE
122-
If no permissions are required for the module, uncomment the following
123-
statement instead the previous block.
124-
-->
125-
126-
<!-- No permissions are needed to run this module.-->
127-
<!-- END MODULE HOOK -->
67+
12868
<!-- BEGIN EXAMPLES HOOK -->
12969
## Examples
13070

13171
- [Examples](examples)
13272
<!-- END EXAMPLES HOOK -->
73+
13374
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
13475
## Requirements
13576

@@ -169,13 +110,9 @@ No modules.
169110

170111
No outputs.
171112
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
172-
<!-- BEGIN CONTRIBUTING HOOK -->
173113

174-
<!-- Leave this section as is so that your module has a link to local development environment set up steps for contributors to follow -->
175114
## Contributing
176115

177116
You can report issues and request features for this module in GitHub issues in the module repo. See [Report an issue or request a feature](https://github.com/terraform-ibm-modules/.github/blob/main/.github/SUPPORT.md).
178117

179118
To set up your local development environment, see [Local development setup](https://terraform-ibm-modules.github.io/documentation/#/local-dev-setup) in the project documentation.
180-
<!-- Source for this readme file: https://github.com/terraform-ibm-modules/common-dev-assets/tree/main/module-assets/ci/module-template-automation -->
181-
<!-- END CONTRIBUTING HOOK -->

common-dev-assets

examples/default/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module "resource_group" {
1111
##############################################################################
1212

1313
##############################################################################
14-
# Create VPC
14+
# Locals
1515
##############################################################################
1616

1717
locals {
@@ -26,11 +26,11 @@ locals {
2626
##############################################################################
2727
# Create a VPC for this example
2828
##############################################################################
29-
3029
resource "ibm_is_vpc" "vpc" {
3130
count = var.create_vpc ? 1 : 0
3231
name = "${var.prefix}-${var.vpc_name}"
3332
resource_group = module.resource_group.resource_group_id
33+
tags = var.resource_tags
3434
}
3535

3636
##############################################################################

examples/default/variables.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ variable "prefix" {
1919
variable "resource_group" {
2020
type = string
2121
description = "An existing resource group name to use for this example, if unset a new resource group will be created"
22-
default = null
22+
default = "geretain-test-resources"
2323
}
2424

2525
##############################################################################
@@ -111,4 +111,10 @@ variable "service_endpoints" {
111111
}
112112
}
113113

114+
variable "resource_tags" {
115+
type = list(string)
116+
description = "Optional list of tags to be added to created resources"
117+
default = []
118+
}
119+
114120
##############################################################################

examples/security-group/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ resource "ibm_is_vpc" "vpc" {
3131
count = var.create_vpc ? 1 : 0
3232
name = "${var.prefix}-${var.vpc_name}"
3333
resource_group = module.resource_group.resource_group_id
34+
tags = var.resource_tags
3435
}
3536

3637
##############################################################################

examples/security-group/variables.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ variable "region" {
1313
variable "prefix" {
1414
description = "The prefix that you would like to append to your resources"
1515
type = string
16-
default = "vpe"
16+
default = "sg-vpe"
1717
}
1818

1919
variable "resource_group" {
2020
type = string
2121
description = "An existing resource group name to use for this example, if unset a new resource group will be created"
22-
default = null
22+
default = "geretain-test-resources"
2323
}
2424

2525
##############################################################################
@@ -172,3 +172,9 @@ variable "add_ibm_cloud_internal_rules" {
172172
type = bool
173173
default = false
174174
}
175+
176+
variable "resource_tags" {
177+
type = list(string)
178+
description = "Optional list of tags to be added to created resources"
179+
default = []
180+
}

main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ resource "ibm_is_virtual_endpoint_gateway" "vpe" {
7474
(gateway.name) => gateway
7575
}
7676

77-
name = "${var.prefix}-${each.key}-endpoint-gateway"
77+
name = "${var.prefix}-${each.key}"
7878
vpc = var.vpc_id
7979
resource_group = var.resource_group_id
8080
security_groups = var.security_group_ids

tests/pr_test.go

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,40 @@ import (
1111
// Use existing resource group
1212
const resourceGroup = "geretain-test-resources"
1313
const defaultExampleTerraformDir = "examples/default"
14+
const securityGroupExampleTerraformDir = "examples/security-group"
1415

15-
func TestRunDefaultExample(t *testing.T) {
16-
t.Parallel()
17-
16+
func setupOptions(t *testing.T, prefix string, dir string) *testhelper.TestOptions {
1817
options := testhelper.TestOptionsDefault(&testhelper.TestOptions{
1918
Testing: t,
20-
TerraformDir: defaultExampleTerraformDir,
21-
Prefix: "mod-template",
19+
TerraformDir: dir,
20+
Prefix: prefix,
2221
ResourceGroup: resourceGroup,
2322
})
23+
return options
24+
}
2425

26+
func TestRunDefaultExample(t *testing.T) {
27+
t.Parallel()
28+
29+
options := setupOptions(t, "vpe-default", defaultExampleTerraformDir)
2530
output, err := options.RunTestConsistency()
2631
assert.Nil(t, err, "This should not have errored")
2732
assert.NotNil(t, output, "Expected some output")
2833
}
2934

30-
func TestRunUpgradeExample(t *testing.T) {
35+
func TestRunSecurityGroupExample(t *testing.T) {
3136
t.Parallel()
3237

33-
// TODO: Remove this line after the first merge to master branch is complete to enable upgrade test
34-
t.Skip("Skipping upgrade test until initial code is in master branch")
38+
options := setupOptions(t, "vpe-security-group", securityGroupExampleTerraformDir)
39+
output, err := options.RunTestConsistency()
40+
assert.Nil(t, err, "This should not have errored")
41+
assert.NotNil(t, output, "Expected some output")
42+
}
3543

36-
options := testhelper.TestOptionsDefault(&testhelper.TestOptions{
37-
Testing: t,
38-
TerraformDir: defaultExampleTerraformDir,
39-
Prefix: "mod-template-upg",
40-
ResourceGroup: resourceGroup,
41-
})
44+
func TestRunUpgradeExample(t *testing.T) {
45+
t.Parallel()
4246

47+
options := setupOptions(t, "vpe-upgrade", defaultExampleTerraformDir)
4348
output, err := options.RunTestUpgrade()
4449
if !options.UpgradeTestSkipped {
4550
assert.Nil(t, err, "This should not have errored")

0 commit comments

Comments
 (0)