kubernetes_config_map/from_files/ destroy.sh #!/bin/bash ../../../bin/destroy.sh kubernetes main.tf # Summary: Kubernetes configmap from files # Documentation: https://www.terraform.io/docs/language/settings/index.html terraform { required_version = ">= 1.0.0" required_providers { kubernetes = { source = "hashicorp/kubernetes" version = "~> 2.0" } } } # Documentation: https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/config_ma resource "kubernetes_config_map" "changeme_from_files_config_map" { metadata { name = "changeme-from-files-config-map" } data = { "my_config_file.yml" = "${file("${path.module}/my_config_file.yml")}" } binary_data = { "my_payload.bin" = "${filebase64("${path.module}/my_payload.bin")}" } } my_config_file.yml key: value my_payload.bin binary_payload run.sh #!/bin/bash ../../../bin/apply.sh kubernetes kubernetes_config_map/simple/ destroy.sh #!/bin/bash ../../../bin/destroy.sh kubernetes main.tf # Summary: Creates a Kubernetes configmap # Documentation: https://www.terraform.io/docs/language/settings/index.html terraform { required_version = ">= 1.0.0" required_providers { kubernetes = { source = "hashicorp/kubernetes" version = "~> 2.0" } } } # Documentation: https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/config_map resource "kubernetes_config_map" "changeme_simple_config_map" { metadata { name = "changeme-simple-config-map" } data = { api_host = "myhost:443" db_host = "dbhost:5432" } } run.sh #!/bin/bash ../../../bin/apply.sh kubernetes kubernetes_deployment/deployment_and_service/ destroy.sh #!/bin/bash ../../../bin/destroy.sh kubernetes main.tf # Summary: Create a Kubernetes deployment and service # Documentation: https://www.terraform.io/docs/language/settings/index.html terraform { required_version = ">= 1.0.0" required_providers { kubernetes = { source = "hashicorp/kubernetes" version = "~> 2.0" } } } # Documentation: https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/namespace resource "kubernetes_namespace" "changeme_deployment_and_service_namespace" { metadata { name = "changeme-deployment-and-service" } } # Documentation: https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/deployment resource "kubernetes_deployment" "changeme_deployment_and_service_deployment" { metadata { name = "changeme-deployment-and-service" namespace = kubernetes_namespace.changeme_deployment_and_service_namespace.metadata.0.name labels = { app = "changeme-deployment-and-service" } } spec { replicas = 2 selector { match_labels = { app = "changeme-deployment-and-service" } } template { metadata { labels = { app = "changeme-deployment-and-service" } } spec { container { image = "nginx" name = "nginx" port { container_port = 80 } } } } } } # Documentation: https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/service resource "kubernetes_service" "changeme_deployment_and_service_service" { metadata { name = "changeme-deployment-and-service" namespace = kubernetes_namespace.changeme_deployment_and_service_namespace.metadata.0.name } spec { selector = { app = kubernetes_deployment.changeme_deployment_and_service_deployment.spec.0.template.0.metadata[0].labels.app } port { port = 80 target_port = 80 } } } run.sh #!/bin/bash ../../../bin/apply.sh kubernetes kubernetes_deployment/simple/ destroy.sh #!/bin/bash ../../../bin/destroy.sh kubernetes main.tf # Summary: A Kubernetes deployment # Documentation: https://www.terraform.io/docs/language/settings/index.html terraform { required_version = ">= 1.0.0" required_providers { kubernetes = { source = "hashicorp/kubernetes" version = "~> 2.0" } } } # Documentation: https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/deployment resource "kubernetes_deployment" "changeme_simple_deployment" { metadata { name = "changeme-simple-deployment" labels = { app = "changeme-simple-deployment" } } spec { replicas = 1 selector { match_labels = { app = "changeme-simple-deployment" } } template { metadata { labels = { app = "changeme-simple-deployment" } } spec { container { image = "nginx" name = "nginx" } } } } } run.sh #!/bin/bash ../../../bin/apply.sh kubernetes kubernetes_namespace/simple/ destroy.sh #!/bin/bash ../../../bin/destroy.sh kubernetes main.tf # Summary: A Kubernetes namespace # Documentation: https://www.terraform.io/docs/language/settings/index.html terraform { required_version = ">= 1.0.0" required_providers { kubernetes = { source = "hashicorp/kubernetes" version = "~> 2.0" } } } # Documentation: https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/namespace resource "kubernetes_namespace" "changeme_simple_namespace" { metadata { name = "changeme-simple-namespace" } } run.sh #!/bin/bash ../../../bin/apply.sh kubernetes kubernetes_service/simple/ destroy.sh #!/bin/bash ../../../bin/destroy.sh kubernetes main.tf # Summary: A kubernetes service # Documentation: https://www.terraform.io/docs/language/settings/index.html terraform { required_version = ">= 1.0.0" required_providers { kubernetes = { source = "hashicorp/kubernetes" version = "~> 2.0" } } } # Documentation: https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/service resource "kubernetes_service" "changeme_simple_service" { metadata { name = "changeme-simple-service" } spec { selector = { app = "changeme-simple-deployment" } port { port = 80 target_port = 80 } } } run.sh #!/bin/bash ../../../bin/apply.sh kubernetes