Skip to content

Instantly share code, notes, and snippets.

@nikhedonia
Last active November 15, 2018 22:46
Show Gist options
  • Save nikhedonia/361ac9f862b7dc5a56c39092baf8f99e to your computer and use it in GitHub Desktop.
Save nikhedonia/361ac9f862b7dc5a56c39092baf8f99e to your computer and use it in GitHub Desktop.
provider "aws" {
region = "eu-west-1"
}
terraform {
backend "s3" { # will handle correctly multiple workspaces
bucket = "project"
region = "eu-west-1"
key = "project/terraform.tfstate"
dynamodb_table = "project-terraform-lock" # to prevent race conditions, table needs to be created manually
}
}
data "terraform_remote_state" "network" {
backend = "s3" # bucket needs to be created manually
config {
bucket = "tf-project"
key = "project/terraform.tfstate"
region = "eu-west-1" # make sure terraform has permissions
}
}
variable "common_tags" {
default = {
ServiceName = "platform"
Team = "my@email.com"
}
}
resource "aws_subnet" "private" {
tags = "${merge(
var.common_tags,
map("Name", "PriSubnet1"),
map("Network", "Private"),
)}"
}
locals { # select a workspace using `terraform workspace select $NAME`
domains {
dev = "dev.mydomain.com"
prod = "prod.mydomain.com"
}
domain = "${local.domains[terraform.workspace]}"
}
@nikhedonia
Copy link
Author

lifecycle {
    prevent_destroy = true
}

terraform lifecycle methods may prevent you from breaking things accidentally

@nikhedonia
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment