hashicorp/terraform · error

error getting bucket: %#v

Error message

error getting bucket: %#v

What it means

Thrown by RemoteClient.Put when ossClient.Bucket(c.bucketName) fails just before uploading state. Same SDK bucket-resolution failure as in Workspaces, but on the write path.

Solutions

  1. Validate bucket name format and region/endpoint consistency.
  2. Refresh credentials (re-run init, or fix RAM role attachment) if the run was long-lived.
  3. Re-run 'terraform init' to rebuild the OSS client.
  4. Check SDK/alibaba-cloud-go version compatibility.
Defensive patterns

Strategy: validation

Validate before calling

if !validBucketName(c.bucketName) { return fmt.Errorf("invalid bucket name %q", c.bucketName) }

Type guard

func validBucketName(name string) bool {
    if len(name) < 3 || len(name) > 63 { return false }
    m, _ := regexp.MatchString(`^[a-z0-9][a-z0-9.-]*[a-z0-9]$`, name); return m
}

Prevention

When it happens

Trigger: Bucket() returns an error during state upload — invalid bucket name, client misconfiguration, or stale/expired credentials being used for the write.

Common situations: STS token expired mid-run; bucket name has illegal characters; endpoint mismatch; SDK init defect; running on ECS with a RAM role whose refresh just failed.

Related errors


AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11). Data as JSON: /api/errors/3ccdc8dd8004e45f. Report an issue: GitHub.

Appendix: source

Thrown at internal/backend/remote-state/oss/client.go:104

			if time.Now().Before(deadline) {
				time.Sleep(consistencyRetryPollInterval)
				log.Println("[INFO] retrying OSS RemoteClient.Get...")
				continue
			}

			return nil, diags.Append(fmt.Errorf(errBadChecksumFmt, digest))
		}

		break
	}
	return payload, diags
}

func (c *RemoteClient) Put(data []byte) tfdiags.Diagnostics {
	var diags tfdiags.Diagnostics
	bucket, err := c.ossClient.Bucket(c.bucketName)
	if err != nil {
		return diags.Append(fmt.Errorf("error getting bucket: %#v", err))
	}

	body := bytes.NewReader(data)

	var options []oss.Option
	if c.acl != "" {
		options = append(options, oss.ACL(oss.ACLType(c.acl)))
	}
	options = append(options, oss.ContentType("application/json"))
	if c.serverSideEncryption {
		options = append(options, oss.ServerSideEncryption("AES256"))
	}
	options = append(options, oss.ContentLength(int64(len(data))))

	if body != nil {
		if err := bucket.PutObject(c.stateFile, body, options...); err != nil {
			return diags.Append(fmt.Errorf("failed to upload state %s: %#v", c.stateFile, err))
		}

View on GitHub (pinned to d32a084675)