Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

## Enhancements

* Adds BETA support for listing `StackDeploymentRuns`, which is EXPERIMENTAL, SUBJECT TO CHANGE, and may not be available to all users by @shwetamurali [#1134](https://github.com/hashicorp/go-tfe/pull/1134)
* Add support for HCP Terraform `/api/v2/workspaces/{external_id}/all-vars` API endpoint to fetch the list of all variables available to a workspace (include inherited variables from varsets) by @debrin-hc [#1105](https://github.com/hashicorp/go-tfe/pull/1105)
* Adds BETA support for listing `StackDeploymentGroups`, which is EXPERIMENTAL, SUBJECT TO CHANGE, and may not be available to all users by @hwatkins05-hashicorp [#1128](https://github.com/hashicorp/go-tfe/pull/1128)
* Adds BETA support for removing/adding VCS backing for a Stack, which is EXPERIMENTAL, SUBJECT TO CHANGE, and may not be available to all users by @Maed223 [#1131](https://github.com/hashicorp/go-tfe/pull/1131)
Expand Down
13 changes: 7 additions & 6 deletions stack_deployment_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/url"
"time"
)

// StackDeploymentGroups describes all the stack-deployment-groups related methods that the HCP Terraform API supports.
Expand Down Expand Up @@ -34,14 +35,14 @@ var _ StackDeploymentGroups = &stackDeploymentGroups{}

// StackDeploymentGroup represents a stack deployment group.
type StackDeploymentGroup struct {
ID string `jsonapi:"primary,stacks-deployment-groups"`
Name string `jsonapi:"attr,name"`
Status DeploymentGroupStatus `jsonapi:"attr,status"`
CreatedAt string `jsonapi:"attr,created-at"`
UpdatedAt string `jsonapi:"attr,updated-at"`
ID string `jsonapi:"primary,stacks-deployment-groups"`
Name string `jsonapi:"attr,name"`
Status string `jsonapi:"attr,status"`
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
UpdatedAt time.Time `jsonapi:"attr,updated-at,iso8601"`

// Relationships
StackConfiguration StackConfiguration `jsonapi:"relation,stack-configurations"`
StackConfiguration *StackConfiguration `jsonapi:"relation,stack-configuration"`
}

// StackDeploymentGroupList represents a list of stack deployment groups.
Expand Down
62 changes: 62 additions & 0 deletions stack_deployment_runs.go
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
}
74 changes: 74 additions & 0 deletions stack_deployment_runs_integration_test.go
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)
})
}
6 changes: 5 additions & 1 deletion tfe.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ type Client struct {
Projects Projects

Meta Meta

StackDeploymentRuns StackDeploymentRuns
}

// Admin is the the Terraform Enterprise Admin API. It provides access to site
Expand Down Expand Up @@ -459,8 +461,8 @@ func NewClient(cfg *Config) (*Client, error) {
client.AuditTrails = &auditTrails{client: client}
client.Comments = &comments{client: client}
client.ConfigurationVersions = &configurationVersions{client: client}
client.GHAInstallations = &gHAInstallations{client: client}
client.CostEstimates = &costEstimates{client: client}
client.GHAInstallations = &gHAInstallations{client: client}
client.GPGKeys = &gpgKeys{client: client}
client.RegistryNoCodeModules = &registryNoCodeModules{client: client}
client.NotificationConfigurations = &notificationConfigurations{client: client}
Expand Down Expand Up @@ -521,6 +523,8 @@ func NewClient(cfg *Config) (*Client, error) {
IPRanges: &ipRanges{client: client},
}

client.StackDeploymentRuns = &stackDeploymentRuns{client: client}

return client, nil
}

Expand Down
Loading