Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to TF 0.12. Add tests. Add Codefresh test pipeline #9

Merged
merged 9 commits into from
Jan 2, 2020
Merged
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2017 Cloud Posse, LLC
Copyright 2017-2019 Cloud Posse, LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
251 changes: 182 additions & 69 deletions README.md

Large diffs are not rendered by default.

63 changes: 59 additions & 4 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ github_repo: cloudposse/terraform-aws-elasticache-memcached

# Badges to display
badges:
- name: "Build Status"
image: "https://travis-ci.org/cloudposse/terraform-aws-elasticache-memcached.svg?branch=master"
url: "https://travis-ci.org/cloudposse/terraform-aws-elasticache-memcached"
- name: "Codefresh Build Status"
image: "https://g.codefresh.io/api/badges/pipeline/cloudposse/terraform-modules%2Fterraform-aws-elasticache-memcached?type=cf-1"
url: "https%3A%2F%2Fg.codefresh.io%2Fpublic%2Faccounts%2Fcloudposse%2Fpipelines%2F5e0a73156baea5f1b7de7ce0"
- name: "Latest Release"
image: "https://img.shields.io/github/release/cloudposse/terraform-aws-elasticache-memcached.svg"
url: "https://github.com/cloudposse/terraform-aws-elasticache-memcached/releases/latest"
Expand All @@ -53,6 +53,59 @@ related:
description: |-
Terraform module to provision an [`ElastiCache`](https://aws.amazon.com/elasticache/) Memcached Cluster
# How to use this project
usage: |-
For a complete example, see [examples/complete](examples/complete).
For automated tests of the complete example using [bats](https://github.com/bats-core/bats-core) and [Terratest](https://github.com/gruntwork-io/terratest) (which tests and deploys the example on AWS), see [test](test).
```hcl
provider "aws" {
region = var.region
}
module "vpc" {
source = "git::https://github.com/cloudposse/terraform-aws-vpc.git?ref=tags/0.8.1"
namespace = var.namespace
stage = var.stage
name = var.name
cidr_block = "172.16.0.0/16"
}
module "subnets" {
source = "git::https://github.com/cloudposse/terraform-aws-dynamic-subnets.git?ref=tags/0.18.1"
availability_zones = var.availability_zones
namespace = var.namespace
stage = var.stage
name = var.name
vpc_id = module.vpc.vpc_id
igw_id = module.vpc.igw_id
cidr_block = module.vpc.vpc_cidr_block
nat_gateway_enabled = false
nat_instance_enabled = false
}
module "memcached" {
source = "git::https://github.com/cloudposse/terraform-aws-elasticache-memcached.git?ref=master"
namespace = var.namespace
stage = var.stage
name = var.name
availability_zones = var.availability_zones
vpc_id = module.vpc.vpc_id
allowed_security_groups = [module.vpc.vpc_default_security_group_id]
subnets = module.subnets.private_subnet_ids
cluster_size = var.cluster_size
instance_type = var.instance_type
engine_version = var.engine_version
apply_immediately = true
zone_id = var.zone_id
}
```
examples: |-
Review the [complete example](examples/simple) to see how to use this module.
include:
- "docs/targets.md"
- "docs/terraform.md"
Expand All @@ -62,4 +115,6 @@ contributors:
- name: "Igor Rodionov"
github: "goruha"
- name: "Andriy Knysh"
github: "aknysh"
github: "aknysh"
- name: "Erik Osterman"
github: "osterman"
77 changes: 77 additions & 0 deletions codefresh/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
version: '1.0'

stages:
- Prepare
- Test

steps:
wait:
title: Wait
stage: Prepare
image: codefresh/cli:latest
commands:
- codefresh get builds --pipeline=${{CF_REPO_NAME}} --status running --limit 1000 -o json | jq --arg id ${{CF_BUILD_ID}} -ser 'flatten|.[-1].id==$id'
retry:
maxAttempts: 10
delay: 20
exponentialFactor: 1.1

main_clone:
title: "Clone repository"
type: git-clone
stage: Prepare
description: "Initialize"
repo: ${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}
git: CF-default
revision: ${{CF_REVISION}}

clean_init:
title: Prepare build-harness and test-harness
image: ${{TEST_IMAGE}}
stage: Prepare
commands:
- cf_export PATH="/usr/local/terraform/0.12/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
- make init
- git -C build-harness checkout master
- make -C test/ clean init TEST_HARNESS_BRANCH=master
- make -C test/src clean init
- find . -type d -name '.terraform' | xargs rm -rf
- find . -type f -name 'terraform.tfstate*' -exec rm -f {} \;

test:
type: "parallel"
title: "Run tests"
description: "Run all tests in parallel"
stage: Test
steps:
test_readme_lint:
title: "Test README.md updated"
stage: "Test"
image: ${{TEST_IMAGE}}
description: Test "readme/lint"
commands:
- make readme/lint

test_module:
title: Test module with bats
image: ${{TEST_IMAGE}}
stage: Test
commands:
- make -C test/ module

test_examples_complete:
title: Test "examples/complete" with bats
image: ${{TEST_IMAGE}}
stage: Test
commands:
- make -C test/ examples/complete

test_examples_complete_terratest:
title: Test "examples/complete" with terratest
image: ${{TEST_IMAGE}}
stage: Test
commands:
- unset AWS_PROFILE
- unset AWS_DEFAULT_PROFILE
- unset AWS_MFA_PROFILE
- make -C test/src
53 changes: 32 additions & 21 deletions docs/terraform.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,45 @@

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| alarm_actions | Alarm actions | list | `<list>` | no |
| alarm_cpu_threshold_percent | CPU threshold alarm level | string | `75` | no |
| alarm_memory_threshold_bytes | Alarm memory threshold bytes | string | `10000000` | no |
| apply_immediately | Specifies whether any database modifications are applied immediately, or during the next maintenance window | string | `true` | no |
| availability_zones | List of Availability Zones where subnets will be created | list | - | yes |
| cluster_size | Cluster size | string | `1` | no |
| engine_version | Engine version | string | `1.4.33` | no |
| instance_type | Elastic cache instance type | string | `t2.micro` | no |
| alarm_actions | Alarm actions | list(string) | `<list>` | no |
| alarm_cpu_threshold_percent | CPU threshold alarm level | number | `75` | no |
| alarm_memory_threshold_bytes | Alarm memory threshold bytes | number | `10000000` | no |
| allowed_cidr_blocks | List of CIDR blocks that are allowed ingress to the cluster's Security Group created in the module | list(string) | `<list>` | no |
| allowed_security_groups | List of Security Group IDs that are allowed ingress to the cluster's Security Group created in the module | list(string) | `<list>` | no |
| apply_immediately | Specifies whether any database modifications are applied immediately, or during the next maintenance window | bool | `true` | no |
| attributes | Additional attributes (_e.g._ "1") | list(string) | `<list>` | no |
| availability_zones | List of Availability Zones for the cluster | list(string) | - | yes |
| cluster_size | Cluster size | number | `1` | no |
| delimiter | Delimiter between `name`, `namespace`, `stage` and `attributes` | string | `-` | no |
| elasticache_parameter_group_family | ElastiCache parameter group family | string | `memcached1.4` | no |
| elasticache_subnet_group_name | Subnet group name for the ElastiCache instance | string | `` | no |
| enabled | Set to false to prevent the module from creating any resources | bool | `true` | no |
| engine_version | Memcached engine version. For more info, see https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/supported-engine-versions.html | string | `1.5.16` | no |
| existing_security_groups | List of existing Security Group IDs to place the cluster into. Set `use_existing_security_groups` to `true` to enable using `existing_security_groups` as Security Groups for the cluster | list(string) | `<list>` | no |
| instance_type | Elastic cache instance type | string | `cache.t2.micro` | no |
| maintenance_window | Maintenance window | string | `wed:03:00-wed:04:00` | no |
| max_item_size | Max item size | string | `10485760` | no |
| name | The Name of the application or solution (e.g. `bastion` or `portal`) | string | - | yes |
| namespace | Namespace (e.g. `cp` or `cloudposse`) | string | - | yes |
| max_item_size | Max item size | number | `10485760` | no |
| name | Name of the application | string | - | yes |
| namespace | Namespace (e.g. `eg` or `cp`) | string | `` | no |
| notification_topic_arn | Notification topic arn | string | `` | no |
| security_groups | AWS security group ids | list | - | yes |
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | - | yes |
| subnets | AWS subnet ids | list | `<list>` | no |
| port | Memcached port | number | `11211` | no |
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | `` | no |
| subnets | AWS subnet ids | list(string) | `<list>` | no |
| tags | Additional tags (_e.g._ map("BusinessUnit","ABC") | map(string) | `<map>` | no |
| use_existing_security_groups | Flag to enable/disable creation of Security Group in the module. Set to `true` to disable Security Group creation and provide a list of existing security Group IDs in `existing_security_groups` to place the cluster into | bool | `false` | no |
| vpc_id | VPC ID | string | `` | no |
| zone_id | Route53 DNS Zone id | string | `` | no |
| zone_id | Route53 DNS Zone ID | string | `` | no |

## Outputs

| Name | Description |
|------|-------------|
| config_host | Config host |
| hosts | Hosts |
| id | Disambiguated ID |
| port | Port |
| security_group_id | Security group id |
| cluster_address | Cluster address |
| cluster_configuration_endpoint | Cluster configuration endpoint |
| cluster_id | Cluster ID |
| cluster_urls | Cluster URLs |
| config_hostname | Cluster configuration hostname |
| hostname | Cluster hostname |
| security_group_id | Security Group ID |

16 changes: 16 additions & 0 deletions examples/complete/fixtures.us-east-2.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
region = "us-east-2"

availability_zones = ["us-east-2a", "us-east-2b"]

namespace = "eg"

stage = "test"

name = "memcached-test"

instance_type = "cache.t2.micro"

cluster_size = 1

# https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/supported-engine-versions.html
engine_version = "1.5.16"
40 changes: 40 additions & 0 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
provider "aws" {
region = var.region
}

module "vpc" {
source = "git::https://github.com/cloudposse/terraform-aws-vpc.git?ref=tags/0.8.1"
namespace = var.namespace
stage = var.stage
name = var.name
cidr_block = "172.16.0.0/16"
}

module "subnets" {
source = "git::https://github.com/cloudposse/terraform-aws-dynamic-subnets.git?ref=tags/0.18.1"
availability_zones = var.availability_zones
namespace = var.namespace
stage = var.stage
name = var.name
vpc_id = module.vpc.vpc_id
igw_id = module.vpc.igw_id
cidr_block = module.vpc.vpc_cidr_block
nat_gateway_enabled = false
nat_instance_enabled = false
}

module "memcached" {
source = "../../"
namespace = var.namespace
stage = var.stage
name = var.name
availability_zones = var.availability_zones
vpc_id = module.vpc.vpc_id
allowed_security_groups = [module.vpc.vpc_default_security_group_id]
subnets = module.subnets.private_subnet_ids
cluster_size = var.cluster_size
instance_type = var.instance_type
engine_version = var.engine_version
apply_immediately = true
zone_id = var.zone_id
}
49 changes: 49 additions & 0 deletions examples/complete/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
output "public_subnet_cidrs" {
value = module.subnets.public_subnet_cidrs
description = "Public subnet CIDRs"
}

output "private_subnet_cidrs" {
value = module.subnets.private_subnet_cidrs
description = "Private subnet CIDRs"
}

output "vpc_cidr" {
value = module.vpc.vpc_cidr_block
description = "VPC CIDR"
}

output "cluster_id" {
value = module.memcached.cluster_id
description = "Cluster ID"
}

output "security_group_id" {
value = module.memcached.security_group_id
description = "Security Group ID"
}

output "cluster_address" {
value = module.memcached.cluster_address
description = "Cluster address"
}

output "cluster_configuration_endpoint" {
value = module.memcached.cluster_configuration_endpoint
description = "Cluster configuration endpoint"
}

output "hostname" {
value = module.memcached.hostname
description = "Cluster hostname"
}

output "config_hostname" {
value = module.memcached.config_hostname
description = "Cluster configuration hostname"
}

output "cluster_urls" {
value = module.memcached.cluster_urls
description = "Cluster URLs"
}
Loading