Skip to content

Commit

Permalink
Convert to TF 0.12. Add tests. Add Codefresh test pipeline (#17)
Browse files Browse the repository at this point in the history
* 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

* 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
  • Loading branch information
aknysh authored Dec 1, 2019
1 parent b76e9be commit acb31cc
Show file tree
Hide file tree
Showing 25 changed files with 816 additions and 191 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

# Module directory
.terraform/
.idea
terraform-aws-vpc-peering.iml
*.iml
.idea/

.build-harness
build-harness
build-harness/
16 changes: 0 additions & 16 deletions .travis.yml

This file was deleted.

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-2018 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
180 changes: 117 additions & 63 deletions README.md

Large diffs are not rendered by default.

20 changes: 12 additions & 8 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ github_repo: cloudposse/terraform-aws-vpc-peering

# Badges to display
badges:
- name: "Build Status"
image: "https://travis-ci.org/cloudposse/terraform-aws-vpc-peering.svg?branch=master"
url: "https://travis-ci.org/cloudposse/terraform-aws-vpc-peering"
- name: "Codefresh Build Status"
image: "https://g.codefresh.io/api/badges/pipeline/cloudposse/terraform-modules%2Fterraform-aws-vpc-peering?type=cf-1"
url: "https://g.codefresh.io/public/accounts/cloudposse/pipelines/5de3232a1fe7e852050b730e"
- name: "Latest Release"
image: "https://img.shields.io/github/release/cloudposse/terraform-aws-vpc-peering.svg"
url: "https://github.com/cloudposse/terraform-aws-vpc-peering/releases/latest"
Expand All @@ -58,17 +58,17 @@ description: |-
# How to use this project
usage: |-
**IMPORTANT:** Using the `master` branch is just an example.
Do not pin to `master` in your code 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-aws-vpc-peering/releases).
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).
### Using VPC IDs
```hcl
module "vpc_peering" {
source = "git::https://github.com/cloudposse/terraform-aws-vpc-peering.git?ref=master"
namespace = "cp"
namespace = "eg"
stage = "dev"
name = "cluster"
requestor_vpc_id = "vpc-XXXXXXXX"
Expand All @@ -81,7 +81,7 @@ usage: |-
```hcl
module "vpc_peering" {
source = "git::https://github.com/cloudposse/terraform-aws-vpc-peering.git?ref=master"
namespace = "cp"
namespace = "eg"
stage = "dev"
name = "cluster"
requestor_vpc_tags = {
Expand Down Expand Up @@ -114,3 +114,7 @@ contributors:
github: "aknysh"
- name: "Vladimir"
github: "SweetOps"
- name: "Erik Osterman"
github: "osterman"
- name: "Igor Rodionov"
github: "goruha"
74 changes: 74 additions & 0 deletions codefresh/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
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:
- make -C test/src
27 changes: 15 additions & 12 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| acceptor_allow_remote_vpc_dns_resolution | Allow acceptor VPC to resolve public DNS hostnames to private IP addresses when queried from instances in the requestor VPC | string | `true` | no |
| acceptor_allow_remote_vpc_dns_resolution | Allow acceptor VPC to resolve public DNS hostnames to private IP addresses when queried from instances in the requestor VPC | bool | `true` | no |
| acceptor_vpc_id | Acceptor VPC ID | string | `` | no |
| acceptor_vpc_tags | Acceptor VPC tags | map | `<map>` | no |
| attributes | Additional attributes (e.g. `policy` or `role`) | list | `<list>` | no |
| auto_accept | Automatically accept the peering (both VPCs need to be in the same AWS account) | string | `true` | no |
| delimiter | Delimiter to be used between `namespace`, `stage`, `name`, and `attributes` | string | `-` | no |
| enabled | Set to false to prevent the module from creating or accessing any resources | string | `true` | no |
| name | Name (e.g. `app` or `cluster`) | string | - | yes |
| namespace | Namespace (e.g. `cp` or `cloudposse`) | string | - | yes |
| requestor_allow_remote_vpc_dns_resolution | Allow requestor VPC to resolve public DNS hostnames to private IP addresses when queried from instances in the acceptor VPC | string | `true` | no |
| acceptor_vpc_tags | Acceptor VPC tags | map(string) | `<map>` | no |
| attributes | Additional attributes (e.g. `1`) | list(string) | `<list>` | no |
| auto_accept | Automatically accept the peering (both VPCs need to be in the same AWS account) | bool | `true` | no |
| create_timeout | VPC peering connection create timeout. For more details, see https://www.terraform.io/docs/configuration/resources.html#operation-timeouts | string | `3m` | no |
| delete_timeout | VPC peering connection delete timeout. For more details, see https://www.terraform.io/docs/configuration/resources.html#operation-timeouts | string | `5m` | no |
| delimiter | Delimiter to be used between `name`, `namespace`, `stage`, etc. | string | `-` | no |
| enabled | Set to false to prevent the module from creating or accessing any resources | bool | `true` | no |
| name | Solution name, e.g. 'app' or 'cluster' | string | - | yes |
| namespace | Namespace, which could be your organization name, e.g. 'eg' or 'cp' | string | `` | no |
| requestor_allow_remote_vpc_dns_resolution | Allow requestor VPC to resolve public DNS hostnames to private IP addresses when queried from instances in the acceptor VPC | bool | `true` | no |
| requestor_vpc_id | Requestor VPC ID | string | `` | no |
| requestor_vpc_tags | Requestor VPC tags | map | `<map>` | no |
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | - | yes |
| tags | Additional tags (e.g. map('BusinessUnit`,`XYZ`) | map | `<map>` | no |
| requestor_vpc_tags | Requestor VPC tags | map(string) | `<map>` | no |
| stage | Stage, e.g. 'prod', 'staging', 'dev', or 'test' | string | `` | no |
| tags | Additional tags (e.g. `map('BusinessUnit`,`XYZ`) | map(string) | `<map>` | no |
| update_timeout | VPC peering connection update timeout. For more details, see https://www.terraform.io/docs/configuration/resources.html#operation-timeouts | string | `3m` | no |

## Outputs

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

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

namespace = "eg"

stage = "test"

name = "vpc-peering"

requestor_vpc_cidr = "172.16.0.0/16"

acceptor_vpc_cidr = "172.32.0.0/16"
70 changes: 70 additions & 0 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
provider "aws" {
region = var.region
}

module "requestor_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
attributes = concat(var.attributes, ["requestor"])
cidr_block = var.requestor_vpc_cidr
tags = var.tags
}

module "requestor_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
attributes = concat(var.attributes, ["requestor"])
vpc_id = module.requestor_vpc.vpc_id
igw_id = module.requestor_vpc.igw_id
cidr_block = module.requestor_vpc.vpc_cidr_block
nat_gateway_enabled = false
nat_instance_enabled = false
tags = var.tags
}

module "acceptor_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
attributes = concat(var.attributes, ["acceptor"])
cidr_block = var.acceptor_vpc_cidr
tags = var.tags
}

module "acceptor_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
attributes = concat(var.attributes, ["acceptor"])
vpc_id = module.acceptor_vpc.vpc_id
igw_id = module.acceptor_vpc.igw_id
cidr_block = module.acceptor_vpc.vpc_cidr_block
nat_gateway_enabled = false
nat_instance_enabled = false
tags = var.tags
}

