Skip to content
This repository was archived by the owner on Jul 3, 2023. It is now read-only.

Commit 8336506

Browse files
kavya498hkantare
authored andcommitted
Merge instance and key to one module
1 parent 1cf233f commit 8336506

32 files changed

+338
-495
lines changed

.github/workflows/test.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: "test-scheduler"
2+
3+
on:
4+
workflow_dispatch:
5+
6+
7+
schedule:
8+
- cron: '*/30 5 * * *' # triggers the workflow every day at 5:30 UTC
9+
10+
# ┌───────────── minute (0 - 59)
11+
# │ ┌───────────── hour (0 - 23)
12+
# │ │ ┌───────────── day of the month (1 - 31)
13+
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
14+
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
15+
# │ │ │ │ │
16+
# │ │ │ │ │
17+
# │ │ │ │ │
18+
# * * * * *
19+
20+
jobs:
21+
continuous-tests:
22+
name: Run Test cases
23+
runs-on: ubuntu-latest
24+
steps:
25+
-
26+
name: checkout # action checks-out your repository under $GITHUB_WORKSPACE, so your workflow can access it.
27+
uses: actions/checkout@v2
28+
29+
- uses: actions/setup-go@v2
30+
with:
31+
go-version: 1.15
32+
33+
- name: Install dependencies
34+
run: |
35+
go get -u "github.com/gruntwork-io/terratest/modules/random"
36+
go get -u "github.com/gruntwork-io/terratest/modules/terraform"
37+
38+
-
39+
name: setup terraform
40+
uses: hashicorp/setup-terraform@v1 # sets up Terraform CLI in your GitHub Actions workflow
41+
with:
42+
terraform_version: 0.13.0
43+
44+
- name: Run Test
45+
working-directory: test
46+
run: go test -v ./...
47+
env:
48+
IC_API_KEY: ${{ secrets.ACCESS_KEY }}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: ci
2+
3+
on: [ push, pull_request ]
4+
5+
jobs:
6+
terraform_validate:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: prepare
10+
# tfswitch command line tool lets you switch between different versions of terraform.
11+
# If you do not have a particular version of terraform installed, tfswitch will download the version you desire.
12+
run: |
13+
echo "$HOME/.bin" >> $GITHUB_PATH
14+
curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh > /tmp/tfswitch-install.sh
15+
chmod +x /tmp/tfswitch-install.sh
16+
/tmp/tfswitch-install.sh -b $HOME/.bin
17+
-
18+
name: checkout # action checks-out your repository under $GITHUB_WORKSPACE, so your workflow can access it.
19+
uses: actions/checkout@v2
20+
-
21+
name: setup terraform
22+
uses: hashicorp/setup-terraform@v1 # sets up Terraform CLI in your GitHub Actions workflow
23+
with:
24+
terraform_version: 0.13.0
25+
-
26+
name: Install pre-commit
27+
run: pip install pre-commit
28+
-
29+
name: Run pre-commit command
30+
run: pre-commit run -a
31+
-
32+
name: terraform init # initialize a working directory containing Terraform configuration files.
33+
run: find . -type f -name "*.tf" -exec dirname {} \;|sort -u | while read m; do (cd "$m" && echo "$m - init" && terraform init -input=false -backend=false) || exit 1; done
34+
-
35+
name: terraform validate # validates the configuration files in a directory
36+
run: find . -name ".terraform" -prune -o -type f -name "*.tf" -exec dirname {} \;|sort -u | while read m; do (cd "$m" && echo "$m - validate" && terraform validate && echo "√ $m") || exit 1 ; done
37+
-
38+
name: terraform fmt check # perform format checks
39+
run: terraform fmt -list=true -write=false -check -recursive

