Skip to content

Commit 3f6856a

Browse files
authored
Convert to TF 0.12. Add tests. Add Codefresh test pipeline (#44)
* Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline
1 parent 307e630 commit 3f6856a

26 files changed

+750
-306
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
*.iml
99

1010
**/.build-harness
11-
**/build-harness
11+
**/build-harness

.travis.yml

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

README.md

Lines changed: 38 additions & 39 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-elasticache-redis [![Build Status](https://travis-ci.org/cloudposse/terraform-aws-elasticache-redis.svg?branch=master)](https://travis-ci.org/cloudposse/terraform-aws-elasticache-redis) [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-aws-elasticache-redis.svg)](https://github.com/cloudposse/terraform-aws-elastic-beanstalk-environment/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)
6+
# terraform-aws-elasticache-redis [![Codefresh Build Status](https://g.codefresh.io/api/badges/pipeline/cloudposse/terraform-modules%2Fterraform-aws-elasticache-redis?type=cf-1)](https://g.codefresh.io/public/accounts/cloudposse/pipelines/5d23a11695dc3006a29862e2) [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-aws-elasticache-redis.svg)](https://github.com/cloudposse/terraform-aws-elastic-beanstalk-environment/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)
77

88

99
Terraform module to provision an [`ElastiCache`](https://aws.amazon.com/elasticache/) Redis Cluster
@@ -57,29 +57,28 @@ resource "random_string" "auth_token" {
5757
5858
module "example_redis" {
5959
source = "git::https://github.com/cloudposse/terraform-aws-elasticache-redis.git?ref=master"
60-
namespace = "general"
60+
namespace = "eg"
61+
stage = "dev"
6162
name = "redis"
62-
stage = "prod"
63-
zone_id = "${var.route53_zone_id}"
64-
security_groups = ["${var.security_group_id}"]
63+
zone_id = var.route53_zone_id
64+
security_groups = [var.security_group_id]
6565
66-
auth_token = "${random_string.auth_token.result}"
67-
vpc_id = "${var.vpc_id}"
68-
subnets = "${var.private_subnets}"
66+
auth_token = random_string.auth_token.result
67+
vpc_id = var.vpc_id
68+
subnets = var.private_subnets
6969
maintenance_window = "wed:03:00-wed:04:00"
70-
cluster_size = "2"
70+
cluster_size = 2
7171
instance_type = "cache.t2.micro"
7272
engine_version = "4.0.10"
73-
alarm_cpu_threshold_percent = "${var.cache_alarm_cpu_threshold_percent}"
74-
alarm_memory_threshold_bytes = "${var.cache_alarm_memory_threshold_bytes}"
75-
apply_immediately = "true"
76-
availability_zones = "${var.availability_zones}"
77-
78-
automatic_failover = "false"
73+
alarm_cpu_threshold_percent = var.cache_alarm_cpu_threshold_percent
74+
alarm_memory_threshold_bytes = var.cache_alarm_memory_threshold_bytes
75+
apply_immediately = true
76+
availability_zones = var.availability_zones
77+
automatic_failover = false
7978
}
8079
8180
output "auth_token" {
82-
value = "${random_string.auth_token.result}"
81+
value = random_string.auth_token.result
8382
}
8483
```
8584

@@ -106,37 +105,37 @@ Available targets:
106105

107106
| Name | Description | Type | Default | Required |
108107
|------|-------------|:----:|:-----:|:-----:|
109-
| alarm_actions | Alarm action list | list | `<list>` | no |
110-
| alarm_cpu_threshold_percent | CPU threshold alarm level | string | `75` | no |
111-
| alarm_memory_threshold_bytes | Ram threshold alarm level | string | `10000000` | no |
112-
| apply_immediately | Apply changes immediately | string | `true` | no |
113-
| at_rest_encryption_enabled | Enable encryption at rest | string | `false` | no |
114-
| attributes | Additional attributes (_e.g._ "1") | list | `<list>` | no |
115-
| auth_token | Auth token for password protecting redis, transit_encryption_enabled must be set to 'true'! Password must be longer than 16 chars | string | `` | no |
116-
| automatic_failover | Automatic failover (Not available for T1/T2 instances) | string | `false` | no |
117-
| availability_zones | Availability zone ids | list | `<list>` | no |
118-
| cluster_size | Count of nodes in cluster | string | `1` | no |
108+
| alarm_actions | Alarm action list | list(string) | `<list>` | no |
109+
| alarm_cpu_threshold_percent | CPU threshold alarm level | number | `75` | no |
110+
| alarm_memory_threshold_bytes | Ram threshold alarm level | number | `10000000` | no |
111+
| apply_immediately | Apply changes immediately | bool | `true` | no |
112+
| at_rest_encryption_enabled | Enable encryption at rest | bool | `false` | no |
113+
| attributes | Additional attributes (_e.g._ "1") | list(string) | `<list>` | no |
114+
| auth_token | Auth token for password protecting redis, `transit_encryption_enabled` must be set to `true`. Password must be longer than 16 chars | string | `` | no |
115+
| automatic_failover | Automatic failover (Not available for T1/T2 instances) | bool | `false` | no |
116+
| availability_zones | Availability zone IDs | list(string) | `<list>` | no |
117+
| cluster_size | Count of nodes in cluster | number | `1` | no |
119118
| delimiter | Delimiter between `name`, `namespace`, `stage` and `attributes` | string | `-` | no |
120119
| elasticache_subnet_group_name | Subnet group name for the ElastiCache instance | string | `` | no |
121-
| enabled | Set to false to prevent the module from creating any resources | string | `true` | no |
120+
| enabled | Set to false to prevent the module from creating any resources | bool | `true` | no |
122121
| engine_version | Redis engine version | string | `4.0.10` | no |
123122
| family | Redis family | string | `redis4.0` | no |
124123
| instance_type | Elastic cache instance type | string | `cache.t2.micro` | no |
125124
| maintenance_window | Maintenance window | string | `wed:03:00-wed:04:00` | no |
126-
| name | Name | string | `redis` | no |
127-
| namespace | Namespace | string | `global` | no |
125+
| name | Name of the application | string | - | yes |
126+
| namespace | Namespace (e.g. `eg` or `cp`) | string | `` | no |
128127
| notification_topic_arn | Notification topic arn | string | `` | no |
129-
| ok_actions | The list of actions to execute when this alarm transitions into an OK state from any other state. Each action is specified as an Amazon Resource Number (ARN) | list | `<list>` | no |
130-
| parameter | A list of Redis parameters to apply. Note that parameters may differ from one Redis family to another | list | `<list>` | no |
131-
| port | Redis port | string | `6379` | no |
128+
| ok_actions | The list of actions to execute when this alarm transitions into an OK state from any other state. Each action is specified as an Amazon Resource Number (ARN) | list(string) | `<list>` | no |
129+
| parameter | A list of Redis parameters to apply. Note that parameters may differ from one Redis family to another | object | `<list>` | no |
130+
| port | Redis port | number | `6379` | no |
132131
| replication_group_id | Replication group ID with the following constraints: A name must contain from 1 to 20 alphanumeric characters or hyphens. The first character must be a letter. A name cannot end with a hyphen or contain two consecutive hyphens. | string | `` | no |
133-
| security_groups | AWS security group ids | list | `<list>` | no |
134-
| stage | Stage | string | `default` | no |
135-
| subnets | AWS subnet IDs | list | `<list>` | no |
136-
| tags | Additional tags (_e.g._ map("BusinessUnit","ABC") | map | `<map>` | no |
137-
| transit_encryption_enabled | Enable TLS | string | `true` | no |
138-
| vpc_id | AWS VPC id | string | - | yes |
139-
| zone_id | Route53 DNS Zone id | string | `` | no |
132+
| security_groups | Security Group IDs | list(string) | `<list>` | no |
133+
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | `` | no |
134+
| subnets | Subnet IDs | list(string) | `<list>` | no |
135+
| tags | Additional tags (_e.g._ map("BusinessUnit","ABC") | map(string) | `<map>` | no |
136+
| transit_encryption_enabled | Enable TLS | bool | `true` | no |
137+
| vpc_id | VPC ID | string | - | yes |
138+
| zone_id | Route53 DNS Zone ID | string | `` | no |
140139

141140
## Outputs
142141

README.yaml

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ github_repo: cloudposse/terraform-aws-elasticache-redis
3232

3333
# Badges to display
3434
badges:
35-
- name: "Build Status"
36-
image: "https://travis-ci.org/cloudposse/terraform-aws-elasticache-redis.svg?branch=master"
37-
url: "https://travis-ci.org/cloudposse/terraform-aws-elasticache-redis"
35+
- name: "Codefresh Build Status"
36+
image: "https://g.codefresh.io/api/badges/pipeline/cloudposse/terraform-modules%2Fterraform-aws-elasticache-redis?type=cf-1"
37+
url: "https://g.codefresh.io/public/accounts/cloudposse/pipelines/5d23a11695dc3006a29862e2"
3838
- name: "Latest Release"
3939
image: "https://img.shields.io/github/release/cloudposse/terraform-aws-elasticache-redis.svg"
4040
url: "https://github.com/cloudposse/terraform-aws-elastic-beanstalk-environment/releases/latest"
@@ -58,29 +58,28 @@ usage: |-
5858
5959
module "example_redis" {
6060
source = "git::https://github.com/cloudposse/terraform-aws-elasticache-redis.git?ref=master"
61-
namespace = "general"
61+
namespace = "eg"
62+
stage = "dev"
6263
name = "redis"
63-
stage = "prod"
64-
zone_id = "${var.route53_zone_id}"
65-
security_groups = ["${var.security_group_id}"]
64+
zone_id = var.route53_zone_id
65+
security_groups = [var.security_group_id]
6666
67-
auth_token = "${random_string.auth_token.result}"
68-
vpc_id = "${var.vpc_id}"
69-
subnets = "${var.private_subnets}"
67+
auth_token = random_string.auth_token.result
68+
vpc_id = var.vpc_id
69+
subnets = var.private_subnets
7070
maintenance_window = "wed:03:00-wed:04:00"
71-
cluster_size = "2"
71+
cluster_size = 2
7272
instance_type = "cache.t2.micro"
7373
engine_version = "4.0.10"
74-
alarm_cpu_threshold_percent = "${var.cache_alarm_cpu_threshold_percent}"
75-
alarm_memory_threshold_bytes = "${var.cache_alarm_memory_threshold_bytes}"
76-
apply_immediately = "true"
77-
availability_zones = "${var.availability_zones}"
78-
79-
automatic_failover = "false"
74+
alarm_cpu_threshold_percent = var.cache_alarm_cpu_threshold_percent
75+
alarm_memory_threshold_bytes = var.cache_alarm_memory_threshold_bytes
76+
apply_immediately = true
77+
availability_zones = var.availability_zones
78+
automatic_failover = false
8079
}
8180
8281
output "auth_token" {
83-
value = "${random_string.auth_token.result}"
82+
value = random_string.auth_token.result
8483
}
8584
```
8685

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: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,37 @@
22

33
| Name | Description | Type | Default | Required |
44
|------|-------------|:----:|:-----:|:-----:|
5-
| alarm_actions | Alarm action list | list | `<list>` | no |
6-
| alarm_cpu_threshold_percent | CPU threshold alarm level | string | `75` | no |
7-
| alarm_memory_threshold_bytes | Ram threshold alarm level | string | `10000000` | no |
8-
| apply_immediately | Apply changes immediately | string | `true` | no |
9-
| at_rest_encryption_enabled | Enable encryption at rest | string | `false` | no |
10-
| attributes | Additional attributes (_e.g._ "1") | list | `<list>` | no |
11-
| auth_token | Auth token for password protecting redis, transit_encryption_enabled must be set to 'true'! Password must be longer than 16 chars | string | `` | no |
12-
| automatic_failover | Automatic failover (Not available for T1/T2 instances) | string | `false` | no |
13-
| availability_zones | Availability zone ids | list | `<list>` | no |
14-
| cluster_size | Count of nodes in cluster | string | `1` | no |
5+
| alarm_actions | Alarm action list | list(string) | `<list>` | no |
6+
| alarm_cpu_threshold_percent | CPU threshold alarm level | number | `75` | no |
7+
| alarm_memory_threshold_bytes | Ram threshold alarm level | number | `10000000` | no |
8+
| apply_immediately | Apply changes immediately | bool | `true` | no |
9+
| at_rest_encryption_enabled | Enable encryption at rest | bool | `false` | no |
10+
| attributes | Additional attributes (_e.g._ "1") | list(string) | `<list>` | no |
11+
| auth_token | Auth token for password protecting redis, `transit_encryption_enabled` must be set to `true`. Password must be longer than 16 chars | string | `` | no |
12+
| automatic_failover | Automatic failover (Not available for T1/T2 instances) | bool | `false` | no |
13+
| availability_zones | Availability zone IDs | list(string) | `<list>` | no |
14+
| cluster_size | Count of nodes in cluster | number | `1` | no |
1515
| delimiter | Delimiter between `name`, `namespace`, `stage` and `attributes` | string | `-` | no |
1616
| elasticache_subnet_group_name | Subnet group name for the ElastiCache instance | string | `` | no |
17-
| enabled | Set to false to prevent the module from creating any resources | string | `true` | no |
17+
| enabled | Set to false to prevent the module from creating any resources | bool | `true` | no |
1818
| engine_version | Redis engine version | string | `4.0.10` | no |
1919
| family | Redis family | string | `redis4.0` | no |
2020
| instance_type | Elastic cache instance type | string | `cache.t2.micro` | no |
2121
| maintenance_window | Maintenance window | string | `wed:03:00-wed:04:00` | no |
22-
| name | Name | string | `redis` | no |
23-
| namespace | Namespace | string | `global` | no |
22+
| name | Name of the application | string | - | yes |
23+
| namespace | Namespace (e.g. `eg` or `cp`) | string | `` | no |
2424
| notification_topic_arn | Notification topic arn | string | `` | no |
25-
| ok_actions | The list of actions to execute when this alarm transitions into an OK state from any other state. Each action is specified as an Amazon Resource Number (ARN) | list | `<list>` | no |
26-
| parameter | A list of Redis parameters to apply. Note that parameters may differ from one Redis family to another | list | `<list>` | no |
27-
| port | Redis port | string | `6379` | no |
25+
| ok_actions | The list of actions to execute when this alarm transitions into an OK state from any other state. Each action is specified as an Amazon Resource Number (ARN) | list(string) | `<list>` | no |
26+
| parameter | A list of Redis parameters to apply. Note that parameters may differ from one Redis family to another | object | `<list>` | no |
27+
| port | Redis port | number | `6379` | no |
2828
| replication_group_id | Replication group ID with the following constraints: A name must contain from 1 to 20 alphanumeric characters or hyphens. The first character must be a letter. A name cannot end with a hyphen or contain two consecutive hyphens. | string | `` | no |
29-
| security_groups | AWS security group ids | list | `<list>` | no |
30-
| stage | Stage | string | `default` | no |
31-
| subnets | AWS subnet IDs | list | `<list>` | no |
32-
| tags | Additional tags (_e.g._ map("BusinessUnit","ABC") | map | `<map>` | no |
33-
| transit_encryption_enabled | Enable TLS | string | `true` | no |
34-
| vpc_id | AWS VPC id | string | - | yes |
35-
| zone_id | Route53 DNS Zone id | string | `` | no |
29+
| security_groups | Security Group IDs | list(string) | `<list>` | no |
30+
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | `` | no |
31+
| subnets | Subnet IDs | list(string) | `<list>` | no |
32+
| tags | Additional tags (_e.g._ map("BusinessUnit","ABC") | map(string) | `<map>` | no |
33+
| transit_encryption_enabled | Enable TLS | bool | `true` | no |
34+
| vpc_id | VPC ID | string | - | yes |
35+
| zone_id | Route53 DNS Zone ID | string | `` | no |
3636

3737
## Outputs
3838

examples/basic/main.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module "elasticsearch" {
2+
source = "../../"
3+
namespace = "eg"
4+
stage = "dev"
5+
name = "es"
6+
dns_zone_id = "Z14EN2YD427LRQ"
7+
security_groups = ["sg-XXXXXXXXX", "sg-YYYYYYYY"]
8+
vpc_id = "vpc-XXXXXXXXX"
9+
subnet_ids = ["subnet-XXXXXXXXX", "subnet-YYYYYYYY"]
10+
zone_awareness_enabled = "true"
11+
elasticsearch_version = "6.5"
12+
instance_type = "t2.small.elasticsearch"
13+
instance_count = 4
14+
iam_role_arns = ["arn:aws:iam::XXXXXXXXX:role/ops", "arn:aws:iam::XXXXXXXXX:role/dev"]
15+
iam_actions = ["es:ESHttpGet", "es:ESHttpPut", "es:ESHttpPost"]
16+
encrypt_at_rest_enabled = "true"
17+
kibana_subdomain_name = "kibana-es"
18+
19+
advanced_options = {
20+
rest.action.multi.allow_explicit_index = "true"
21+
}
22+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
region = "us-west-1"
2+
3+
availability_zones = ["us-west-1b", "us-west-1c"]
4+
5+
namespace = "eg"
6+
7+
stage = "test"
8+
9+
name = "redis-test"
10+
11+
instance_type = "cache.t2.micro"
12+
13+
cluster_size = 1
14+
15+
family = "redis4.0"
16+
17+
engine_version = "4.0.10"
18+
19+
at_rest_encryption_enabled = false
20+
21+
transit_encryption_enabled = true
22+
23+
zone_id = "Z3SO0TKDDQ0RGG"

0 commit comments

Comments
 (0)