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 / 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"
@soerenmartius
soerenmartius / stack.hcl.tm
Created July 14, 2022 11:55
Example Terramate Stack Definition
# File: /projects/<project>/<stack>/stack.tm.hcl
stack {
name = "My awesome <stack>"
description = "This stack defines awesome resources"
}
@soerenmartius
soerenmartius / provider.tf
Created July 14, 2022 11:21
Terraform provider.tf example
# File: /projects/my-project-<env>/<stack>/provider.tf
provider "google" {
project = "my-project-<env>"
region = "europe-north1"
}
terraform {
required_providers {
google = {
@soerenmartius
soerenmartius / example_terraform_google_cloud_project_structure.sh
Created July 14, 2022 11:19
Example Terraform Google Cloud Project Structure
projects/
├── my-project-prod/
│   ├── stack-1/
│   │ ├── main.tf
│   │ ├── provider.tf
│   │ └── backend.tf
│   └── stack-2/
│   │ ├── main.tf
│   │ ├── provider.tf
│   │ └── backend.tf