Skip to content

Instantly share code, notes, and snippets.

@ukayani
ukayani / movestate.sh
Created January 8, 2019 20:51
Terraform/Terragrunt wrapper module state move
#!/bin/bash
# Lets say we have all resources under state /A using module A
# We decide to wrap all the resources of the module into a inner module B
# So now all resources that were orignally top level in A are now top level in B
# Normally if we try to plan our changes, terraform will want to delete all resources originally under A and create new ones under B
# However, we may not want that (what if our resources are vpc level resources that we cant afford to delete)
# Terraform provides a state move command
# We can list all the resources in a module via `terraform state list`
# We can pipe this list to xargs and for each resource we can move it to the new prefix, ie. under inner module B.
@ukayani
ukayani / main.tf
Created January 11, 2019 18:54
Kubernetes Rollout Status - Terraform External Data Source
resource "local_file" "kube_config" {
content = "${var.kube_config}"
filename = "${path.module}/kubeconfig"
}
# Hacky way to force a dependency on some external resource (since modules dont support a depends_on)
data "template_file" "deps" {
template = "${join(",", var.depends_on)}"
}