Skip to content

Commit bd1cdb9

Browse files
authored
Merge pull request #974 from hashicorp/add_billable_rum_count
Add billable RUM count to state version
2 parents c53e306 + e5e5287 commit bd1cdb9

File tree

6 files changed

+49
-27
lines changed

6 files changed

+49
-27
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# UNRELEASED
22

3+
## Enhancements
4+
5+
* Adds `billable-rum-count` attribute to `StateVersion` by @shoekstra [#974](https://github.com/hashicorp/go-tfe/pull/974)
6+
37
# v1.65.0
48

59
## Enhancements

helper_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,13 +576,18 @@ func createNotificationConfiguration(t *testing.T, client *Client, w *Workspace,
576576
w, wCleanup = createWorkspace(t, client, nil)
577577
}
578578

579+
runTaskURL := os.Getenv("TFC_RUN_TASK_URL")
580+
if runTaskURL == "" {
581+
t.Skip("Cannot create a notification configuration with an empty URL. You must set TFC_RUN_TASK_URL for run task related tests.")
582+
}
583+
579584
if options == nil {
580585
options = &NotificationConfigurationCreateOptions{
581586
DestinationType: NotificationDestination(NotificationDestinationTypeGeneric),
582587
Enabled: Bool(false),
583588
Name: String(randomString(t)),
584589
Token: String(randomString(t)),
585-
URL: String("http://example.com"),
590+
URL: String(runTaskURL),
586591
Triggers: []NotificationTriggerType{NotificationTriggerCreated},
587592
}
588593
}

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
}

workspace_resources_integration_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ func TestWorkspaceResourcesList(t *testing.T) {
3434
assert.Equal(t, 1, rs.CurrentPage)
3535
assert.Equal(t, 1, rs.TotalCount)
3636

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

0 commit comments

Comments
 (0)