This repository shows how to use IBM Cloud Object Storage (COS) as a backend to store terraform state through COS Terraform S3 compatibility.
-
Create a COS instance and bucket in IBM Cloud. Terraform is used in this step to create the COS service and the bucket as it is easier than to list all instructions that you would need to perform in the UI or the CLI.
cd 010-prepare-backend terraform init terraform apply
It generates a
backend.tf
file in020-use-backend
with the COS service instance and bucket information. Later instead of hardcoding the values inbackend.tf
, you can use environment variables to initialize the backend as described in https://www.terraform.io/docs/language/settings/backends/s3.html. -
Test the backend.
cd 020-use-backend terraform init terraform apply
-
Look into your COS bucket for a file named
global.state
.
You can benefit from COS built-in object versioning by changing the definition of the COS bucket in 010-prepare-backend/main.tf
to include the object_versioning flag.
This project is licensed under the Apache License Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0).