JimloveTM
JimloveTM

Reputation: 41

Terraform State Management with Huawei Cloud OBS using s3 Backend

This is not a question, rather my experience sharing on how to save terraform state file in Huawei Cloud Object Storage Service (OBS) incase you have similar challenge. Like you already know, terraform backend supports s3, and Huawei cloud OBS is compatible with s3. So how can we configure this correctly to save the terraform.tfstate in OBS bucket?

I followed the guide here -- https://registry.terraform.io/providers/huaweicloud/hcso/latest/docs/guides/remote-state-backend

Created a file backend.tf and pasted the code below:

terraform {
  backend "s3" {
    bucket   = "xyzbucket"
    key      = "terraform.tfstate"
    region   = "af-south-1"
    endpoint = "https://obs.af-south-1.myhuaweicloud.com"

    skip_region_validation      = true
    skip_credentials_validation = true
    skip_metadata_api_check     = true
  }
}

bucket can be any bucket you have created in the Huawei cloud OBS console choose the region and endpoint that your resources will reside -- https://developer.huaweicloud.com/intl/en-us/endpoint

Had a couple of errors as follows:

Error: Error loading state: InvalidAccessKeyId: The AWS Access Key Id you provided does not exist in our records. status code: 403

also sometimes

Error: Retrieving AWS account details: AWS account ID not previously found and failed retrieving via all available methods

By the way, my terraform version was 1.6.4

Upvotes: 0

Views: 289

Answers (1)

JimloveTM
JimloveTM

Reputation: 41

So i resolved the above errors as follows:

terraform {
  backend "s3" {
    access_key  = "your huaweicloud access key"
    secret_key  = "your huaweicloud secret key"
    bucket      = "xyzbucket"
    key         = "terraform.tfstate"
    region      = "af-south-1"
    endpoint    = "https://obs.af-south-1.myhuaweicloud.com"

    skip_region_validation      = true
    skip_credentials_validation = true
    skip_metadata_api_check     = true
    skip_requesting_account_id  = true
    skip_s3_checksum            = true
  }
}

choose the region and endpoint that your resources reside -- https://developer.huaweicloud.com/intl/en-us/endpoint

Upvotes: 0

Related Questions