Skip to content

Commit 097a2a6

Browse files
authored
Convert to TF 0.12. Add tests. Add Codefresh test pipeline (#6)
* Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline
1 parent 4bdc26f commit 097a2a6

23 files changed

+517
-154
lines changed

.travis.yml

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

README.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
[![Cloud Posse][logo]](https://cpco.io/homepage)
55

6-
# terraform-aws-ssm-tls-ssh-key-pair [![Build Status](https://travis-ci.org/cloudposse/terraform-aws-ssm-tls-ssh-key-pair.svg?branch=master)](https://travis-ci.org/cloudposse/terraform-aws-ssm-tls-ssh-key-pair) [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-aws-ssm-tls-ssh-key-pair.svg)](https://github.com/cloudposse/terraform-aws-ssm-tls-ssh-key-pair/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)
6+
# terraform-aws-ssm-tls-ssh-key-pair [![Codefresh Build Status](https://g.codefresh.io/api/badges/pipeline/cloudposse/terraform-modules%2Fterraform-aws-ssm-tls-ssh-key-pair?type=cf-1)](https://g.codefresh.io/public/accounts/cloudposse/pipelines/5d1ba83195dc307c009861ce) [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-aws-ssm-tls-ssh-key-pair.svg)](https://github.com/cloudposse/terraform-aws-ssm-tls-ssh-key-pair/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)
77

88

99
Terraform module that provisions an SSH TLS key pair and writes it to SSM Parameter Store.
@@ -44,6 +44,11 @@ We literally have [*hundreds of terraform modules*][terraform_modules] that are
4444

4545
## Usage
4646

47+
48+
**IMPORTANT:** The `master` branch is used in `source` just as an example. In your code, do not pin to `master` because there may be breaking changes between releases.
49+
Instead pin to the release tag (e.g. `?ref=tags/x.y.z`) of one of our [latest releases](https://github.com/cloudposse/terraform-aws-ssm-tls-ssh-key-pair/releases).
50+
51+
4752
```hcl
4853
module "ssm_tls_ssh_key_pair" {
4954
source = "git::https://github.com/cloudposse/terraform-aws-ssm-tls-ssh-key-pair.git?ref=master"
@@ -74,28 +79,29 @@ Available targets:
7479

7580
| Name | Description | Type | Default | Required |
7681
|------|-------------|:----:|:-----:|:-----:|
77-
| attributes | Additional attributes (e.g. `1`) | list | `<list>` | no |
82+
| attributes | Additional attributes (e.g. `1`) | list(string) | `<list>` | no |
7883
| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | string | `-` | no |
7984
| ecdsa_curve | When ssh_key_algorithm is 'ECDSA', the name of the elliptic curve to use. May be any one of 'P256', 'P384' or P521' | string | `P256` | no |
80-
| enabled | Whether to create the resources. Set to `false` to prevent the module from creating any resources | string | `true` | no |
85+
| enabled | Whether to create the resources. Set to `false` to prevent the module from creating any resources | bool | `true` | no |
8186
| kms_key_id | KMS Key ID used for encryption | string | `` | no |
8287
| name | Application or solution name (e.g. `app`) | string | - | yes |
83-
| namespace | Namespace (e.g. `eg` or `cp`) | string | - | yes |
84-
| overwrite_ssm_parameter | Whether to overwrite an existing SSM parameter | string | `true` | no |
85-
| rsa_bits | When ssh_key_algorithm is 'RSA', the size of the generated RSA key in bits | string | `4096` | no |
88+
| namespace | Namespace (e.g. `eg` or `cp`) | string | `` | no |
89+
| overwrite_ssm_parameter | Whether to overwrite an existing SSM parameter | bool | `true` | no |
90+
| rsa_bits | When ssh_key_algorithm is 'RSA', the size of the generated RSA key in bits | number | `4096` | no |
8691
| ssh_key_algorithm | SSH key algorithm to use. Currently-supported values are 'RSA' and 'ECDSA' | string | `RSA` | no |
8792
| ssh_private_key_name | SSM Parameter name of the SSH private key | string | `` | no |
8893
| ssh_public_key_name | SSM Parameter name of the SSH public key | string | `` | no |
8994
| ssm_path_format | SSM path format | string | `/%s/%s` | no |
9095
| ssm_path_prefix | The SSM parameter path prefix (e.g. /$ssm_path_prefix/$key_name) | string | `ssh_keys` | no |
91-
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | - | yes |
92-
| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`) | map | `<map>` | no |
96+
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | `` | no |
97+
| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`) | map(string) | `<map>` | no |
9398

9499
## Outputs
95100

96101
| Name | Description |
97102
|------|-------------|
98-
| public_key | Contents of the generated public key |
103+
| key_name | Name of SSH key |
104+
| public_key | Content of the generated public key |
99105

100106

101107

@@ -233,13 +239,15 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
233239

234240
### Contributors
235241

236-
| [![Erik Osterman][osterman_avatar]][osterman_homepage]<br/>[Erik Osterman][osterman_homepage] | [![Josh Myers][joshmyers_avatar]][joshmyers_homepage]<br/>[Josh Myers][joshmyers_homepage] |
237-
|---|---|
242+
| [![Erik Osterman][osterman_avatar]][osterman_homepage]<br/>[Erik Osterman][osterman_homepage] | [![Josh Myers][joshmyers_avatar]][joshmyers_homepage]<br/>[Josh Myers][joshmyers_homepage] | [![Andriy Knysh][aknysh_avatar]][aknysh_homepage]<br/>[Andriy Knysh][aknysh_homepage] |
243+
|---|---|---|
238244

239245
[osterman_homepage]: https://github.com/osterman
240246
[osterman_avatar]: https://github.com/osterman.png?size=150
241247
[joshmyers_homepage]: https://github.com/joshmyers
242248
[joshmyers_avatar]: https://github.com/joshmyers.png?size=150
249+
[aknysh_homepage]: https://github.com/aknysh
250+
[aknysh_avatar]: https://github.com/aknysh.png?size=150
243251

244252

245253

README.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ github_repo: cloudposse/terraform-aws-ssm-tls-ssh-key-pair
1818

1919
# Badges to display
2020
badges:
21-
- name: "Build Status"
22-
image: "https://travis-ci.org/cloudposse/terraform-aws-ssm-tls-ssh-key-pair.svg?branch=master"
23-
url: "https://travis-ci.org/cloudposse/terraform-aws-ssm-tls-ssh-key-pair"
21+
- name: "Codefresh Build Status"
22+
image: "https://g.codefresh.io/api/badges/pipeline/cloudposse/terraform-modules%2Fterraform-aws-ssm-tls-ssh-key-pair?type=cf-1"
23+
url: "https://g.codefresh.io/public/accounts/cloudposse/pipelines/5d1ba83195dc307c009861ce"
2424
- name: "Latest Release"
2525
image: "https://img.shields.io/github/release/cloudposse/terraform-aws-ssm-tls-ssh-key-pair.svg"
2626
url: "https://github.com/cloudposse/terraform-aws-ssm-tls-ssh-key-pair/releases/latest"
@@ -65,3 +65,5 @@ contributors:
6565
github: "osterman"
6666
- name: "Josh Myers"
6767
github: "joshmyers"
68+
- name: "Andriy Knysh"
69+
github: "aknysh"

codefresh/test.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
version: '1.0'
2+
3+
stages:
4+
- Prepare
5+
- Test
6+
7+
steps:
8+
wait:
9+
title: Wait
10+
stage: Prepare
11+
image: codefresh/cli:latest
12+
commands:
13+
- codefresh get builds --pipeline=${{CF_REPO_NAME}} --status running --limit 1000 -o json | jq --arg id ${{CF_BUILD_ID}} -ser 'flatten|.[-1].id==$id'
14+
retry:
15+
maxAttempts: 10
16+
delay: 20
17+
exponentialFactor: 1.1
18+
19+
main_clone:
20+
title: "Clone repository"
21+
type: git-clone
22+
stage: Prepare
23+
description: "Initialize"
24+
repo: ${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}
25+
git: CF-default
26+
revision: ${{CF_REVISION}}
27+
28+
clean_init:
29+
title: Prepare build-harness and test-harness
30+
image: ${{TEST_IMAGE}}
31+
stage: Prepare
32+
commands:
33+
- cf_export PATH="/usr/local/terraform/0.12/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
34+
- make init
35+
- git -C build-harness checkout master
36+
- make -C test/ clean init TEST_HARNESS_BRANCH=master
37+
- make -C test/src clean init
38+
- find . -type d -name '.terraform' | xargs rm -rf
39+
- find . -type f -name 'terraform.tfstate*' -exec rm -f {} \;
40+
41+
test:
42+
type: "parallel"
43+
title: "Run tests"
44+
description: "Run all tests in parallel"
45+
stage: Test
46+
steps:
47+
test_readme_lint:
48+
title: "Test README.md updated"
49+
stage: "Test"
50+
image: ${{TEST_IMAGE}}
51+
description: Test "readme/lint"
52+
commands:
53+
- make readme/lint
54+
55+
test_module:
56+
title: Test module with bats
57+
image: ${{TEST_IMAGE}}
58+
stage: Test
59+
commands:
60+
- make -C test/ module
61+
62+
test_examples_complete:
63+
title: Test "examples/complete" with bats
64+
image: ${{TEST_IMAGE}}
65+
stage: Test
66+
commands:
67+
- make -C test/ examples/complete
68+
69+
test_examples_complete_terratest:
70+
title: Test "examples/complete" with terratest
71+
image: ${{TEST_IMAGE}}
72+
stage: Test
73+
commands:
74+
- make -C test/src

docs/terraform.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,27 @@
22

33
| Name | Description | Type | Default | Required |
44
|------|-------------|:----:|:-----:|:-----:|
5-
| attributes | Additional attributes (e.g. `1`) | list | `<list>` | no |
5+
| attributes | Additional attributes (e.g. `1`) | list(string) | `<list>` | no |
66
| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | string | `-` | no |
77
| ecdsa_curve | When ssh_key_algorithm is 'ECDSA', the name of the elliptic curve to use. May be any one of 'P256', 'P384' or P521' | string | `P256` | no |
8-
| enabled | Whether to create the resources. Set to `false` to prevent the module from creating any resources | string | `true` | no |
8+
| enabled | Whether to create the resources. Set to `false` to prevent the module from creating any resources | bool | `true` | no |
99
| kms_key_id | KMS Key ID used for encryption | string | `` | no |
1010
| name | Application or solution name (e.g. `app`) | string | - | yes |
11-
| namespace | Namespace (e.g. `eg` or `cp`) | string | - | yes |
12-
| overwrite_ssm_parameter | Whether to overwrite an existing SSM parameter | string | `true` | no |
13-
| rsa_bits | When ssh_key_algorithm is 'RSA', the size of the generated RSA key in bits | string | `4096` | no |
11+
| namespace | Namespace (e.g. `eg` or `cp`) | string | `` | no |
12+
| overwrite_ssm_parameter | Whether to overwrite an existing SSM parameter | bool | `true` | no |
13+
| rsa_bits | When ssh_key_algorithm is 'RSA', the size of the generated RSA key in bits | number | `4096` | no |
1414
| ssh_key_algorithm | SSH key algorithm to use. Currently-supported values are 'RSA' and 'ECDSA' | string | `RSA` | no |
1515
| ssh_private_key_name | SSM Parameter name of the SSH private key | string | `` | no |
1616
| ssh_public_key_name | SSM Parameter name of the SSH public key | string | `` | no |
1717
| ssm_path_format | SSM path format | string | `/%s/%s` | no |
1818
| ssm_path_prefix | The SSM parameter path prefix (e.g. /$ssm_path_prefix/$key_name) | string | `ssh_keys` | no |
19-
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | - | yes |
20-
| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`) | map | `<map>` | no |
19+
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | `` | no |
20+
| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`) | map(string) | `<map>` | no |
2121

2222
## Outputs
2323

2424
| Name | Description |
2525
|------|-------------|
26-
| public_key | Contents of the generated public key |
26+
| key_name | Name of SSH key |
27+
| public_key | Content of the generated public key |
2728

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
region = "us-east-1"
1+
region = "us-west-1"
2+
3+
namespace = "eg"
4+
5+
stage = "test"
6+
7+
name = "ssm-tls-ssh-key-pair"
28

39
ssh_public_key_name = "id_rsa.pub"
10+
411
ssh_private_key_name = "id_rsa"
12+
513
ssh_key_algorithm = "ECDSA"
14+
615
ssm_path_prefix = "ssh_keys"

examples/complete/main.tf

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
provider "aws" {
2-
region = "${var.region}"
2+
region = var.region
3+
}
4+
5+
module "kms_key" {
6+
source = "git::https://github.com/cloudposse/terraform-aws-kms-key.git?ref=tags/0.2.0"
7+
namespace = var.namespace
8+
stage = var.stage
9+
name = var.name
10+
description = "Test KMS key"
11+
deletion_window_in_days = 7
12+
enable_key_rotation = false
313
}
414

515
module "ssm_tls_ssh_key_pair" {
616
source = "../../"
7-
namespace = "${var.namespace}"
8-
stage = "${var.stage}"
9-
name = "${var.name}"
10-
attributes = "${var.attributes}"
11-
tags = "${var.tags}"
12-
ssm_path_prefix = "${var.ssm_path_prefix}"
13-
ssh_key_algorithm = "${var.ssh_key_algorithm}"
14-
ssh_private_key_name = "${var.ssh_private_key_name}"
15-
ssh_public_key_name = "${var.ssh_public_key_name}"
16-
enabled = "${var.enabled}"
17+
namespace = var.namespace
18+
stage = var.stage
19+
name = var.name
20+
kms_key_id = module.kms_key.key_id
21+
ssm_path_prefix = var.ssm_path_prefix
22+
ssh_key_algorithm = var.ssh_key_algorithm
23+
ssh_private_key_name = var.ssh_private_key_name
24+
ssh_public_key_name = var.ssh_public_key_name
1725
}

examples/complete/output.tf

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

examples/complete/outputs.tf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
output "ssh_public_key" {
2+
value = module.ssm_tls_ssh_key_pair.public_key
3+
description = "Content of the generated public key"
4+
}
5+
6+
output "ssh_key_name" {
7+
value = module.ssm_tls_ssh_key_pair.key_name
8+
description = "Name of SSH key"
9+
}
10+
11+
output "kms_key_arn" {
12+
value = module.kms_key.key_arn
13+
description = "Key ARN"
14+
}
15+
16+
output "kms_key_id" {
17+
value = module.kms_key.key_id
18+
description = "Key ID"
19+
}
20+
21+
output "kms_alias_arn" {
22+
value = module.kms_key.alias_arn
23+
description = "Alias ARN"
24+
}
25+
26+
output "kms_alias_name" {
27+
value = module.kms_key.alias_name
28+
description = "Alias name"
29+
}

examples/complete/variables.tf

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
variable "region" {
2+
type = "string"
3+
description = "AWS Region"
4+
}
5+
16
variable "namespace" {
27
type = "string"
38
description = "Namespace (e.g. `eg` or `cp`)"
@@ -13,30 +18,6 @@ variable "name" {
1318
description = "Application or solution name (e.g. `app`)"
1419
}
1520

16-
variable "delimiter" {
17-
type = "string"
18-
default = "-"
19-
description = "Delimiter to be used between `namespace`, `stage`, `name` and `attributes`"
20-
}
21-
22-
variable "enabled" {
23-
type = "string"
24-
description = "Whether to create the resources. Set to `false` to prevent the module from creating any resources"
25-
default = "true"
26-
}
27-
28-
variable "attributes" {
29-
type = "list"
30-
default = []
31-
description = "Additional attributes (e.g. `1`)"
32-
}
33-
34-
variable "tags" {
35-
type = "map"
36-
default = {}
37-
description = "Additional tags (e.g. map(`BusinessUnit`,`XYZ`)"
38-
}
39-
4021
variable "ssh_public_key_name" {
4122
type = "string"
4223
description = "SSM Parameter name of the SSH public key"
@@ -56,8 +37,3 @@ variable "ssm_path_prefix" {
5637
type = "string"
5738
description = "The SSM parameter path prefix"
5839
}
59-
60-
variable "region" {
61-
type = "string"
62-
description = "AWS Region"
63-
}

0 commit comments

Comments
 (0)