Skip to content

Commit

Permalink
Add billable RUM count to state version
Browse files Browse the repository at this point in the history
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 <shoekstra@schubergphilis.com>
  • Loading branch information
shoekstra authored and brandonc committed Sep 13, 2024
1 parent c53e306 commit 122d53d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
21 changes: 11 additions & 10 deletions state_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,17 @@ type StateVersionList struct {

// StateVersion represents a Terraform Enterprise state version.
type StateVersion struct {
ID string `jsonapi:"primary,state-versions"`
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
DownloadURL string `jsonapi:"attr,hosted-state-download-url"`
UploadURL string `jsonapi:"attr,hosted-state-upload-url"`
Status StateVersionStatus `jsonapi:"attr,status"`
JSONUploadURL string `jsonapi:"attr,hosted-json-state-upload-url"`
JSONDownloadURL string `jsonapi:"attr,hosted-json-state-download-url"`
Serial int64 `jsonapi:"attr,serial"`
VCSCommitSHA string `jsonapi:"attr,vcs-commit-sha"`
VCSCommitURL string `jsonapi:"attr,vcs-commit-url"`
ID string `jsonapi:"primary,state-versions"`
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
DownloadURL string `jsonapi:"attr,hosted-state-download-url"`
UploadURL string `jsonapi:"attr,hosted-state-upload-url"`
Status StateVersionStatus `jsonapi:"attr,status"`
JSONUploadURL string `jsonapi:"attr,hosted-json-state-upload-url"`
JSONDownloadURL string `jsonapi:"attr,hosted-json-state-download-url"`
Serial int64 `jsonapi:"attr,serial"`
VCSCommitSHA string `jsonapi:"attr,vcs-commit-sha"`
VCSCommitURL string `jsonapi:"attr,vcs-commit-url"`
BillableRUMCount *uint32 `jsonapi:"attr,billable-rum-count"`
// Whether HCP Terraform has finished populating any StateVersion fields that required async processing.
// If `false`, some fields may appear empty even if they should actually contain data; see comments on
// individual fields for details.
Expand Down
7 changes: 5 additions & 2 deletions state_version_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ func TestStateVersionsRead(t *testing.T) {
svTest, err := client.StateVersions.Read(ctx, svTest.ID)
require.NoError(t, err)

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

return svTest, nil
Expand All @@ -447,6 +447,9 @@ func TestStateVersionsRead(t *testing.T) {
assert.NotEmpty(t, sv.StateVersion)
assert.NotEmpty(t, sv.TerraformVersion)
assert.NotEmpty(t, sv.Outputs)

require.NotNil(t, sv.BillableRUMCount)
assert.Greater(t, *sv.BillableRUMCount, uint32(0))
})

t.Run("when the state version does not exist", func(t *testing.T) {
Expand Down
29 changes: 19 additions & 10 deletions test-fixtures/state-version/terraform.tfstate
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"version": 4,
"terraform_version": "0.12.29",
"serial": 2,
"lineage": "b2b54b23-e7ea-5500-7b15-fcb68c1d92bb",
"terraform_version": "1.3.6",
"serial": 5,
"lineage": "8094ef40-1dbd-95cd-1f60-bb25d84d883b",
"outputs": {
"test_output_list_string": {
"value": [
Expand Down Expand Up @@ -66,19 +66,28 @@
},
"resources": [
{
"module": "module.media_bucket",
"mode": "managed",
"type": "null_resource",
"name": "test",
"provider": "provider.null",
"type": "aws_s3_bucket_public_access_block",
"name": "this",
"provider": "provider[\"registry.terraform.io/hashicorp/aws\"]",
"instances": [
{
"index_key": 0,
"schema_version": 0,
"attributes": {
"id": "9023256633839603543",
"triggers": null
}
"block_public_acls": true,
"block_public_policy": true,
"bucket": "1234-edited-videos",
"id": "1234-edited-videos",
"ignore_public_acls": true,
"restrict_public_buckets": true
},
"sensitive_attributes": [],
"private": "XXXX=="
}
]
}
]
],
"check_results": null
}

0 comments on commit 122d53d

Please sign in to comment.