diff --git a/CHANGELOG.md b/CHANGELOG.md index 05bf45f1a..ed1472c9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/helper_test.go b/helper_test.go index 35b7fea63..9098674e5 100644 --- a/helper_test.go +++ b/helper_test.go @@ -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}, } } diff --git a/state_version.go b/state_version.go index 5dce6e0e9..a90f8a0a0 100644 --- a/state_version.go +++ b/state_version.go @@ -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. diff --git a/state_version_integration_test.go b/state_version_integration_test.go index 927006648..dc854831e 100644 --- a/state_version_integration_test.go +++ b/state_version_integration_test.go @@ -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 @@ -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) { diff --git a/test-fixtures/state-version/terraform.tfstate b/test-fixtures/state-version/terraform.tfstate index af39d30c0..d3f67b580 100644 --- a/test-fixtures/state-version/terraform.tfstate +++ b/test-fixtures/state-version/terraform.tfstate @@ -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": [ @@ -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 } diff --git a/workspace_resources_integration_test.go b/workspace_resources_integration_test.go index 9c3e9e13e..bed84ed3a 100644 --- a/workspace_resources_integration_test.go +++ b/workspace_resources_integration_test.go @@ -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{