module "vpc_peering" {
source = "../.."
namespace = var.namespace
stage = var.stage
name = var.name
attributes = var.attributes
tags = var.tags
auto_accept = true
requestor_allow_remote_vpc_dns_resolution = true
acceptor_allow_remote_vpc_dns_resolution = true
requestor_vpc_id = module.requestor_vpc.vpc_id
acceptor_vpc_id = module.acceptor_vpc.vpc_id
create_timeout = "5m"
update_timeout = "5m"
delete_timeout = "10m"
}
39 changes: 39 additions & 0 deletions examples/complete/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
output "requestor_vpc_cidr" {
value = module.requestor_vpc.vpc_cidr_block
description = "Requestor VPC ID"
}

output "requestor_public_subnet_cidrs" {
value = module.requestor_subnets.public_subnet_cidrs
description = "Requestor public subnet CIDRs"
}

output "requestor_private_subnet_cidrs" {
value = module.requestor_subnets.private_subnet_cidrs
description = "Requestor private subnet CIDRs"
}

output "acceptor_vpc_cidr" {
value = module.acceptor_vpc.vpc_cidr_block
description = "Acceptor VPC ID"
}

output "acceptor_public_subnet_cidrs" {
value = module.acceptor_subnets.public_subnet_cidrs
description = "Acceptor public subnet CIDRs"
}

output "acceptor_private_subnet_cidrs" {
value = module.acceptor_subnets.private_subnet_cidrs
description = "Acceptor private subnet CIDRs"
}

output "connection_id" {
value = module.vpc_peering.connection_id
description = "VPC peering connection ID"
}

output "accept_status" {
value = module.vpc_peering.accept_status
description = "The status of the VPC peering connection request"
}
52 changes: 52 additions & 0 deletions examples/complete/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
variable "region" {
type = string
description = "AWS Region"
}

variable "availability_zones" {
type = list(string)
description = "List of availability zones"
}

variable "namespace" {
type = string
description = "Namespace, which could be your organization name, e.g. 'eg' or 'cp'"
}

variable "stage" {
type = string
description = "Stage, e.g. 'prod', 'staging', 'dev' or 'testing'"
}

variable "name" {
type = string
description = "Solution name, e.g. 'app' or 'cluster'"
}

variable "delimiter" {
type = string
default = "-"
description = "Delimiter to be used between `name`, `namespace`, `stage`, etc."
}

variable "attributes" {
type = list(string)
default = []
description = "Additional attributes (e.g. `1`)"
}

variable "tags" {
type = map(string)
default = {}
description = "Additional tags (e.g. `map('BusinessUnit`,`XYZ`)"
}

variable "requestor_vpc_cidr" {
type = string
description = "Requestor VPC CIDR"
}

variable "acceptor_vpc_cidr" {
type = string
description = "Acceptor VPC CIDR"
}
9 changes: 9 additions & 0 deletions examples/complete/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_version = "~> 0.12.0"

required_providers {
aws = "~> 2.0"
template = "~> 2.0"
local = "~> 1.3"
}
}
Loading

0 comments on commit acb31cc

Please sign in to comment.