Last active
February 28, 2018 14:50
-
-
Save moali87/2a3b2c7ef5515ff7d6f4a0123749e24f to your computer and use it in GitHub Desktop.
Terraform workspaces with locals
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
locals { | |
vpc_type = "${terraform.workspace == "prod" ? "prod" : "dev"}" | |
vpc_id = "${local.vpc_type == "prod" ? var.vpc_ids["prod"] : var.vpc_ids["dev"]}" | |
} |
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
resource "aws_subnet" "ext_subnets" { | |
vpc_id = "${local.vpc_id}" | |
cidr_block = "${var.ext_subnet_cidr[local.vpc_type]}" | |
tags { | |
Name = "EXT_1_${terraform.workspace}" | |
} | |
} |
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
vpc_ids = { | |
prod = "vpc-aad01dd1" | |
dev = "vpc-f78f568c" | |
} | |
ext_subnet_cidr = { | |
prod = "10.0.0.0/24" | |
dev = "10.1.0.0/24" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment