Skip to content

Instantly share code, notes, and snippets.

View unfor19's full-sized avatar
😺

Meir Gabay unfor19

😺
View GitHub Profile
@unfor19
unfor19 / variable_cidr_ab.tf
Last active September 24, 2019 08:59
Set cidr_ab per environment
variable "cidr_ab" {
type = map
default = {
development = "172.22"
qa = "172.24"
staging = "172.26"
production = "172.28"
}
}
@unfor19
unfor19 / get_cidr_ab.tf
Created September 24, 2019 08:58
Get cidr_ab per environment
locals {
private_subnets = [
"${lookup(var.cidr_ab, var.environment)}.1.0/24",
"${lookup(var.cidr_ab, var.environment)}.2.0/24",
"${lookup(var.cidr_ab, var.environment)}.3.0/24"
]
}
@unfor19
unfor19 / variables-1.tf
Created September 24, 2019 08:59
Issue #1: Full Solution
variable "cidr_ab" {
type = map
default = {
development = "172.22"
qa = "172.24"
staging = "172.26"
production = "172.28"
}
}
@unfor19
unfor19 / vpc-1.tf
Created September 24, 2019 09:01
Issue #1: Full Solution
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~>2.0"
name = "my-vpc"
cidr = "${lookup(var.cidr_ab, var.environment)}.0.0/16"
private_subnets = local.private_subnets
database_subnets = local.database_subnets
public_subnets = local.public_subnets
azs = ["us-west-2a", "us-west-2b", "us-west-2c"]
@unfor19
unfor19 / region_abc.tf
Created September 24, 2019 09:03
region name followed by abc
variable "region" {
type = map(string)
default = {
"development" = "us-west-2"
"qa" = "us-east-2"
"staging" = "us-east-1"
"production" = "ca-central-1"
}
}
@unfor19
unfor19 / data_aws_availability_zones.tf
Created September 24, 2019 09:04
data aws_availability_zones
data "aws_availability_zones" "available" {
state = "available"
}
@unfor19
unfor19 / data_aws_availability_zones.names.tf
Created September 24, 2019 09:05
Availability zones names
locals {
availability_zones = data.aws_availability_zones.available.names
}
@unfor19
unfor19 / variables-2.tf
Created September 24, 2019 09:06
Issue #2: Full solution
variable "cidr_ab" {
type = map
default = {
development = "172.22"
qa = "172.24"
staging = "172.26"
production = "172.28"
}
}
@unfor19
unfor19 / vpc-2.tf
Created September 24, 2019 09:06
Issue #2: Full solution
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~>2.0"
name = "my-vpc"
cidr = "${lookup(var.cidr_ab, var.environment)}.0.0/16"
private_subnets = local.private_subnets
database_subnets = local.database_subnets
public_subnets = local.public_subnets
azs = local.availability_zones
@unfor19
unfor19 / for-loop-pseudo.tf
Created September 24, 2019 09:09
for loop pseudo-code
for availability_zone in local.availability_zones:
"${lookup(var.cidr_ab, var.environment)}.${local.cidr_c_private_subnets + index_of_availability_zone}.0/24"