Skip to content

Commit

Permalink
feat: mod template cleanup (#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocofaigh committed Aug 15, 2023
1 parent ec57842 commit 14a6c3a
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 117 deletions.
117 changes: 25 additions & 92 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
<!-- BEGIN MODULE HOOK -->

<!-- Update the title to match the module name and add a description -->
<!-- Update the title -->
# Terraform Modules Template Project
<!-- UPDATE BADGE: Update the link for the following badge-->

<!--
Update status and "latest release" badges:
1. For the status options, see https://github.ibm.com/GoldenEye/documentation/blob/master/status.md
2. Update the "latest release" badge to point to the correct module's repo. Replace "module-template" in two places.
-->
[![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)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
[![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)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
[![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com/)
[![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)

<!-- Add a description of module(s) in this repo -->


<!--
If this repo contains any reference architectures, uncomment the heading below and links to them.
(Usually in the `/reference-architectures` directory.)
See "Reference architecture" in Authoring Guidelines in the public documentation at
https://terraform-ibm-modules.github.io/documentation/#/implementation-guidelines?id=reference-architecture
-->
<!-- ## Reference architectures -->


<!-- Below content is automatically populated via pre-commit hook -->
<!-- BEGIN OVERVIEW HOOK -->
## Overview
* [terraform-ibm-module-template](#terraform-ibm-module-template)
Expand All @@ -19,88 +36,6 @@
## terraform-ibm-module-template
<!-- END OVERVIEW HOOK -->

<!-- Remove the content in this H2 heading after completing the steps -->

## Submit a new module

:+1::tada: Thank you for taking the time to contribute! :tada::+1:

This template repository exists to help you create Terraform modules for IBM Cloud.

The default structure includes the following files:

- `README.md`: A description of the module
- `main.tf`: The logic for the module
- `version.tf`: The required terraform and provider versions
- `variables.tf`: The input variables for the module
- `outputs.tf`: The values that are output from the module

Use nested modules to split complex behavior into smaller modules that advanced users can choose from. Put nested modules under a `/modules` subdirectory. If you include more than one nested module, make the submodules [composable](https://developer.hashicorp.com/terraform/language/modules/develop/composition) by the caller. In other words, don't embed calls between submodules to create a deeply nested tree of modules.
For more information, see [Module structure](https://terraform-ibm-modules.github.io/documentation/#/module-structure) in the project documentation.

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.

Follow this process to create and submit a Terraform module.

### Create a repo from this repo template

1. Create a repository from this repository template by clicking `Use this template` in the upper right of the GitHub UI.
&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).
1. Select `terraform-ibm-modules` as the owner.
1. Enter a name for the module in format `terraform-ibm-<name>`, where `<name>` reflects the type of infrastructure that the module manages.
&emsp;&emsp;&emsp;&emsp;<br>Use hyphens as delimiters for names with multiple words (for example, terraform-ibm-`activity-tracker`).
1. Provide a short description of the module.
&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.

### Clone the repo and set up your development environment

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.

### Update the repo name and description in source control

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.

Check to make sure that values are uncommented and correct:

1. Open the [settings.yml](.github/settings.yml) file.
1. If not already updated, uncomment the `name` and `description` properties and set the values to what you specified when you requested the repo.

### Update the Terraform files

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).

### Create examples and tests

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).

### Update the content in the readme file

After you implement the logic for your module and create examples and tests, update this readme file in your repository by following these steps:

1. Update the title heading and add a description about your module.
1. Update the badge links.
1. Remove all the content in this H2 heading section.
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.

### Commit your code and submit your module for review

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.
1. Create a pull request for review.

### Post-merge steps

After the first PR for your module is merged, follow these post-merge steps:

<!-- Remove the content in this previous H2 heading -->
### Reference architectures

<!--
Add links to any reference architectures for this module.
(Usually in the `/reference-architectures` directory.)
See "Reference architecture" in Authoring Guidelines in the public documentation at
https://terraform-ibm-modules.github.io/documentation/#/implementation-guidelines?id=reference-architecture
-->

### Usage

<!--
Expand Down Expand Up @@ -142,7 +77,9 @@ statement instead the previous block.
-->

<!-- No permissions are needed to run this module.-->
<!-- END MODULE HOOK -->


<!-- Below content is automatically populated via pre-commit hook -->
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
### Requirements

Expand All @@ -167,13 +104,9 @@ No inputs.
No outputs.
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

<!-- BEGIN CONTRIBUTING HOOK -->

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

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).

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.
<!-- Source for this readme file: https://github.com/terraform-ibm-modules/common-dev-assets/tree/main/module-assets/ci/module-template-automation -->
<!-- END CONTRIBUTING HOOK -->
2 changes: 1 addition & 1 deletion common-dev-assets
8 changes: 4 additions & 4 deletions cra-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# More info about this file at https://github.com/terraform-ibm-modules/common-pipeline-assets/blob/main/.github/workflows/terraform-test-pipeline.md#cra-config-yaml
version: "v1"
CRA_TARGETS:
- CRA_TARGET: "examples/basic" # Target directory for CRA scan. If not provided, the CRA Scan will not be run.
- CRA_TARGET: "examples/complete" # Target directory for CRA scan. If not provided, the CRA Scan will not be run.
CRA_IGNORE_RULES_FILE: "cra-tf-validate-ignore-rules.json" # CRA Ignore file to use. If not provided, it checks the repo root directory for `cra-tf-validate-ignore-rules.json`
PROFILE_ID: "0e6e7b5a-817d-4344-ab6f-e5d7a9c49520" # SCC profile ID (currently set to the FSCloud 1.4.0 profile).
# SCC_INSTANCE_ID: "" # The SCC instance ID to use to download profile for CRA scan. If not provided, a default global value will be used.
# SCC_REGION: "" # The IBM Cloud region that the SCC instance is in. If not provided, a default global value will be used.
# CRA_ENVIRONMENT_VARIABLES: # An optional map of environment variables for CRA, where the key is the variable name and value is the value. Useful for providing TF_VARs.
# TF_VAR_sample: "sample value"
# TF_VAR_other: "another value"
# SCC_INSTANCE_ID: "" # The SCC instance ID to use to download profile for CRA scan. If not provided, a default global value will be used.
# SCC_REGION: "" # The IBM Cloud region that the SCC instance is in. If not provided, a default global value will be used.
# PROFILE_ID: "" # The Profile ID input for CRA SCC scan. If not provided, a default global value will be used.
7 changes: 5 additions & 2 deletions examples/basic/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Basic example

<!-- There is a pre-commit hook that will take the title of each example add include it in the repos main README.md -->
<!-- The text below should describe exactly what resources are provisioned / configured by the example -->
<!--
The basic example should call the module(s) stored in this repository with a basic configuration.
Note, there is a pre-commit hook that will take the title of each example and include it in the repos main README.md.
The text below should describe exactly what resources are provisioned / configured by the example.
-->

An end-to-end basic example that will provision the following:
- A new resource group if one is not passed in.
Expand Down
8 changes: 4 additions & 4 deletions examples/basic/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
##############################################################################
########################################################################################################################
# Resource group
##############################################################################
########################################################################################################################

module "resource_group" {
source = "terraform-ibm-modules/resource-group/ibm"
Expand All @@ -10,9 +10,9 @@ module "resource_group" {
existing_resource_group_name = var.resource_group
}

##############################################################################
########################################################################################################################
# COS instance
##############################################################################
########################################################################################################################

resource "ibm_resource_instance" "cos_instance" {
name = "${var.prefix}-cos"
Expand Down
4 changes: 2 additions & 2 deletions examples/basic/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
##############################################################################
########################################################################################################################
# Outputs
##############################################################################
########################################################################################################################

output "cos_instance_id" {
description = "COS instance id"
Expand Down
4 changes: 2 additions & 2 deletions examples/basic/provider.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
##############################################################################
########################################################################################################################
# Provider config
##############################################################################
########################################################################################################################

provider "ibm" {
ibmcloud_api_key = var.ibmcloud_api_key
Expand Down
4 changes: 2 additions & 2 deletions examples/basic/variables.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
##############################################################################
########################################################################################################################
# Input variables
##############################################################################
########################################################################################################################

variable "ibmcloud_api_key" {
type = string
Expand Down
4 changes: 2 additions & 2 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
##############################################################################
########################################################################################################################
# Outputs
##############################################################################
########################################################################################################################

#output "myoutput" {
# description = "Description of my output"
Expand Down
3 changes: 0 additions & 3 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<!-- BEGIN TESTS HOOK -->

# Tests

For information about how to create and run tests, see [Validation tests](https://terraform-ibm-modules.github.io/documentation/#/tests) in the project documentation.

<!-- Add any more steps that are specific to testing this module and that are not in the docs. -->
<!-- END TESTS HOOK -->
4 changes: 2 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
##############################################################################
########################################################################################################################
# Input Variables
##############################################################################
########################################################################################################################

#variable "my_variable" {
# type = string
Expand Down
3 changes: 2 additions & 1 deletion version.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
terraform {
required_version = ">= 1.3.0"
# If your module requires any terraform providers, uncomment the "required_providers" section below and add all required providers.
# Each required provider's version should be a flexible range to future proof the module's usage with upcoming minor and patch versions.

# Use a flexible range in modules that future proofs the module's usage with upcoming minor and patch versions
# required_providers {
# ibm = {
# source = "IBM-Cloud/ibm"
Expand Down

0 comments on commit 14a6c3a

Please sign in to comment.