Informal list of references, useful links, and examples referencing Terraform 0.12 related patterns and examples.
-
Upgrade Guide. A thorough guide on upgrading to 0.12.
-
Which providers are compatible? Includes a running list and updates.
-
Configuration Language Documentation. Official documentation.
-
Terraform 0.12 Blog Preview. This has links to other blogs (with examples!) detailing each improvement.
-
A Tour of Terraform 0.12. Kristin Laemmert walks through changes in 0.12 and compares them to 0.11
-
With v0.11.14,
terraform 0.12checklist
checks providers in a module for compatibility. -
Use
terraform fmt
for formatting files. The HCL extensions on VSCode may not be updated.
resource "kubernetes_namespace" "example" {
count = var.namespace == "default" || var.namespace == "kube-system" || var.namespace == null ? 0 : 1
metadata {
name = var.namespace
}
}
Snippet in variables.tf
variable "enable" {
default = false
}
Snippet in main.tf
resource "kubernetes_service" "zk_client" {
count = var.enable ? 1 : 0
metadata {
name = "${var.name}-client"
namespace = var.namespace
labels = {
app = var.name
}
}
spec {
selector = {
app = var.name
}
port {
port = var.ports.client.port
name = var.ports.client.name
}
}
}
Snippet in variables.tf
variable "containers" {
type = list(object({
name = string,
image = string,
port = number
}))
}
Snippet in main.tf
dynamic "container" {
for_each = var.containers
content {
name = container.value.name
image = container.value.image
port {
container_port = container.value.port
}
security_context {
allow_privilege_escalation = false
}
}
}
resource "null_resource" "hosts" {
count = var.replicas
triggers = {
zk_hosts = format("%s-%d:%d", var.name, count.index, var.ports.client.port)
}
}
resource "kubernetes_config_map" "zk_connection_string" {
metadata {
name = "${var.name}-connection-string"
namespace = var.namespace
}
data = {
hosts = join(",", null_resource.hosts.*.triggers.zk_hosts)
}
}
resource "null_resource" "numbered_hosts" {
count = var.replicas
triggers = {
hosts = format("%s-%d", var.name, count.index)
}
}
resource "kubernetes_config_map" "zk_config" {
metadata {
name = "${var.name}-zoo-cfg"
namespace = var.namespace
}
data = {
config = <<EOT
tickTime=2000
dataDir=/var/zookeeper
clientPort=${var.ports.client.port}
initLimit=5
syncLimit=2
%{for i, host in null_resource.numbered_hosts.*.triggers.hosts~}
server.${i}=${host}:${var.ports.server.port}:${var.ports.leader_election.port}
%{endfor}
EOT
}
}