{"id":20700757,"url":"https://github.com/l2fprod/serverless-terraform-backend","last_synced_at":"2025-05-10T19:32:15.131Z","repository":{"id":51286698,"uuid":"126471161","full_name":"l2fprod/serverless-terraform-backend","owner":"l2fprod","description":"A serverless backend for Terraform","archived":true,"fork":false,"pushed_at":"2021-05-17T17:50:09.000Z","size":266,"stargazers_count":16,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-22T16:50:42.885Z","etag":null,"topics":["ibmcloud","openwhisk","serverless","terraform","terraform-backend"],"latest_commit_sha":null,"homepage":"https://www.ibm.com/cloud/blog/store-terraform-states-cloud-object-storage","language":"JavaScript","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/l2fprod.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":null,"security":null,"support":null}},"created_at":"2018-03-23T10:39:59.000Z","updated_at":"2024-01-17T20:35:03.000Z","dependencies_parsed_at":"2022-09-24T13:11:54.026Z","dependency_job_id":null,"html_url":"https://github.com/l2fprod/serverless-terraform-backend","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/l2fprod%2Fserverless-terraform-backend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/l2fprod%2Fserverless-terraform-backend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/l2fprod%2Fserverless-terraform-backend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/l2fprod%2Fserverless-terraform-backend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/l2fprod","download_url":"https://codeload.github.com/l2fprod/serverless-terraform-backend/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253471347,"owners_count":21913839,"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":["ibmcloud","openwhisk","serverless","terraform","terraform-backend"],"created_at":"2024-11-17T00:37:00.005Z","updated_at":"2025-05-10T19:32:14.877Z","avatar_url":"https://github.com/l2fprod.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A serverless backend for Terraform\n\nTerraform offers several [backend types](https://www.terraform.io/docs/language/settings/backends/index.html). One of them is the [**http**](https://www.terraform.io/docs/language/settings/backends/http.html) backend which stores Terraform states using a REST client.\n\nThis project provides an implementation of the REST backend using serverless [IBM Cloud Functions](https://cloud.ibm.com/functions/) and [IBM Cloud Object Storage (COS)](https://cloud.ibm.com/catalog/services/cloud-object-storage) with **optional [state locking](https://www.terraform.io/docs/language/state/locking.html)** and **versioning** of Terraform states.\n\n## Step 1 - Prepare the backend\n\nThis first step creates:\n- a resource group,\n- a COS instance with a bucket,\n- Cloud Functions namespace, package and action.\n\nIt uses terraform to create the resources :)\n\n![create action and bucket](./xdocs/step-010.png)\n\n1. Change to the step directory\n   ```\n   cd 010-prepare-backend\n   ```\n1. Copy the terraform configuration\n   ```\n   cp terraform.tfvars.template terraform.tfvars\n   ```\n1. Edit `terraform.tfvars` to match your environment\n1. Create the resources\n   ```\n   terraform init\n   terraform apply\n   ```\n\n   \u003e It creates the resources and generates a `backend.env` file in 020-use-backend with the backend address and password.\n\n## Step 2 - Test the backend\n\n1. Change to the step directory\n   ```\n   cd 020-use-backend\n   ```\n1. Load the backend configuration variables\n   ```\n   source backend.env\n   ```\n1. Test the backend\n   ```\n   terraform init\n   terraform apply\n1. In IBM Cloud console,\n   - go to the COS service instance,\n   - select the bucket\n   - find the `dev.tfstate` under `states/named`\n\n## Advanced configuration\n\nYou can configure the generated `backend.env` to suit your needs by changing the value of the `env` and `versioning` parameters or commenting the lock/unlock address to disable locking:\n\n```\n# TF_HTTP_ADDRESS points to the Cloud Functions action implementing the backend.\n# It is reused for locking implementation too.\n#\n# env: name for the terraform state, e.g mystate, us/south/staging (.tfstate will be added automatically)\n# versioning: set to true to keep multiple copies of the states in the storage\nexport TF_HTTP_ADDRESS=\"https://us-south.functions.cloud.ibm.com/api/v1/web/1234-5678/serverless-terraform-backend-package/backend?env=dev\u0026versioning=true\"\nexport TF_HTTP_PASSWORD=\"\u003cCOS-API-KEY\u003e\"\n\n# comment the following variables to disable locking\nexport TF_HTTP_LOCK_ADDRESS=$TF_HTTP_ADDRESS\nexport TF_HTTP_UNLOCK_ADDRESS=$TF_HTTP_ADDRESS\n```\n\n## License\n\nThis project is licensed under the Apache License Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fl2fprod%2Fserverless-terraform-backend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fl2fprod%2Fserverless-terraform-backend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fl2fprod%2Fserverless-terraform-backend/lists"}