Skip to content

Commit

Permalink
feat: initial release (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocofaigh committed Nov 8, 2022
2 parents 8695e6b + b251c33 commit bed0ef1
Show file tree
Hide file tree
Showing 28 changed files with 230 additions and 305 deletions.
4 changes: 2 additions & 2 deletions .github/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ repository:
# By changing this field, you rename the repository.

# Uncomment this name property and set the name to the current repo name.
# name: ""
name: "terraform-ibm-key-protect-key-ring"

# The description is displayed under the repository name on the
# organization page and in the 'About' section of the repository.

# Uncomment this description property
# and update the description to the current repo description.
# description: ""
description: "Module to create Key Rings in a Key Protect instance"
147 changes: 35 additions & 112 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,159 +1,82 @@
<!-- BEGIN MODULE HOOK -->

<!-- Update the title to match the module name and add a description -->
# Terraform Modules Template Project
# Terraform IBM Key Protect Key Ring Module
<!-- UPDATE BADGE: Update the link for the following badge-->
[![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)
[![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)
[![Stable (With Quality Checks)](https://img.shields.io/badge/Status-Stable%20(With%20quality%20checks)-green?style=plastic)](https://terraform-ibm-modules.github.io/documentation/#/badge-status)
[![Build status](https://github.com/terraform-ibm-modules/terraform-ibm-key-protect-key-ring/actions/workflows/ci.yml/badge.svg)](https://github.com/terraform-ibm-modules/terraform-ibm-key-protect-key-ring/actions/workflows/ci.yml)
[![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)
[![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)
[![latest release](https://img.shields.io/github/v/release/terraform-ibm-modules/terraform-ibm-key-protect-key-ring?logo=GitHub&sort=semver)](https://github.com/terraform-ibm-modules/terraform-ibm-key-protect-key-ring/releases/latest)

<!-- 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
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:

1. Create a PR to enable the upgrade test by removing the `t.Skip` line in `tests/pr_test.go`.

<!-- Remove the content in this previous H2 heading -->
This module creates a Key Ring in the provided Key Protect instance to help organize keys within the instance.

## Usage

<!--
Add an example of the use of the module in the following code block.
Use real values instead of "var.<var_name>" or other placeholder values
unless real values don't help users know what to change.
-->

<!-- Add sample usage of the module itself in the following code block -->
```hcl
##############################################################################
# Key Protect Key Ring
##############################################################################
# Replace "main" with a GIT release version to lock into a specific release
module "key_protect_module" {
source = "git::https://github.com:terraform-ibm-modules/terraform-ibm-key-protect-key-ring.git?ref=main"
endpoint_type = var.endpoint_type
instance_id = var.instance_id
key_ring_id = "${var.prefix}-key-ring"
}
```

## Required IAM access policies

<!-- PERMISSIONS REQUIRED TO RUN MODULE
If this module requires permissions, uncomment the following block and update
the sample permissions, following the format.
Replace the sample Account and IBM Cloud service names and roles with the
information in the console at
Manage > Access (IAM) > Access groups > Access policies.
-->

<!--
You need the following permissions to run this module.

- Account Management
- **Sample Account Service** service
- `Editor` platform access
- **Resource Group** service
- `Viewer` platform access
- IAM Services
- **Key Protect** service
- `Viewer` platform access
- `Manager` service access
- IAM Services
- **Sample Cloud Service** service
- `Administrator` platform access
-->

<!-- NO PERMISSIONS FOR MODULE
If no permissions are required for the module, uncomment the following
statement instead the previous block.
-->

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

- [ Default example](examples/default)
- [ Example that uses existing resources](examples/existing-resources)
- [ Non default example](examples/non-default)
- [ End to end example with default values](examples/default)
<!-- END EXAMPLES HOOK -->
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.0 |
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >= 1.45.0 |

## Modules

No modules.

## Resources

No resources.
| Name | Type |
|------|------|
| [ibm_kms_key_rings.key_ring](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/kms_key_rings) | resource |

## Inputs

No inputs.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_endpoint_type"></a> [endpoint\_type](#input\_endpoint\_type) | The type of endpoint to be used for creating keys, accepts 'public' or 'private' | `string` | `"private"` | no |
| <a name="input_instance_id"></a> [instance\_id](#input\_instance\_id) | The Key Protect instance GUID | `string` | n/a | yes |
| <a name="input_key_ring_id"></a> [key\_ring\_id](#input\_key\_ring\_id) | The ID that identifies the Key Ring, each ID is unique within the given Key Protect instance but is not reserved across the Key Protect service | `string` | n/a | yes |

## Outputs

No outputs.
| Name | Description |
|------|-------------|
| <a name="output_key_ring_id"></a> [key\_ring\_id](#output\_key\_ring\_id) | ID of the Key Ring |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
<!-- BEGIN CONTRIBUTING HOOK -->

Expand Down
5 changes: 3 additions & 2 deletions examples/default/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Default example
# End to end example with default values

An end-to-end example that uses the module's default variable values.
This example uses the IBM Cloud terraform provider to:
- Create a new resource group if one is not passed in.
- Create a new VPC in the resource group and region provided.
- Create a new Key Protect instance in the resource group.
- Create a Key Ring within the Key Protect Instance.

<!-- Add your example and link to it from the module's main readme file. -->
25 changes: 19 additions & 6 deletions examples/default/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,31 @@
##############################################################################

module "resource_group" {
source = "git::https://github.com/terraform-ibm-modules/terraform-ibm-resource-group.git?ref=v1.0.1"
source = "git::https://github.com/terraform-ibm-modules/terraform-ibm-resource-group.git?ref=v1.0.2"
# if an existing resource group is not set (null) create a new one using prefix
resource_group_name = var.resource_group == null ? "${var.prefix}-resource-group" : null
existing_resource_group_name = var.resource_group
}

##############################################################################
# VPC
# Key Protect module
##############################################################################

resource "ibm_is_vpc" "vpc" {
name = "${var.prefix}-vpc"
resource_group = module.resource_group.resource_group_id
tags = var.resource_tags
module "key_protect_module" {
source = "git::https://github.com/terraform-ibm-modules/terraform-ibm-key-protect.git?ref=v1.0.0"
key_protect_name = "${var.prefix}-kp"
resource_group_id = module.resource_group.resource_group_id
region = var.region
tags = var.resource_tags
}

##############################################################################
# Key Ring module
##############################################################################

module "key_protect_key_ring" {
source = "../.."
instance_id = module.key_protect_module.key_protect_guid
key_ring_id = "${var.prefix}-key-ring"
endpoint_type = "public"
}
15 changes: 10 additions & 5 deletions examples/default/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
# Outputs
##############################################################################

output "vpc_id" {
description = "ID of VPC created"
value = ibm_is_vpc.vpc.id
}

output "resource_group_name" {
description = "Resource group name"
value = module.resource_group.resource_group_name
Expand All @@ -16,3 +11,13 @@ output "resource_group_id" {
description = "Resource group ID"
value = module.resource_group.resource_group_id
}

output "key_protect_id" {
description = "Key Protect Instance ID"
value = module.key_protect_module.key_protect_guid
}

output "key_protect_key_ring_id" {
description = "Key Protect Key Ring ID"
value = module.key_protect_key_ring.key_ring_id
}
15 changes: 15 additions & 0 deletions examples/default/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,18 @@ provider "ibm" {
ibmcloud_api_key = var.ibmcloud_api_key
region = var.region
}

data "ibm_iam_auth_token" "token_data" {
}

provider "restapi" {
uri = "https:"
write_returns_object = false
create_returns_object = false
debug = false # set to true to show detailed logs, but use carefully as it might print sensitive values.
headers = {
Authorization = data.ibm_iam_auth_token.token_data.iam_access_token
Bluemix-Instance = module.key_protect_module.key_protect_guid
Content-Type = "application/vnd.ibm.kms.policy+json"
}
}
4 changes: 2 additions & 2 deletions examples/default/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ variable "ibmcloud_api_key" {
variable "region" {
type = string
description = "Region to provision all resources created by this example"
default = "us-south"
default = "eu-gb"
}

variable "prefix" {
type = string
description = "Prefix to append to all resources created by this example"
default = "terraform"
default = "example-kpkr"
}

variable "resource_group" {
Expand Down
5 changes: 5 additions & 0 deletions examples/default/version.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@ terraform {
source = "IBM-Cloud/ibm"
version = "1.45.0"
}
# The restapi provider is not actually required by the module itself, just this example, so OK to use ">=" here instead of locking into a version
restapi = {
source = "Mastercard/restapi"
version = ">= 1.17.0"
}
}
}
3 changes: 0 additions & 3 deletions examples/existing-resources/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions examples/existing-resources/main.tf

This file was deleted.

8 changes: 0 additions & 8 deletions examples/existing-resources/outputs.tf

This file was deleted.

4 changes: 0 additions & 4 deletions examples/existing-resources/provider.tf

This file was deleted.

15 changes: 0 additions & 15 deletions examples/existing-resources/variables.tf

This file was deleted.

10 changes: 0 additions & 10 deletions examples/existing-resources/version.tf

This file was deleted.

5 changes: 0 additions & 5 deletions examples/non-default/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions examples/non-default/main.tf

This file was deleted.

Loading

0 comments on commit bed0ef1

Please sign in to comment.