-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added new variables to allow the number of public or private subnets to be specified. * Added option to create 0 to many subnets for each subnet type (public or private). Added Example * set the dynamic subnet length to match the number of provided az's if any provided * updated availability_zone variable description * Added region back in, updated the description to show that there is a nested aws provider within the module * Added region back in, updated the description to show that there is a nested aws provider within the module * Created availability_zones.tf and moves availability zone data and locals in to it. Moved the public and private subnet locals into public.tf and private.tf. * Fixed a miscalculated value for labeling the nat instances by az * removed outdated comment
- Loading branch information
1 parent
90ca5cf
commit d7b8237
Showing
12 changed files
with
222 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
data "aws_availability_zones" "available" {} | ||
|
||
locals { | ||
## If the variable availability_zones is empty, use the list provided by data.aws_availability_zones.available.names | ||
## Otherwise use the zones listed in availability_zones | ||
az_name_map = { | ||
"0" = ["${data.aws_availability_zones.available.names}"] | ||
"1" = ["${var.availability_zones}"] | ||
} | ||
|
||
availability_zones = "${local.az_name_map[signum(length(var.availability_zones))]}" | ||
|
||
## This selects one of the lists based on the signum() interpolation | ||
az_map = { | ||
"-1" = ["${data.aws_availability_zones.available.names}"] | ||
"1" = ["${local.availability_zones}"] | ||
"0" = [] | ||
} | ||
|
||
## Select the az from the list using a function like `local.availability_zones_public[count.index % length(local.availability_zones_public)]` | ||
availability_zones_public = "${local.az_map[signum(local.public_subnet_count)]}" | ||
availability_zones_private = "${local.az_map[signum(local.private_subnet_count)]}" | ||
} | ||
|
||
## This should be depreciated in the future. | ||
locals { | ||
max_subnets_map = { | ||
"-1" = "${length(local.availability_zones)}" | ||
"0" = "0" | ||
"1" = "${var.max_subnet_count}" | ||
} | ||
|
||
max_subnet_count = "${local.max_subnets_map[signum(var.max_subnet_count)]}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
## This example demonstrates it use as if it was being used | ||
## for some Spinnaker (spinnaker.io) deployment | ||
|
||
module "dynamic_subnets" { | ||
source = "./.." | ||
context = "${module.label.context}" | ||
tags = "${merge(module.label.tags, local.subnet_tags)}" | ||
region = "${data.aws_region.current.name}" | ||
availability_zones = ["${data.aws_region.current.name}a", "${data.aws_region.current.name}b"] // Optional list of AZ's to restrict it to | ||
vpc_id = "${module.vpc.vpc_id}" | ||
igw_id = "${module.vpc.igw_id}" | ||
public_subnet_count = "2" // Two public zones for the load balancers | ||
private_subnet_count = "4" // Four private zones for the | ||
map_public_ip_on_launch = "true" | ||
|
||
## You can use nat_gateway_enabled or nat_instance_enabled | ||
## It creates one nat instance per public subnet. | ||
## So if you want to exclude the public subnet by setting the public_subnet_count to 0 | ||
## You will neet to use the nat_gateway_enabled option. | ||
nat_instance_enabled = "true" | ||
|
||
nat_gateway_enabled = "false" | ||
|
||
## Optionally customising a tag based on whether it is public or private | ||
## will format like this: "immutable_metadata": {"purpose": \"public-subnet\"}" | ||
subnet_type_tag_key = "immutable_metadata" | ||
|
||
subnet_type_tag_value_format = "{\"purpose\": \"%s-subnet\"}" // The %s gets replaced with 'public' on public subnets and 'private' on private subnets | ||
} | ||
|
||
## VPC module doesn't have the latest version of null_label | ||
## module integrated with it at the time of this example being | ||
## written so no context variable here. | ||
module "vpc" { | ||
source = "git::https://github.com/cloudposse/terraform-aws-vpc.git?ref=tags/0.4.1" | ||
namespace = "${module.label.namespace}" | ||
stage = "${module.label.environment}" | ||
name = "${module.label.name}" | ||
attributes = ["${module.label.attributes}"] | ||
delimiter = "${module.label.delimiter}" | ||
tags = "${module.label.tags}" | ||
cidr_block = "${var.vpc_cidr}" | ||
} | ||
|
||
data "aws_region" "current" {} | ||
|
||
module "label" { | ||
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.11.1" | ||
namespace = "cp" | ||
environment = "prod" | ||
delimiter = "-" | ||
name = "spinnaker" | ||
|
||
tags = { | ||
"ManagedBy" = "Terraform" | ||
"ModuleBy" = "CloudPosse" | ||
} | ||
} | ||
|
||
variable "eks_cluster_name" { | ||
description = "The name of the EKS cluster that will be utilising this network(if any)" | ||
default = "my-main-eks-cluster" | ||
} | ||
|
||
variable "vpc_cidr" { | ||
default = "10.0.0.0/16" | ||
} | ||
|
||
locals { | ||
# Spinnaker subnet tags | ||
subnet_tags = { | ||
"kubernetes.io/cluster/${var.eks_cluster_name}" = "shared" | ||
"kubernetes.io/role/elb" = "" | ||
"kubernetes.io/role/internal-elb" = "" | ||
} | ||
} | ||
|
||
provider "aws" { | ||
version = "~> 2.12" | ||
region = "us-west-2" | ||
skip_requesting_account_id = true # this can be tricky | ||
skip_get_ec2_platforms = true | ||
skip_metadata_api_check = true | ||
skip_region_validation = true | ||
skip_credentials_validation = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.