diff --git a/01_example_outputs/aks/backend.tf b/01_example_outputs/aks/backend.tf new file mode 100644 index 0000000..1921ded --- /dev/null +++ b/01_example_outputs/aks/backend.tf @@ -0,0 +1,11 @@ +// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT + +terraform { + backend "azurerm" { + container_name = "tfstate" + key = "terraform/stacks/by-id/d0901d9c-0854-4af8-b0ca-813a63d1aaac/terraform.tfstate" + resource_group_name = "tfstate" + storage_account_name = "tfstatexscz2" + use_oidc = true + } +} diff --git a/01_example_outputs/flux/backend.tf b/01_example_outputs/flux/backend.tf new file mode 100644 index 0000000..9018008 --- /dev/null +++ b/01_example_outputs/flux/backend.tf @@ -0,0 +1,11 @@ +// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT + +terraform { + backend "azurerm" { + container_name = "tfstate" + key = "terraform/stacks/by-id/6cd87f96-218f-4a72-8be1-88104b460c05/terraform.tfstate" + resource_group_name = "tfstate" + storage_account_name = "tfstatexscz2" + use_oidc = true + } +} diff --git a/01_example_outputs/network/backend.tf b/01_example_outputs/network/backend.tf new file mode 100644 index 0000000..8df25ed --- /dev/null +++ b/01_example_outputs/network/backend.tf @@ -0,0 +1,11 @@ +// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT + +terraform { + backend "azurerm" { + container_name = "tfstate" + key = "terraform/stacks/by-id/f20c9067-70ef-4489-8a70-9d1580ab67f7/terraform.tfstate" + resource_group_name = "tfstate" + storage_account_name = "tfstatexscz2" + use_oidc = true + } +} diff --git a/02_example_data_sources/network/aks/backend.tf b/02_example_data_sources/network/aks/backend.tf new file mode 100644 index 0000000..9e38d57 --- /dev/null +++ b/02_example_data_sources/network/aks/backend.tf @@ -0,0 +1,11 @@ +// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT + +terraform { + backend "azurerm" { + container_name = "tfstate" + key = "terraform/stacks/by-id/5d97b4f1-4e0a-4831-8ea8-ad2d1b90f7b5/terraform.tfstate" + resource_group_name = "tfstate" + storage_account_name = "tfstatexscz2" + use_oidc = true + } +} diff --git a/02_example_data_sources/network/aks/data.tf b/02_example_data_sources/network/aks/data.tf new file mode 100644 index 0000000..7f85295 --- /dev/null +++ b/02_example_data_sources/network/aks/data.tf @@ -0,0 +1,15 @@ +// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT + +data "terraform_remote_state" "vpc" { + backend = "azurerm" + config = { + container_name = "tfstate" + key = "terraform/stacks/by-id/5999e860-86d6-49b6-aa18-c91df7586483/terraform.tfstate" + storage_account_name = "tfstatexscz2" + } + depends_on = [ + null_resource.deployment_trigger, + ] +} +resource "null_resource" "deployment_trigger" { +} diff --git a/02_example_data_sources/network/aks/data.tf.tmgen b/02_example_data_sources/network/aks/data.tf.tmgen new file mode 100644 index 0000000..e794b19 --- /dev/null +++ b/02_example_data_sources/network/aks/data.tf.tmgen @@ -0,0 +1,12 @@ +data "terraform_remote_state" "vpc" { + backend = "azurerm" + config = { + storage_account_name = global.terraform.backend.azurerm.storage_account_name + container_name = tm_try(global.terraform.backend.azurerm.container_name, "tfstate") + key = "terraform/stacks/by-id/${global.from_stack}/terraform.tfstate" + } + + depends_on = [null_resource.deployment_trigger] +} + +resource "null_resource" "deployment_trigger" {} diff --git a/02_example_data_sources/network/aks/flux/backend.tf b/02_example_data_sources/network/aks/flux/backend.tf new file mode 100644 index 0000000..9d9d120 --- /dev/null +++ b/02_example_data_sources/network/aks/flux/backend.tf @@ -0,0 +1,11 @@ +// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT + +terraform { + backend "azurerm" { + container_name = "tfstate" + key = "terraform/stacks/by-id/2ac5c655-b876-44dd-8ab7-137d07e67097/terraform.tfstate" + resource_group_name = "tfstate" + storage_account_name = "tfstatexscz2" + use_oidc = true + } +} diff --git a/02_example_data_sources/network/aks/flux/data.tf b/02_example_data_sources/network/aks/flux/data.tf new file mode 100644 index 0000000..56ee6ec --- /dev/null +++ b/02_example_data_sources/network/aks/flux/data.tf @@ -0,0 +1,15 @@ +// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT + +data "terraform_remote_state" "cluster" { + backend = "azurerm" + config = { + container_name = "tfstate" + key = "terraform/stacks/by-id/5d97b4f1-4e0a-4831-8ea8-ad2d1b90f7b5/terraform.tfstate" + storage_account_name = "tfstatexscz2" + } + depends_on = [ + null_resource.deployment_trigger, + ] +} +resource "null_resource" "deployment_trigger" { +} diff --git a/02_example_data_sources/network/aks/flux/data.tf.tmgen b/02_example_data_sources/network/aks/flux/data.tf.tmgen new file mode 100644 index 0000000..f04a1d8 --- /dev/null +++ b/02_example_data_sources/network/aks/flux/data.tf.tmgen @@ -0,0 +1,12 @@ +data "terraform_remote_state" "cluster" { + backend = "azurerm" + config = { + storage_account_name = global.terraform.backend.azurerm.storage_account_name + container_name = tm_try(global.terraform.backend.azurerm.container_name, "tfstate") + key = "terraform/stacks/by-id/${global.from_stack}/terraform.tfstate" + } + + depends_on = [null_resource.deployment_trigger] +} + +resource "null_resource" "deployment_trigger" {} diff --git a/02_example_data_sources/network/aks/flux/main.tf b/02_example_data_sources/network/aks/flux/main.tf index 3707b9e..9735037 100644 --- a/02_example_data_sources/network/aks/flux/main.tf +++ b/02_example_data_sources/network/aks/flux/main.tf @@ -3,25 +3,6 @@ provider "azurerm" { features {} } -data "terraform_remote_state" "cluster" { - backend = "local" - - config = { - path = "../terraform.tfstate" - } - - depends_on = [null_resource.deployment_trigger] -} - -# data "azurerm_kubernetes_cluster" "cluster" { -# name = "dev2-aks-cluster-aks" -# resource_group_name = "${var.environment}-aks-env-out" - -# depends_on = [null_resource.deployment_trigger] -# } - -resource "null_resource" "deployment_trigger" {} - provider "helm" { kubernetes { host = "https://${data.terraform_remote_state.cluster.outputs.host}" diff --git a/02_example_data_sources/network/aks/flux/stack.tm.hcl b/02_example_data_sources/network/aks/flux/stack.tm.hcl index bbf5266..444863a 100644 --- a/02_example_data_sources/network/aks/flux/stack.tm.hcl +++ b/02_example_data_sources/network/aks/flux/stack.tm.hcl @@ -3,3 +3,7 @@ stack { description = "Flux Controller deployed via Helm in Kubernetes" id = "2ac5c655-b876-44dd-8ab7-137d07e67097" } + +globals { + from_stack = "5d97b4f1-4e0a-4831-8ea8-ad2d1b90f7b5" +} diff --git a/02_example_data_sources/network/aks/main.tf b/02_example_data_sources/network/aks/main.tf index e71e28f..f9fe0e4 100644 --- a/02_example_data_sources/network/aks/main.tf +++ b/02_example_data_sources/network/aks/main.tf @@ -20,17 +20,16 @@ resource "random_id" "name" { # depends_on = [null_resource.deployment_trigger] # } -data "terraform_remote_state" "vpc" { - backend = "local" +# data "terraform_remote_state" "vpc" { +# backend = "local" - config = { - path = "../terraform.tfstate" - } +# config = { +# path = "../terraform.tfstate" +# } - depends_on = [null_resource.deployment_trigger] -} +# depends_on = [null_resource.deployment_trigger] +# } -resource "null_resource" "deployment_trigger" {} module "cluster" { source = "Azure/aks/azurerm" diff --git a/02_example_data_sources/network/aks/stack.tm.hcl b/02_example_data_sources/network/aks/stack.tm.hcl index f1800a1..e67ca82 100644 --- a/02_example_data_sources/network/aks/stack.tm.hcl +++ b/02_example_data_sources/network/aks/stack.tm.hcl @@ -3,3 +3,7 @@ stack { description = "Managed Kubernetes cluster on Azure" id = "5d97b4f1-4e0a-4831-8ea8-ad2d1b90f7b5" } + +globals { + from_stack = "5999e860-86d6-49b6-aa18-c91df7586483" +} diff --git a/02_example_data_sources/network/backend.tf b/02_example_data_sources/network/backend.tf new file mode 100644 index 0000000..11d1ba1 --- /dev/null +++ b/02_example_data_sources/network/backend.tf @@ -0,0 +1,11 @@ +// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT + +terraform { + backend "azurerm" { + container_name = "tfstate" + key = "terraform/stacks/by-id/5999e860-86d6-49b6-aa18-c91df7586483/terraform.tfstate" + resource_group_name = "tfstate" + storage_account_name = "tfstatexscz2" + use_oidc = true + } +} diff --git a/config.tm.hcl b/config.tm.hcl new file mode 100644 index 0000000..0563710 --- /dev/null +++ b/config.tm.hcl @@ -0,0 +1,21 @@ +# globals "tofu" { +# version = "1.8.5" +# } + +# globals "terraform" { +# version = "1.9.8" +# } + +globals "terraform" "providers" "azurerm" { + enabled = true + + source = "hashicorp/azurerm" + version = "~> 3.0" + features = {} +} + +globals "terraform" "backend" "azurerm" { + resource_group_name = "tfstate" + storage_account_name = "tfstatexscz2" + container_name = "tfstate" +} diff --git a/imports.tm.hcl b/imports.tm.hcl new file mode 100644 index 0000000..669f7a2 --- /dev/null +++ b/imports.tm.hcl @@ -0,0 +1,3 @@ +import { + source = "./imports/*.tm.hcl" +} diff --git a/imports/backend.tm.hcl b/imports/backend.tm.hcl new file mode 100644 index 0000000..177ee85 --- /dev/null +++ b/imports/backend.tm.hcl @@ -0,0 +1,18 @@ +generate_hcl "backend.tf" { + condition = tm_alltrue([ + tm_can(tm_try(global.terraform.backend.azurerm, false)), + !tm_contains(terramate.stack.tags, "no-backend") + ]) + + content { + terraform { + backend "azurerm" { + resource_group_name = global.terraform.backend.azurerm.resource_group_name + storage_account_name = global.terraform.backend.azurerm.storage_account_name + container_name = tm_try(global.terraform.backend.azurerm.container_name, "tfstate") + key = "terraform/stacks/by-id/${terramate.stack.id}/terraform.tfstate" + use_oidc = true + } + } + } +} diff --git a/terramate.tm.hcl b/terramate.tm.hcl index 4d1ebcf..93bccba 100644 --- a/terramate.tm.hcl +++ b/terramate.tm.hcl @@ -29,10 +29,11 @@ terramate { } } - # Enable Terramate Scripts + # Enable Features experiments = [ "scripts", "outputs-sharing", + "tmgen" ] } }