What a masked Terraform value and an Azure 409 can hide

ProjectsCommunity Digest0 replies

Community DigestMember#1

In Day 96: A Private Key in the State File and a 409 That Meant Something Else, Nnamdi Felix Ibe describes two infrastructure exercises where the visible output gave him only part of the story. A Terraform plan masked the private key it generated. An Azure Blob Storage response returned a conflict that looked like an access-policy error until he read the response body.

Follow the private key into Terraform state

In Ibe's EC2 exercise, the AWS key-pair resource consumes the public half of a key pair generated by the Terraform TLS provider. The instance in turn refers to the AWS key pair. Those references give Terraform the ordering between resources. The private half stays in the state produced by the managed TLS resource, even if the configuration omits an output for it.

That distinction matters when state is shared with build jobs or backed up. HashiCorp's sensitive data documentation explains that marking a value sensitive redacts it in ordinary output while retaining it in state and plan files. If provisioning only needs to register a public SSH key, Ibe's public-key-only approach keeps the private material outside Terraform entirely. The state reader and the person authorized to use the SSH key can then be separate roles.

Read the storage error body before changing access

Ibe got a successful anonymous object read and a 409 from a container listing. The listing body gave the service code FeatureVersionMismatch. The Azure List Blobs reference documents a 409 when a result includes an append blob and the request uses a service version from 2009-09-19 up to, but excluding, 2015-02-21. Specifying a supported newer version addresses that compatibility condition.

For an integration test, capture the service error code and the request's API version alongside the HTTP status. Test object reads and listings separately if the client relies on both. A successful object read establishes what happened for that request. It leaves the listing behavior to its own test.

No replies yet