Skip to content

Commit

Permalink
Added a variable + slice function to control how many AZs will be dep…
Browse files Browse the repository at this point in the history
…loyed (#18)

* Added a variable + slice function to control how many AZs will be deployed

* Changed variable name to max_availability_zones

* Updated README with new examples
  • Loading branch information
ivan-pinatti authored and aknysh committed Jan 19, 2018
1 parent a8b4e37 commit 8e91395
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ For complete examples, see [examples](examples).
### Deploy Jenkins into an existing VPC with existing subnets

```hcl
variable "max_availability_zones" {
default = "2"
}
data "aws_availability_zones" "available" {}
module "jenkins" {
Expand All @@ -74,7 +78,7 @@ module "jenkins" {
master_instance_type = "t2.medium"
aws_account_id = "000111222333"
aws_region = "us-west-2"
availability_zones = ["${data.aws_availability_zones.available.names}"]
availability_zones = ["${slice(data.aws_availability_zones.available.names, 0, var.max_availability_zones)}"]
vpc_id = "vpc-a22222ee"
zone_id = "ZXXXXXXXXXXX"
public_subnets = ["subnet-e63f82cb", "subnet-e66f44ab", "subnet-e88f42bd"]
Expand Down Expand Up @@ -110,6 +114,10 @@ module "jenkins" {
### Deploy Jenkins into an existing VPC and new subnets

```hcl
variable "max_availability_zones" {
default = "2"
}
data "aws_availability_zones" "available" {}
module "jenkins" {
Expand All @@ -122,7 +130,7 @@ module "jenkins" {
master_instance_type = "t2.medium"
aws_account_id = "000111222333"
aws_region = "us-west-2"
availability_zones = ["${data.aws_availability_zones.available.names}"]
availability_zones = ["${slice(data.aws_availability_zones.available.names, 0, var.max_availability_zones)}"]
vpc_id = "vpc-a22222ee"
zone_id = "ZXXXXXXXXXXX"
public_subnets = "${module.subnets.public_subnet_ids}"
Expand Down Expand Up @@ -156,7 +164,7 @@ module "jenkins" {
module "subnets" {
source = "git::https://github.com/cloudposse/terraform-aws-dynamic-subnets.git?ref=master"
availability_zones = ["${data.aws_availability_zones.available.names}"]
availability_zones = ["${slice(data.aws_availability_zones.available.names, 0, var.max_availability_zones)}"]
namespace = "cp"
name = "jenkins"
stage = "prod"
Expand All @@ -176,6 +184,10 @@ module "subnets" {
### Deploy Jenkins into a new VPC and new subnets

```hcl
variable "max_availability_zones" {
default = "2"
}
data "aws_availability_zones" "available" {}
module "jenkins" {
Expand All @@ -188,7 +200,7 @@ module "jenkins" {
master_instance_type = "t2.medium"
aws_account_id = "000111222333"
aws_region = "us-west-2"
availability_zones = ["${data.aws_availability_zones.available.names}"]
availability_zones = ["${slice(data.aws_availability_zones.available.names, 0, var.max_availability_zones)}"]
vpc_id = "${module.vpc.vpc_id}"
zone_id = "ZXXXXXXXXXXX"
public_subnets = "${module.subnets.public_subnet_ids}"
Expand Down Expand Up @@ -236,7 +248,7 @@ module "vpc" {
module "subnets" {
source = "git::https://github.com/cloudposse/terraform-aws-dynamic-subnets.git?ref=master"
availability_zones = ["${data.aws_availability_zones.available.names}"]
availability_zones = ["${slice(data.aws_availability_zones.available.names, 0, var.max_availability_zones)}"]
namespace = "cp"
name = "jenkins"
stage = "prod"
Expand Down
6 changes: 5 additions & 1 deletion examples/existing_vpc_existing_subnets/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ provider "aws" {
region = "us-west-2"
}

variable "max_availability_zones" {
default = "2"
}

data "aws_availability_zones" "available" {}

module "jenkins" {
Expand All @@ -14,7 +18,7 @@ module "jenkins" {
master_instance_type = "t2.medium"
aws_account_id = "000111222333"
aws_region = "us-west-2"
availability_zones = ["${data.aws_availability_zones.available.names}"]
availability_zones = ["${slice(data.aws_availability_zones.available.names, 0, var.max_availability_zones)}"]
vpc_id = "vpc-a22222ee"
zone_id = "ZXXXXXXXXXXX"
public_subnets = ["subnet-e63f82cb", "subnet-e66f44ab", "subnet-e88f42bd"]
Expand Down
8 changes: 6 additions & 2 deletions examples/existing_vpc_new_subnets/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ provider "aws" {
region = "us-west-2"
}

variable "max_availability_zones" {
default = "2"
}

data "aws_availability_zones" "available" {}

module "jenkins" {
Expand All @@ -14,7 +18,7 @@ module "jenkins" {
master_instance_type = "t2.medium"
aws_account_id = "000111222333"
aws_region = "us-west-2"
availability_zones = ["${data.aws_availability_zones.available.names}"]
availability_zones = ["${slice(data.aws_availability_zones.available.names, 0, var.max_availability_zones)}"]
vpc_id = "vpc-a22222ee"
zone_id = "ZXXXXXXXXXXX"
public_subnets = "${module.subnets.public_subnet_ids}"
Expand Down Expand Up @@ -48,7 +52,7 @@ module "jenkins" {

module "subnets" {
source = "git::https://github.com/cloudposse/terraform-aws-dynamic-subnets.git?ref=master"
availability_zones = ["${data.aws_availability_zones.available.names}"]
availability_zones = ["${slice(data.aws_availability_zones.available.names, 0, var.max_availability_zones)}"]
namespace = "cp"
name = "jenkins"
stage = "prod"
Expand Down
8 changes: 6 additions & 2 deletions examples/new_vpc_new_subnets/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ provider "aws" {
region = "us-west-2"
}

variable "max_availability_zones" {
default = "2"
}

data "aws_availability_zones" "available" {}

module "jenkins" {
Expand All @@ -14,7 +18,7 @@ module "jenkins" {
master_instance_type = "t2.medium"
aws_account_id = "000111222333"
aws_region = "us-west-2"
availability_zones = ["${data.aws_availability_zones.available.names}"]
availability_zones = ["${slice(data.aws_availability_zones.available.names, 0, var.max_availability_zones)}"]
vpc_id = "${module.vpc.vpc_id}"
zone_id = "ZXXXXXXXXXXX"
public_subnets = "${module.subnets.public_subnet_ids}"
Expand Down Expand Up @@ -62,7 +66,7 @@ module "vpc" {

module "subnets" {
source = "git::https://github.com/cloudposse/terraform-aws-dynamic-subnets.git?ref=master"
availability_zones = ["${data.aws_availability_zones.available.names}"]
availability_zones = ["${slice(data.aws_availability_zones.available.names, 0, var.max_availability_zones)}"]
namespace = "cp"
name = "jenkins"
stage = "prod"
Expand Down

0 comments on commit 8e91395

Please sign in to comment.