{"id":23380745,"url":"https://github.com/softonic/terraformer","last_synced_at":"2026-05-02T04:34:33.435Z","repository":{"id":66183009,"uuid":"177148133","full_name":"softonic/terraformer","owner":"softonic","description":"Terraform templating","archived":false,"fork":false,"pushed_at":"2021-10-06T10:52:44.000Z","size":15,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-02-14T04:51:17.977Z","etag":null,"topics":["gomplate","template-library","terraform"],"latest_commit_sha":null,"homepage":"https://hub.docker.com/repository/docker/softonic/terraformer","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/softonic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-22T13:47:47.000Z","updated_at":"2021-10-06T10:52:43.000Z","dependencies_parsed_at":"2023-02-23T01:15:44.251Z","dependency_job_id":null,"html_url":"https://github.com/softonic/terraformer","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softonic%2Fterraformer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softonic%2Fterraformer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softonic%2Fterraformer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softonic%2Fterraformer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/softonic","download_url":"https://codeload.github.com/softonic/terraformer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247801195,"owners_count":20998331,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gomplate","template-library","terraform"],"created_at":"2024-12-21T20:18:15.528Z","updated_at":"2026-05-02T04:34:33.398Z","avatar_url":"https://github.com/softonic.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Terraformer\n\nUse templating for terraform manifest.\nTemplates use go template syntax and must have `.tf.tpl` extension.\n\n`-f` defines config file, it is mandatory.\n`-s` defines secrets extensions if set (optional)\n\n### Files structure\n\n```bash\n$ tree .\n.\n├── backend.tf\n├── service-account.json\n├── main.tf\n├── modules\n│   └── sql\n│       ├── main.tf.tpl\n│       ├── secrets.tf.production.enc\n│       └── variables.tf\n├── provider.tf\n├── sites.yaml\n└── variables.tf\n```\n\n### Docker\n\nRun `terraformer` with `GOOGLE_APPLICATION_CREDENTIALS`.\n\n```bash\ndocker run -v ~/.terraform:/root/.terraform -v ~/.terraform.d:/root/.terraform.d -v $(pwd):/app -w /app --rm -e GOOGLE_APPLICATION_CREDENTIALS=/app/service-account.json softonic/terraformer:latest -f sites.yaml -s .production.enc init\n```\n\nRun `terraformer` Use gcloud host credentials.\n\n```bash\ndocker run -v ~/.config:/root/.config -v ~/.terraform:/root/.terraform -v ~/.terraform.d:/root/.terraform.d -v $(pwd):/app -w /app --rm softonic/terraformer:latest -f sites.yaml -s .production.enc init\n```\n\nSet alias:\n```bash\nalias terraformer=\"docker run -v ~/.config:/root/.config -v ~/.terraform:/root/.terraform -v ~/.terraform.d:/root/.terraform.d -v $(pwd):/app -w /app --rm softonic/terraformer:latest\"\n```\n\nUse aliased command:\n```bash\nterraformer -f sites.yaml -s .production.enc init\n```\n\n### Templates\n\n`main.tf.tpl` could look like below:\n\n```bash\n{{ range (ds \"sites\").site }}\nresource \"google_sql_database_instance\" \"myapp-db-{{ . }}\" {\n  name = \"myapp-db\"\n  database_version = \"MYSQL_5_7\"\n  region = \"europe-west1\"\n\n  settings {\n    tier = \"db-n1-standard-1\"\n    ip_configuration {\n      ipv4_enabled = \"false\"\n      private_network = \"${var.mynetwork}\"\n    }\n    backup_configuration {\n      binary_log_enabled = true\n      enabled = true\n    }\n    user_labels {\n      app = \"myapp\"\n    }\n  }\n}\n{{ end }}\n```\nAnd `sites.yaml`:\n\n```bash\n$ cat sites.yaml\nsite:\n- foo\n- bar\n```\n\nAnd then run `terraformer`:\n\n```bash\nterraformer -f sites.yaml\n```\n\nThe manifest applied would be equivalent of the following:\n\n```bash\nresource \"google_sql_database_instance\" \"myapp-db-foo\" {\n  name = \"myapp-db\"\n  database_version = \"MYSQL_5_7\"\n  region = \"europe-west1\"\n\n  settings {\n    tier = \"db-n1-standard-1\"\n    ip_configuration {\n      ipv4_enabled = \"false\"\n      private_network = \"${var.mynetwork}\"\n    }\n    backup_configuration {\n      binary_log_enabled = true\n      enabled = true\n    }\n    user_labels {\n      app = \"myapp\"\n    }\n  }\n}\n\nresource \"google_sql_database_instance\" \"myapp-db-bar\" {\n  name = \"myapp-db\"\n  database_version = \"MYSQL_5_7\"\n  region = \"europe-west1\"\n\n  settings {\n    tier = \"db-n1-standard-1\"\n    ip_configuration {\n      ipv4_enabled = \"false\"\n      private_network = \"${var.mynetwork}\"\n    }\n    backup_configuration {\n      binary_log_enabled = true\n      enabled = true\n    }\n    user_labels {\n      app = \"myapp\"\n    }\n  }\n}\n```\n\n### Secrets\n\n`main.tf.tpl`\n\n```bash\n{{ range (ds \"sites\").site }}\nresource \"google_sql_database_instance\" \"myapp-db-{{ . }}\" {\n  name = \"myapp-db\"\n  database_version = \"MYSQL_5_7\"\n  region = \"europe-west1\"\n\n  settings {\n    tier = \"db-n1-standard-1\"\n    ip_configuration {\n      ipv4_enabled = \"false\"\n      private_network = \"${var.mynetwork}\"\n    }\n    backup_configuration {\n      binary_log_enabled = true\n      enabled = true\n    }\n    user_labels {\n      app = \"myapp\"\n    }\n  }\n}\n\nresource \"google_sql_user\" \"myapp-db-{{ . }}\" {\n  name     = \"${var.{{ . }}_root_user}\"\n  instance = \"${google_sql_database_instance.myapp-db-{{ . }}.name}\"\n  host     = \"%\"\n  password = \"${var.{{ . }}_root_password}\"\n}\n{{ end }}\n```\n\nWe need to generate an encrypted file. Generate a temporary file: `plain.text.tf`\n\n```bash\nvariable \"foo_root_user\" {\n    default = \"fooroot\"\n}\n\nvariable \"foo_root_password\" {\n    default = \"tooroof\"\n}\n\nvariable \"bar_root_user\" {\n    default = \"barroot\"\n}\n\nvariable \"bar_root_password\" {\n    default = \"toorrab\"\n}\n```\n\nThen we need to encrypt it with a well-known extensions, that we will use later (`secrets.tf.production.enc`):\n```bash\nsops -e plain.text.tf \u003e secrets.tf.production.enc\n```\n\nThen we need to remove the plain text file:\n```bash\nrm -f plain.text.tf\n```\n\nNow we can apply the templating + secrets:\n\n```bash\nterraformer -f sites.yaml -s .production.enc\n```\n\n### Known issues\n\nTerraformer must initialize the manifest, or at least it must be initialized with a container with the same parameters, as the directory `.terraform` contains symbolic links, and it would change depending how it's mounted.\n\nIn the case host `terraform` is already initialized, `terraformer` would not work. In this case, please delete `.terraform` directory and initialize with `terraformer`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftonic%2Fterraformer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoftonic%2Fterraformer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftonic%2Fterraformer/lists"}