Skip to content

Commit

Permalink
Add tests (#41)
Browse files Browse the repository at this point in the history
* Update README

* Add `codefresh.yml`

* Update README

* Test README
  • Loading branch information
aknysh authored and osterman committed May 27, 2019
1 parent 8ac35bc commit 5f28e20
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 10 deletions.
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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

# terraform-null-label [![Build Status](https://travis-ci.org/cloudposse/terraform-null-label.svg?branch=master)](https://travis-ci.org/cloudposse/terraform-null-label) [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-null-label.svg)](https://github.com/cloudposse/terraform-null-label/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)
# terraform-null-label [![Codefresh Build Status](https://g.codefresh.io/api/badges/pipeline/cloudposse/cloudposse%2Fterraform-null-label%2Ftest?type=cf-1)](https://g.codefresh.io/public/accounts/cloudposse/pipelines/cloudposse/terraform-null-label/test) [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-null-label.svg)](https://github.com/cloudposse/terraform-null-label/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)


Terraform module designed to generate consistent label names and tags for resources. Use `terraform-null-label` to implement a strict naming convention.
Expand Down Expand Up @@ -54,6 +54,11 @@ We literally have [*hundreds of terraform modules*][terraform_modules] that are

## Usage


**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.
Instead pin to the release tag (e.g. `?ref=tags/x.y.z`) of one of our [latest releases](https://github.com/cloudposse/terraform-null-label/releases).


### Simple Example

```hcl
Expand All @@ -64,7 +69,11 @@ module "eg_prod_bastion_label" {
name = "bastion"
attributes = ["public"]
delimiter = "-"
tags = "${map("BusinessUnit", "XYZ", "Snapshot", "true")}"
tags = {
"BusinessUnit" = "XYZ",
"Snapshot" = "true"
}
}
```

Expand Down Expand Up @@ -109,7 +118,11 @@ module "eg_prod_bastion_abc_label" {
name = "bastion"
attributes = ["abc"]
delimiter = "-"
tags = "${map("BusinessUnit", "ABC")}"
tags = {
"BusinessUnit" = "XYZ",
"Snapshot" = "true"
}
}
resource "aws_security_group" "eg_prod_bastion_abc" {
Expand All @@ -136,7 +149,11 @@ module "eg_prod_bastion_xyz_label" {
name = "bastion"
attributes = ["xyz"]
delimiter = "-"
tags = "${map("BusinessUnit", "XYZ")}"
tags = {
"BusinessUnit" = "XYZ",
"Snapshot" = "true"
}
}
resource "aws_security_group" "eg_prod_bastion_xyz" {
Expand Down
24 changes: 18 additions & 6 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ github_repo: cloudposse/terraform-null-label

# Badges to display
badges:
- name: "Build Status"
image: "https://travis-ci.org/cloudposse/terraform-null-label.svg?branch=master"
url: "https://travis-ci.org/cloudposse/terraform-null-label"
- name: "Codefresh Build Status"
image: "https://g.codefresh.io/api/badges/pipeline/cloudposse/cloudposse%2Fterraform-null-label%2Ftest?type=cf-1"
url: "https://g.codefresh.io/public/accounts/cloudposse/pipelines/cloudposse/terraform-null-label/test"
- name: "Latest Release"
image: "https://img.shields.io/github/release/cloudposse/terraform-null-label.svg"
url: "https://github.com/cloudposse/terraform-null-label/releases/latest"
Expand Down Expand Up @@ -75,7 +75,11 @@ usage: |-
name = "bastion"
attributes = ["public"]
delimiter = "-"
tags = "${map("BusinessUnit", "XYZ", "Snapshot", "true")}"
tags = {
"BusinessUnit" = "XYZ",
"Snapshot" = "true"
}
}
```
Expand Down Expand Up @@ -120,7 +124,11 @@ usage: |-
name = "bastion"
attributes = ["abc"]
delimiter = "-"
tags = "${map("BusinessUnit", "ABC")}"
tags = {
"BusinessUnit" = "XYZ",
"Snapshot" = "true"
}
}
resource "aws_security_group" "eg_prod_bastion_abc" {
Expand All @@ -147,7 +155,11 @@ usage: |-
name = "bastion"
attributes = ["xyz"]
delimiter = "-"
tags = "${map("BusinessUnit", "XYZ")}"
tags = {
"BusinessUnit" = "XYZ",
"Snapshot" = "true"
}
}
resource "aws_security_group" "eg_prod_bastion_xyz" {
Expand Down
51 changes: 51 additions & 0 deletions codefresh/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
version: '1.0'

stages:
- Prepare
- Test

steps:
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:
- make init
- make -C test/ clean init

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
image: ${{TEST_IMAGE}}
stage: Test
commands:
- make -C test/ module

test_examples_complete:
title: Test "examples/complete"
image: ${{TEST_IMAGE}}
stage: Test
commands:
- make -C test/ examples/complete
1 change: 1 addition & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.test-harness
41 changes: 41 additions & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
TEST_HARNESS ?= https://github.com/cloudposse/test-harness.git
TEST_HARNESS_BRANCH ?= master
TEST_HARNESS_PATH = $(realpath .test-harness)
BATS_ARGS ?= --tap
BATS_LOG ?= test.log

# Define a macro to run the tests
define RUN_TESTS
@echo "Running tests in $(1)"
@cd $(1) && bats $(BATS_ARGS) $(addsuffix .bats,$(addprefix $(TEST_HARNESS_PATH)/test/terraform/,$(TESTS)))
endef

default: all

# Provision the test-harnesss
.test-harness:
[ -d $@ ] || git clone --depth=1 -b $(TEST_HARNESS_BRANCH) $(TEST_HARNESS) $@

# Initialize the tests
init: .test-harness

# Clean up the test harness
clean:
[ "$(TEST_HARNESS_PATH)" == "/" ] || rm -rf $(TEST_HARNESS_PATH)

# Run all tests
all: module examples/complete

# Install all dependencies (OS specific)
deps: init
@[ ! -x /sbin/apk ] || apk add --update terraform-docs@cloudposse

# Run basic sanity checks against the module itself
module: export TESTS ?= installed lint get-modules validate terraform-docs input-descriptions output-descriptions
module: deps
$(call RUN_TESTS, ../)

# Run tests against example
examples/complete: export TESTS ?= init plan apply
examples/complete: deps
$(call RUN_TESTS, ../$@)

0 comments on commit 5f28e20

Please sign in to comment.