Skip to content

Commit

Permalink
Merge pull request #974 from hashicorp/add_billable_rum_count
Browse files Browse the repository at this point in the history
Add billable RUM count to state version
  • Loading branch information
brandonc authored Sep 13, 2024
2 parents c53e306 + e5e5287 commit bd1cdb9
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 27 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# UNRELEASED

## Enhancements

* Adds `billable-rum-count` attribute to `StateVersion` by @shoekstra [#974](https://github.com/hashicorp/go-tfe/pull/974)

# v1.65.0

## Enhancements
Expand Down
7 changes: 6 additions & 1 deletion helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,13 +576,18 @@ func createNotificationConfiguration(t *testing.T, client *Client, w *Workspace,
w, wCleanup = createWorkspace(t, client, nil)
}

runTaskURL := os.Getenv("TFC_RUN_TASK_URL")
if runTaskURL == "" {
t.Skip("Cannot create a notification configuration with an empty URL. You must set TFC_RUN_TASK_URL for run task related tests.")
}

if options == nil {
options = &NotificationConfigurationCreateOptions{
DestinationType: NotificationDestination(NotificationDestinationTypeGeneric),
Enabled: Bool(false),
Name: String(randomString(t)),
Token: String(randomString(t)),
URL: String("http://example.com"),
URL: String(runTaskURL),
Triggers: []NotificationTriggerType{NotificationTriggerCreated},
}
}
Expand Down
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
}
8 changes: 4 additions & 4 deletions workspace_resources_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ func TestWorkspaceResourcesList(t *testing.T) {
assert.Equal(t, 1, rs.CurrentPage)
assert.Equal(t, 1, rs.TotalCount)

assert.Equal(t, "null_resource.test", rs.Items[0].Address)
assert.Equal(t, "test", rs.Items[0].Name)
assert.Equal(t, "root", rs.Items[0].Module)
assert.Equal(t, "null", rs.Items[0].Provider)
assert.Equal(t, "media_bucket.aws_s3_bucket_public_access_block.this[0]", rs.Items[0].Address)
assert.Equal(t, "this", rs.Items[0].Name)
assert.Equal(t, "media_bucket", rs.Items[0].Module)
assert.Equal(t, "hashicorp/aws", rs.Items[0].Provider)
})
t.Run("with list options", func(t *testing.T) {
rs, err := client.WorkspaceResources.List(ctx, wTest.ID, &WorkspaceResourceListOptions{
Expand Down

0 comments on commit bd1cdb9

Please sign in to comment.