Skip to content

Commit

Permalink
Add private_subnets_additional_tags and `public_subnets_additional_…
Browse files Browse the repository at this point in the history
…tags` variables. Change AWS region for tests. (#84)

* Add `private_subnets_additional_tags` and `public_subnets_additional_tags` variables. Change AWS region for tests.

* Add `private_subnets_additional_tags` and `public_subnets_additional_tags` variables. Change AWS region for tests.
  • Loading branch information
aknysh authored Feb 13, 2020
1 parent 98c575e commit 7d3182d
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 30 deletions.
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-2019 Cloud Posse, LLC
Copyright 2017-2020 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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,15 @@ Available targets:
| label_order | The naming order of the ID output and Name tag | list(string) | `<list>` | no |
| map_public_ip_on_launch | Instances launched into a public subnet should be assigned a public IP address | bool | `true` | no |
| max_subnet_count | Sets the maximum amount of subnets to deploy. 0 will deploy a subnet for every provided availablility zone (in `availability_zones` variable) within the region | string | `0` | no |
| name | Solution name, e.g. 'app' or 'jenkins' | string | `` | no |
| name | Solution name, e.g. 'app' or 'cluster' | string | `` | no |
| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | string | `` | no |
| nat_gateway_enabled | Flag to enable/disable NAT Gateways to allow servers in the private subnets to access the Internet | bool | `true` | no |
| nat_instance_enabled | Flag to enable/disable NAT Instances to allow servers in the private subnets to access the Internet | bool | `false` | no |
| nat_instance_type | NAT Instance type | string | `t3.micro` | no |
| private_network_acl_id | Network ACL ID that will be added to private subnets. If empty, a new ACL will be created | string | `` | no |
| private_subnets_additional_tags | Additional tags to be added to private subnets | map(string) | `<map>` | no |
| public_network_acl_id | Network ACL ID that will be added to public subnets. If empty, a new ACL will be created | string | `` | no |
| public_subnets_additional_tags | Additional tags to be added to public subnets | map(string) | `<map>` | no |
| regex_replace_chars | Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`. By default only hyphens, letters and digits are allowed, all other chars are removed | string | `/[^a-zA-Z0-9-]/` | no |
| stage | Stage, e.g. 'prod', 'staging', 'dev', or 'test' | string | `` | no |
| subnet_type_tag_key | Key for subnet type tag to provide information about the type of subnets, e.g. `cpco.io/subnet/type=private` or `cpco.io/subnet/type=public` | string | `cpco.io/subnet/type` | no |
Expand Down Expand Up @@ -323,7 +325,7 @@ In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.

## Copyright

Copyright © 2017-2019 [Cloud Posse, LLC](https://cpco.io/copyright)
Copyright © 2017-2020 [Cloud Posse, LLC](https://cpco.io/copyright)



Expand Down
4 changes: 3 additions & 1 deletion docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
| label_order | The naming order of the ID output and Name tag | list(string) | `<list>` | no |
| map_public_ip_on_launch | Instances launched into a public subnet should be assigned a public IP address | bool | `true` | no |
| max_subnet_count | Sets the maximum amount of subnets to deploy. 0 will deploy a subnet for every provided availablility zone (in `availability_zones` variable) within the region | string | `0` | no |
| name | Solution name, e.g. 'app' or 'jenkins' | string | `` | no |
| name | Solution name, e.g. 'app' or 'cluster' | string | `` | no |
| namespace | Namespace, which could be your organization name or abbreviation, e.g. 'eg' or 'cp' | string | `` | no |
| nat_gateway_enabled | Flag to enable/disable NAT Gateways to allow servers in the private subnets to access the Internet | bool | `true` | no |
| nat_instance_enabled | Flag to enable/disable NAT Instances to allow servers in the private subnets to access the Internet | bool | `false` | no |
| nat_instance_type | NAT Instance type | string | `t3.micro` | no |
| private_network_acl_id | Network ACL ID that will be added to private subnets. If empty, a new ACL will be created | string | `` | no |
| private_subnets_additional_tags | Additional tags to be added to private subnets | map(string) | `<map>` | no |
| public_network_acl_id | Network ACL ID that will be added to public subnets. If empty, a new ACL will be created | string | `` | no |
| public_subnets_additional_tags | Additional tags to be added to public subnets | map(string) | `<map>` | no |
| regex_replace_chars | Regex to replace chars with empty string in `namespace`, `environment`, `stage` and `name`. By default only hyphens, letters and digits are allowed, all other chars are removed | string | `/[^a-zA-Z0-9-]/` | no |
| stage | Stage, e.g. 'prod', 'staging', 'dev', or 'test' | string | `` | no |
| subnet_type_tag_key | Key for subnet type tag to provide information about the type of subnets, e.g. `cpco.io/subnet/type=private` or `cpco.io/subnet/type=public` | string | `cpco.io/subnet/type` | no |
Expand Down
9 changes: 9 additions & 0 deletions examples/complete/fixtures.us-east-2.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
region = "us-east-2"

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

namespace = "eg"

stage = "test"

name = "subnets-vpc-test"
9 changes: 0 additions & 9 deletions examples/complete/fixtures.us-west-1.tfvars

This file was deleted.

2 changes: 1 addition & 1 deletion examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ provider "aws" {
}

module "vpc" {
source = "git::https://github.com/cloudposse/terraform-aws-vpc.git?ref=tags/0.7.0"
source = "git::https://github.com/cloudposse/terraform-aws-vpc.git?ref=tags/0.8.1"
namespace = var.namespace
stage = var.stage
name = var.name
Expand Down
19 changes: 12 additions & 7 deletions examples/complete/variables.tf
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
variable "region" {
type = string
type = string
description = "AWS region"
}

variable "availability_zones" {
type = list(string)
type = list(string)
description = "List of Availability Zones where subnets will be created"
}

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

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

variable "stage" {
type = string
variable "name" {
type = string
description = "Solution/application name, e.g. 'app' or 'cluster'"
}
4 changes: 2 additions & 2 deletions label.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module "label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.14.0"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.16.0"
attributes = var.attributes
namespace = var.namespace
environment = var.environment
Expand Down Expand Up @@ -52,7 +52,7 @@ variable "stage" {
variable "name" {
type = string
default = ""
description = "Solution name, e.g. 'app' or 'jenkins'"
description = "Solution name, e.g. 'app' or 'cluster'"
}

variable "environment" {
Expand Down
2 changes: 1 addition & 1 deletion nat-gateway.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module "nat_label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.14.0"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.16.0"
context = module.label.context
attributes = distinct(compact(concat(module.label.attributes, ["nat"])))
}
Expand Down
2 changes: 1 addition & 1 deletion nat-instance.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module "nat_instance_label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.14.0"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.16.0"
context = module.label.context
attributes = distinct(compact(concat(module.label.attributes, ["nat", "instance"])))
}
Expand Down
3 changes: 2 additions & 1 deletion private.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module "private_label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.14.0"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.16.0"
context = module.label.context
attributes = compact(concat(module.label.attributes, ["private"]))

tags = merge(
module.label.tags,
var.private_subnets_additional_tags,
map(var.subnet_type_tag_key, format(var.subnet_type_tag_value_format, "private"))
)
}
Expand Down
3 changes: 2 additions & 1 deletion public.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module "public_label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.14.0"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.16.0"
context = module.label.context
attributes = compact(concat(module.label.attributes, ["public"]))

tags = merge(
module.label.tags,
var.public_subnets_additional_tags,
map(var.subnet_type_tag_key, format(var.subnet_type_tag_value_format, "public"))
)
}
Expand Down
6 changes: 3 additions & 3 deletions test/src/examples_complete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestExamplesComplete(t *testing.T) {
TerraformDir: "../../examples/complete",
Upgrade: true,
// Variables to pass to our Terraform code using -var-file options
VarFiles: []string{"fixtures.us-west-1.tfvars"},
VarFiles: []string{"fixtures.us-east-2.tfvars"},
}

// At the end of the test, run `terraform destroy` to clean up any resources that were created
Expand All @@ -28,14 +28,14 @@ func TestExamplesComplete(t *testing.T) {
// Run `terraform output` to get the value of an output variable
privateSubnetCidrs := terraform.OutputList(t, terraformOptions, "private_subnet_cidrs")

expectedPrivateSubnetCidrs := []string{"172.16.0.0/18", "172.16.64.0/18"}
expectedPrivateSubnetCidrs := []string{"172.16.0.0/19", "172.16.32.0/19"}
// Verify we're getting back the outputs we expect
assert.Equal(t, expectedPrivateSubnetCidrs, privateSubnetCidrs)

// Run `terraform output` to get the value of an output variable
publicSubnetCidrs := terraform.OutputList(t, terraformOptions, "public_subnet_cidrs")

expectedPublicSubnetCidrs := []string{"172.16.128.0/18", "172.16.192.0/18"}
expectedPublicSubnetCidrs := []string{"172.16.96.0/19", "172.16.128.0/19"}
// Verify we're getting back the outputs we expect
assert.Equal(t, expectedPublicSubnetCidrs, publicSubnetCidrs)
}
12 changes: 12 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,15 @@ variable "map_public_ip_on_launch" {
default = true
description = "Instances launched into a public subnet should be assigned a public IP address"
}

variable "private_subnets_additional_tags" {
type = map(string)
default = {}
description = "Additional tags to be added to private subnets"
}

variable "public_subnets_additional_tags" {
type = map(string)
default = {}
description = "Additional tags to be added to public subnets"
}

0 comments on commit 7d3182d

Please sign in to comment.