Skip to content

Commit 122d53d

Browse files
shoekstrabrandonc
authored andcommitted
Add billable RUM count to state version
Billable RUM count is now part of the workspace endpoint attributes and can be used to get the amount of billable RUM rather than iterating over the resources in the workspace/state. Signed-off-by: Stephen Hoekstra <[email protected]>
1 parent c53e306 commit 122d53d

File tree

3 files changed

+35
-22
lines changed

3 files changed

+35
-22
lines changed

state_version.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,17 @@ type StateVersionList struct {
8989

9090
// StateVersion represents a Terraform Enterprise state version.
9191
type StateVersion struct {
92-
ID string `jsonapi:"primary,state-versions"`
93-
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
94-
DownloadURL string `jsonapi:"attr,hosted-state-download-url"`
95-
UploadURL string `jsonapi:"attr,hosted-state-upload-url"`
96-
Status StateVersionStatus `jsonapi:"attr,status"`
97-
JSONUploadURL string `jsonapi:"attr,hosted-json-state-upload-url"`
98-
JSONDownloadURL string `jsonapi:"attr,hosted-json-state-download-url"`
99-
Serial int64 `jsonapi:"attr,serial"`
100-
VCSCommitSHA string `jsonapi:"attr,vcs-commit-sha"`
101-
VCSCommitURL string `jsonapi:"attr,vcs-commit-url"`
92+
ID string `jsonapi:"primary,state-versions"`
93+
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
94+
DownloadURL string `jsonapi:"attr,hosted-state-download-url"`
95+
UploadURL string `jsonapi:"attr,hosted-state-upload-url"`
96+
Status StateVersionStatus `jsonapi:"attr,status"`
97+
JSONUploadURL string `jsonapi:"attr,hosted-json-state-upload-url"`
98+
JSONDownloadURL string `jsonapi:"attr,hosted-json-state-download-url"`
99+
Serial int64 `jsonapi:"attr,serial"`
100+
VCSCommitSHA string `jsonapi:"attr,vcs-commit-sha"`
101+
VCSCommitURL string `jsonapi:"attr,vcs-commit-url"`
102+
BillableRUMCount *uint32 `jsonapi:"attr,billable-rum-count"`
102103
// Whether HCP Terraform has finished populating any StateVersion fields that required async processing.
103104
// If `false`, some fields may appear empty even if they should actually contain data; see comments on
104105
// individual fields for details.

state_version_integration_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,8 @@ func TestStateVersionsRead(t *testing.T) {
426426
svTest, err := client.StateVersions.Read(ctx, svTest.ID)
427427
require.NoError(t, err)
428428

429-
if !svTest.ResourcesProcessed {
430-
return nil, fmt.Errorf("resources not processed %s", err)
429+
if !svTest.ResourcesProcessed || svTest.BillableRUMCount == nil || *svTest.BillableRUMCount == 0 {
430+
return nil, fmt.Errorf("resources not processed %v / %d", svTest.ResourcesProcessed, svTest.BillableRUMCount)
431431
}
432432

433433
return svTest, nil
@@ -447,6 +447,9 @@ func TestStateVersionsRead(t *testing.T) {
447447
assert.NotEmpty(t, sv.StateVersion)
448448
assert.NotEmpty(t, sv.TerraformVersion)
449449
assert.NotEmpty(t, sv.Outputs)
450+
451+
require.NotNil(t, sv.BillableRUMCount)
452+
assert.Greater(t, *sv.BillableRUMCount, uint32(0))
450453
})
451454

452455
t.Run("when the state version does not exist", func(t *testing.T) {

test-fixtures/state-version/terraform.tfstate

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"version": 4,
3-
"terraform_version": "0.12.29",
4-
"serial": 2,
5-
"lineage": "b2b54b23-e7ea-5500-7b15-fcb68c1d92bb",
3+
"terraform_version": "1.3.6",
4+
"serial": 5,
5+
"lineage": "8094ef40-1dbd-95cd-1f60-bb25d84d883b",
66
"outputs": {
77
"test_output_list_string": {
88
"value": [
@@ -66,19 +66,28 @@
6666
},
6767
"resources": [
6868
{
69+
"module": "module.media_bucket",
6970
"mode": "managed",
70-
"type": "null_resource",
71-
"name": "test",
72-
"provider": "provider.null",
71+
"type": "aws_s3_bucket_public_access_block",
72+
"name": "this",
73+
"provider": "provider[\"registry.terraform.io/hashicorp/aws\"]",
7374
"instances": [
7475
{
76+
"index_key": 0,
7577
"schema_version": 0,
7678
"attributes": {
77-
"id": "9023256633839603543",
78-
"triggers": null
79-
}
79+
"block_public_acls": true,
80+
"block_public_policy": true,
81+
"bucket": "1234-edited-videos",
82+
"id": "1234-edited-videos",
83+
"ignore_public_acls": true,
84+
"restrict_public_buckets": true
85+
},
86+
"sensitive_attributes": [],
87+
"private": "XXXX=="
8088
}
8189
]
8290
}
83-
]
91+
],
92+
"check_results": null
8493
}

0 commit comments

Comments
 (0)