Skip to content

Instantly share code, notes, and snippets.

View soerenmartius's full-sized avatar
🎯
focused

Sören Martius soerenmartius

🎯
focused
View GitHub Profile
@soerenmartius
soerenmartius / fancy_generate.tm.hcl
Created February 27, 2025 11:51
Fancy Generate
globals {
dns_record_sets = [
"google.com",
"facebook.com",
]
}
generate_hcl "terramate_data.tf" {
content {
@soerenmartius
soerenmartius / generate.tm.hcl
Created February 27, 2025 11:45
conditional code generation
globals {
generate_data_source_google_ip = true
}
generate_hcl "terramate_data.tf" {
lets {
condition = tm_try(global.generate_data_source_google_ip, true)
}
content {
@soerenmartius
soerenmartius / state_count.sh
Created January 24, 2025 11:33
Naive approach to counting resources in Terraform State
terraform state list | grep -v '^data\.' | grep -v '^null_resource\.' | wc -l
@soerenmartius
soerenmartius / kubernetes.hcl
Last active April 9, 2024 20:44
Kubernetes Provider Generation
### Example on how to generate a more specific provider such as Kubernetes
# The deployment trigger is used to deferr the data source at plan time if it's not available quick is a commonly known workaround in Terraform
# In TF 1.9 this will most likely be fixes by finally allowing plan time with values that are not yet available natively https://github.com/hashicorp/terraform/releases/tag/v1.9.0-alpha20240404
globals "terraform" "providers" "kubernetes" {
source = "hashicorp/kubernetes"
version = "~> 2.16"
postpone_init_to_apply = true
enabled = true
@soerenmartius
soerenmartius / locals.hcl.tm
Created July 14, 2022 12:31
Generate Terraform locals with Terramate
# File: /projects/locals.tm.hcl
# Export env and project_id to be referenced as local.project_id and local.env
# in main.tf and other Terraform files in each stack.
generate_hcl "_terramate_generated_locals" {
content {
locals {
env = global.env
project_id = global.project_id
}
@soerenmartius
soerenmartius / generated_files.sg
Created July 14, 2022 12:12
Project Structure with Terramate generated files
projects/
├── provider.tm.hcl
├── backend.tm.hcl
├── my-project-prod/
│   ├── project.tm.hcl
│   ├── stack-1/
│   │ ├── main.tf
│   │ ├── stack.tm.hcl
│   │ ├── _terramate_generated_provider.tf
│   │ └── _terramate_generated_backend.tf
@soerenmartius
soerenmartius / backend.tm.hcl
Created July 14, 2022 12:08
Generate Terraform backend.tf files with Terramate
# File: /projects/backend.tm.hcl
# The file is prefixed with _terramate_generated here to make the generated nature
# of it more visible
generate_hcl "_terramate_generated_backend.tf" {
content {
terraform {
backend "gcs" {
bucket = "tf-state-${global.project_id}"
prefix = terramate.stack.path.absolute
@soerenmartius
soerenmartius / project.tm.hcl
Created July 14, 2022 12:07
Definition of globals with Terramate
# File: /projects/my-project-prod/project.tm.hcl
globals {
env = "prod"
project_id = "my-project-${global.env}"
}
@soerenmartius
soerenmartius / project.tm.hcl
Created July 14, 2022 12:06
Definition of globals with Terramate
# File: /projects/my-project-staging/project.tm.hcl
globals {
env = "staging"
project_id = "my-project-${global.env}"
}
@soerenmartius
soerenmartius / providers.hcl.tm
Last active July 14, 2022 12:00
Terramate provider definition in providers.hcl.tm
# File: /projects/providers.tm.hcl
globals {
# The default project_id to configure the provider with.
# The provider_id can be set at any level in the hierarchy.
# If no project_id the provider fallbacks are used.
terraform_google_provider_project = tm_try(global.project_id, null)
# The default region to configure
terraform_google_provider_region = "europe-north1"