fix(ec2): omit empty stateReason element in DescribeInstances (#1410)

* fix(core): use self-closing tags for empty XmlBuilder values

XmlBuilder.elem(name, "") produced <name></name> for empty string values, which caused some XML consumers (e.g. Terraform AWS provider) to crash with nil pointer dereference.

Now empty string values render as self-closing <name/> instead, which is semantically identical but avoids the parser crash. Null values remain skipped entirely.

* fix(ec2): conditionally omit stateReason instead of self-closing empty tags

The previous approach (self-closing tags for empty XmlBuilder values)
was wrong for two reasons:
1. AWS emits <tag></tag> (paired tags), not <tag/> — verified against
   botocore rest-xml protocol fixtures (XmlEmptyStrings, XmlEmptyBlobs).
2. Go's encoding/xml tokenizes both forms identically (StartElement +
   EndElement, no CharData), so the Terraform crash persisted either way.

Real fix: stop hardcoding <stateReason><code></code><message></message>
in Ec2QueryHandler for every instance. AWS omits stateReason entirely
when there is none (e.g. a running instance). Now it is only emitted
when stateReasonCode or stateReasonMessage is present.

XmlBuilder.elem() reverted to its original paired-tag behavior.
Added Instance.stateReasonCode/stateReasonMessage model fields.
Updated Ec2InstanceResponseShapeTest to assert null for running
instances (matching real AWS behavior).
This commit is contained in:
José Miguel González Guzmán authored and GitHub committed 2026-06-19 19:03:50 -05:00
1 parent 4bd43020d5
commit b4ee4ca489
3 files changed
+21 -9

No files matched your search

@@ -180,11 +180,13 @@ class Ec2InstanceResponseShapeTest {
@Test
@Order(9)
@DisplayName("stateReason is not null")
@DisplayName("stateReason is null for a running instance")
void stateReason() {
assertThat(instance.stateReason())
.as("stateReason must not be null — Terraform reads Code and Message")
.isNotNull();
.as("stateReason must be null for a running instance with no state reason. " +
"AWS omits the element entirely; a non-null stateReason with empty code/message " +
"crashes Terraform's Go XML decoder.")
.isNull();
}
@Test