resource "kubernetes_namespace" "testaroo" {
metadata {
name = "testaroo-${terraform.workspace}"
}
resource "kubernetes_pod" "basic-pod" {
name = "alpine"
namespace = kubernetes_namespace.testaroo.metadata.0.name
spec {
container {
image = "alpine:3.15"
command = ["sh", "-c", "while true; do sleep 3600; done"]
resource "kubernetes_deployment" "testaroo" {
count = terraform.workspace == "prod" ? 0 : 1
name = "nginx"
replicas = 2
selector {
match_labels = {
app = "Nginx"
template {
labels = {
image = "nginx"
name = "nginx-container"
port {
container_port = 80
resource "kubernetes_service" "testaroo" {
count = length(kubernetes_deployment.testaroo)
name = "nginx-np"
selector = {
app = kubernetes_deployment.testaroo[0].spec.0.template.0.metadata.0.labels.app
type = "NodePort"
node_port = 31234
port = 80
target_port = 80
resource "kubernetes_service" "testaroo-lb" {
name = "nginx-lb"
type = "LoadBalancer"