Use a lockable state repository.
Also, make use of terraform workspaces.
This commit is contained in:
9
k8s/init.tf
Normal file
9
k8s/init.tf
Normal file
@ -0,0 +1,9 @@
|
||||
terraform {
|
||||
backend "s3" {
|
||||
bucket = "terraform-state-infra-aws-eks"
|
||||
key = "global/s3/terraform.k8s.tfstate"
|
||||
region = "eu-west-3"
|
||||
dynamodb_table = "terraform-state-locks-infra-aws-eks"
|
||||
encrypt = true
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
resource "kubernetes_namespace" "testaroo" {
|
||||
metadata {
|
||||
name = "testaroo"
|
||||
name = "testaroo-${terraform.workspace}"
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ resource "kubernetes_pod" "basic-pod" {
|
||||
}
|
||||
|
||||
resource "kubernetes_deployment" "testaroo" {
|
||||
count = var.enable_nginx
|
||||
count = terraform.workspace == "prod" ? 0 : 1
|
||||
|
||||
metadata {
|
||||
name = "nginx"
|
||||
@ -56,7 +56,7 @@ resource "kubernetes_deployment" "testaroo" {
|
||||
}
|
||||
|
||||
resource "kubernetes_service" "testaroo" {
|
||||
count = var.enable_nginx
|
||||
count = length(kubernetes_deployment.testaroo)
|
||||
|
||||
metadata {
|
||||
name = "nginx-np"
|
||||
@ -78,7 +78,7 @@ resource "kubernetes_service" "testaroo" {
|
||||
}
|
||||
|
||||
resource "kubernetes_service" "testaroo-lb" {
|
||||
count = var.enable_nginx
|
||||
count = length(kubernetes_deployment.testaroo)
|
||||
|
||||
metadata {
|
||||
name = "nginx-lb"
|
||||
|
@ -1,4 +1,5 @@
|
||||
variable "enable_nginx" {
|
||||
type = number
|
||||
default = 0
|
||||
}
|
||||
# Superseeded by terraform's workspaces.
|
||||
# variable "enable_nginx" {
|
||||
# type = number
|
||||
# default = 0
|
||||
# }
|
||||
|
Reference in New Issue
Block a user