.gitignore

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
terraform.tfstate
2-
terraform.tfstate.backup
3-
terraform.tfplan
4-
.terraform.tfstate.lock.info
5-
.terraform
1+
# Local .terraform directories
2+
**/.terraform/*
3+
# .tfstate files
4+
*.tfstate
5+
*.tfstate.*
6+
*.terraform.lock.hcl
7+
# Crash log files
8+
crash.log
9+
# Exclude all .tfvars files, which are likely to contain sentitive data, such as
10+
# password, private keys, and other secrets. These should not be part of version
11+
# control as they are data points which are potentially sensitive and subject
12+
# to change depending on the environment.
13+

.pre-commit-config.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
default_stages: [commit]
2+
# TFLint : Checks for possible errors, best practices, etc. It will also help identify provider-specific issues before errors occur during a Terraform run.
3+
# TFSec : Uses static analysis of your Terraform templates to spot potential security issues. TFSec checks for sensitive data inclusion
4+
# Terraform Docs : Utility to automatically generate documentation from Terraform modules and base repositories in various output formats.
5+
# Terraform Fmt : Used to rewrite Terraform configuration files to a canonical format and style.
6+
# Terraform Validate : Validates the configuration files in a directory, referring only to the configuration and not accessing any remote services such as remote state, provider APIs, etc
7+
repos:
8+
- repo: git://github.com/antonbabenko/pre-commit-terraform
9+
rev: v1.45.0
10+
hooks:
11+
- id: terraform_fmt
12+
- repo: git://github.com/pre-commit/pre-commit-hooks
13+
rev: v3.4.0
14+
hooks:
15+
- id: check-merge-conflict
16+
- id: trailing-whitespace
17+
- id: detect-private-key

README.md

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,33 @@
11
# terraform-ibm-kms
2+
23
Terraform modules to create and work with IBM Key Management Service
34

4-
The supported modules are
5-
* [Provisioning Key protect Instance](./modules/instance)
6-
* [Creating or Importing Key Protect Key](./modules/key)
5+
The supported modules are
6+
7+
* [Provision and manage Key protect Instance and its keys](./modules/key-protect)
78

89
## Example Usage
9-
```
10-
data "ibm_resource_group" "resource_group" {
11-
name = var.resource_group
12-
}
1310

14-
module "kms_instance" {
15-
source = "terraform-ibm-modules/kms/ibm//modules/instance"
11+
``` terraform
12+
module "kms_key" {
13+
source = "../../modules/key-protect"
14+
is_kp_instance_exist = false
1615
resource_group_id = data.ibm_resource_group.resource_group.id
1716
service_name = var.service_name
1817
location = var.location
1918
plan = "tiered-pricing"
2019
tags = var.tags
2120
allowed_network_policy = var.allowed_network_policy
22-
}
23-
24-
module "kms_key" {
25-
source = "terraform-ibm-modules/kms/ibm//modules/key"
26-
kms_instance_guid = module.kms_instance.kms_instance-guid
27-
name = var.name
21+
key_name = var.key_name
2822
standard_key_type = var.standard_key_type
2923
force_delete = var.force_delete
3024
network_access_allowed = var.network_access_allowed
3125
}
32-
3326
```
3427

3528
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
3629
## Inputs
30+
3731
| Name | Description | Type |Default |Required |
3832
|--------------------------|----------------------------------------------------------------|:-------|:--------|:--------|
3933
| resource\_group | Name of the resource group |`string`| n/a | yes |
@@ -42,26 +36,41 @@ module "kms_key" {
4236
| tags | Tags for the KMS Instance |`set` | n/a | no |
4337
| allowed_network_policy | Types of the service endpoints. |`string`| n/a | no |
4438
| kms_instance_guid | GUID of the Instance |`string`| n/a | yes |
45-
| name | Name of the Key |`string`| n/a | yes |
39+
| key_name | Name of the Key |`string`| n/a | yes |
4640
| standard_key_type | Determines if it has to be a standard key or root key |`bool` | false | no |
4741
| force_delete | Determines if it has to be force deleted |`bool` | false | no |
4842
| network_access_allowed | public or private |`string`| `public`| no |
4943

5044
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
5145

52-
## NOTE: If we want to make use of a particular version of module, then set the argument "version" to respective module version.
46+
## NOTE: If we want to make use of a particular version of module, then set the argument "version" to respective module version
47+
5348
## Usage
5449

55-
To run this example you need to execute:
50+
Initialising Provider
51+
52+
Make sure you declare a required providers ibm block to make use of IBM-Cloud Terraform Provider
53+
54+
```terraform
55+
terraform {
56+
required_providers {
57+
ibm = {
58+
source = "IBM-Cloud/ibm"
59+
version = "<version>" // Specify the version
60+
}
61+
}
62+
}
63+
```
5664

5765
```bash
58-
$ terraform init
59-
$ terraform plan
60-
$ terraform apply
66+
terraform init
67+
terraform plan
68+
terraform apply
6169
```
6270

6371
Run `terraform destroy` when you don't need these resources.
6472

65-
## Note:
73+
## Note
74+
6675
* All optional fields are given value `null` in varaible.tf file. User can configure the same by overwriting with appropriate values.
67-
* Provide `version` attribute in terraform block in versions.tf file to use specific version of terraform provider
76+
* Provide `version` attribute in terraform block in versions.tf file to use specific version of terraform provider.

examples/import-key/main.tf

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

examples/import-key/versions.tf

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

examples/instance/README.md

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

examples/instance/main.tf

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

examples/instance/outputs.tf

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

0 commit comments

Comments
 (0)