-
Notifications
You must be signed in to change notification settings - Fork 104
Implement endpoint for deployment-run list #1134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
shwetamurali
merged 10 commits into
main
from
TF-25652-go_tfe_endpoint_deployment_run_list
Jun 17, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d84451c
initial commit
shwetamurali 27e06a9
change
shwetamurali dc04969
change
shwetamurali 0f91724
Update CHANGELOG.md
shwetamurali 3dc0376
remove comments
shwetamurali a002a68
Merge branch 'main' into TF-25652-go_tfe_endpoint_deployment_run_list
ctrombley 825502b
Update stack_deployment_run.go
shwetamurali 9209ce7
Merge branch 'TF-25652-go_tfe_endpoint_deployment_run_list' of https:…
shwetamurali 9b633bb
change file name
shwetamurali 7e09a99
also change test file name
shwetamurali File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // Copyright (c) HashiCorp, Inc. | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package tfe | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "net/url" | ||
| "time" | ||
| ) | ||
|
|
||
| // StackDeploymentRuns describes all the stack deployment runs-related methods that the HCP Terraform API supports. | ||
| type StackDeploymentRuns interface { | ||
| // List returns a list of stack deployment runs for a given deployment group. | ||
| List(ctx context.Context, deploymentGroupID string, options *StackDeploymentRunListOptions) (*StackDeploymentRunList, error) | ||
| } | ||
|
|
||
| // stackDeploymentRuns implements StackDeploymentRuns. | ||
| type stackDeploymentRuns struct { | ||
| client *Client | ||
| } | ||
|
|
||
| var _ StackDeploymentRuns = &stackDeploymentRuns{} | ||
|
|
||
| // StackDeploymentRun represents a stack deployment run. | ||
| type StackDeploymentRun struct { | ||
| ID string `jsonapi:"primary,stacks-deployment-runs"` | ||
| Status string `jsonapi:"attr,status"` | ||
| StartedAt time.Time `jsonapi:"attr,started-at,iso8601"` | ||
| CompletedAt time.Time `jsonapi:"attr,completed-at,iso8601"` | ||
|
|
||
| // Relationships | ||
| StackDeploymentGroup *StackDeploymentGroup `jsonapi:"relation,stack-deployment-group"` | ||
| } | ||
|
|
||
| // StackDeploymentRunList represents a list of stack deployment runs. | ||
| type StackDeploymentRunList struct { | ||
| *Pagination | ||
| Items []*StackDeploymentRun | ||
| } | ||
|
|
||
| // StackDeploymentRunListOptions represents the options for listing stack deployment runs. | ||
| type StackDeploymentRunListOptions struct { | ||
| ListOptions | ||
| } | ||
|
|
||
| // List returns a list of stack deployment runs for a given deployment group. | ||
| func (s *stackDeploymentRuns) List(ctx context.Context, deploymentGroupID string, options *StackDeploymentRunListOptions) (*StackDeploymentRunList, error) { | ||
| req, err := s.client.NewRequest("GET", fmt.Sprintf("stack-deployment-groups/%s/stack-deployment-runs", url.PathEscape(deploymentGroupID)), options) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| sdrl := &StackDeploymentRunList{} | ||
| err = req.Do(ctx, sdrl) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return sdrl, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| // Copyright (c) HashiCorp, Inc. | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package tfe | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestStackDeploymentRunList(t *testing.T) { | ||
| skipUnlessBeta(t) | ||
|
|
||
| client := testClient(t) | ||
| ctx := context.Background() | ||
|
|
||
| orgTest, orgTestCleanup := createOrganization(t, client) | ||
| t.Cleanup(orgTestCleanup) | ||
|
|
||
| oauthClient, cleanup := createOAuthClient(t, client, orgTest, nil) | ||
| t.Cleanup(cleanup) | ||
|
|
||
| stack, err := client.Stacks.Create(ctx, StackCreateOptions{ | ||
| Name: "test-stack", | ||
| VCSRepo: &StackVCSRepoOptions{ | ||
| Identifier: "hashicorp-guides/pet-nulls-stack", | ||
| OAuthTokenID: oauthClient.OAuthTokens[0].ID, | ||
| Branch: "main", | ||
| }, | ||
| Project: &Project{ | ||
| ID: orgTest.DefaultProject.ID, | ||
| }, | ||
| }) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, stack) | ||
|
|
||
| stackUpdated, err := client.Stacks.UpdateConfiguration(ctx, stack.ID) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, stackUpdated) | ||
|
|
||
| stack = pollStackDeployments(t, ctx, client, stackUpdated.ID) | ||
| require.NotNil(t, stack.LatestStackConfiguration) | ||
|
|
||
| // Get the deployment group ID from the stack configuration | ||
| deploymentGroups, err := client.StackDeploymentGroups.List(ctx, stack.LatestStackConfiguration.ID, nil) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, deploymentGroups) | ||
| require.NotEmpty(t, deploymentGroups.Items) | ||
| deploymentGroupID := deploymentGroups.Items[0].ID | ||
|
|
||
| t.Run("List without options", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| runList, err := client.StackDeploymentRuns.List(ctx, deploymentGroupID, nil) | ||
| require.NoError(t, err) | ||
| assert.NotNil(t, runList) | ||
| }) | ||
|
|
||
| t.Run("List with pagination", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| runList, err := client.StackDeploymentRuns.List(ctx, deploymentGroupID, &StackDeploymentRunListOptions{ | ||
| ListOptions: ListOptions{ | ||
| PageNumber: 1, | ||
| PageSize: 10, | ||
| }, | ||
| }) | ||
| require.NoError(t, err) | ||
| assert.NotNil(t, runList) | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.