Skip to content

Commit 4a98dad

Browse files
authored
Merge pull request #1175 from hashicorp/TF-27927/deployment-group-list-name-filter
`StackDeploymentGroup` List name filter
2 parents c21b599 + 9afd115 commit 4a98dad

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Enhancements
44
* Adds support for `RegistryModule` VCS source_directory and tag_prefix options, by @jillrami [#1154] (https://github.com/hashicorp/go-tfe/pull/1154)
5+
* Adds `GroupName` filter option for `StackDeploymentGroup` by @Maed223 [#1175](https://github.com/hashicorp/go-tfe/pull/1175)
56

67
## Bug Fixes
78
* Fixes issue [1061](https://github.com/hashicorp/go-tfe/issues/1061), validation accepts all RunStatus including `"cost_estimated"` by @KenCox-Hashicorp [#1171](https://github.com/hashicorp/go-tfe/pull/1171)

stack_deployment_groups.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ type StackDeploymentGroupList struct {
6161
// StackDeploymentGroupListOptions represents additional options when listing stack deployment groups.
6262
type StackDeploymentGroupListOptions struct {
6363
ListOptions
64+
// A query string used to filter by deployment group name.
65+
GroupName string `url:"group_name,omitempty"`
6466
}
6567

6668
// List returns a list of Deployment Groups in a stack, optionally filtered by additional parameters.
@@ -69,11 +71,12 @@ func (s stackDeploymentGroups) List(ctx context.Context, stackConfigID string, o
6971
return nil, fmt.Errorf("invalid stack configuration ID: %s", stackConfigID)
7072
}
7173

72-
if options == nil {
73-
options = &StackDeploymentGroupListOptions{}
74+
u := fmt.Sprintf("stack-configurations/%s/stack-deployment-groups/", url.PathEscape(stackConfigID))
75+
qp, err := decodeQueryParams(options)
76+
if err != nil {
77+
return nil, err
7478
}
75-
76-
req, err := s.client.NewRequest("GET", fmt.Sprintf("stack-configurations/%s/stack-deployment-groups", url.PathEscape(stackConfigID)), options)
79+
req, err := s.client.NewRequestWithAdditionalQueryParams("GET", u, nil, qp)
7780
if err != nil {
7881
return nil, err
7982
}

stack_deployment_groups_integration_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,21 @@ func TestStackDeploymentGroupsList(t *testing.T) {
7272
require.NotNil(t, sdgl)
7373
require.Len(t, sdgl.Items, 1)
7474
})
75+
76+
t.Run("List with filtering by group name", func(t *testing.T) {
77+
noOptionSdg, err := client.StackDeploymentGroups.List(ctx, stackUpdated.LatestStackConfiguration.ID, nil)
78+
require.NoError(t, err)
79+
require.NotNil(t, noOptionSdg)
80+
require.GreaterOrEqual(t, len(noOptionSdg.Items), 1)
81+
options := &StackDeploymentGroupListOptions{
82+
GroupName: noOptionSdg.Items[0].Name,
83+
}
84+
sdgl, err := client.StackDeploymentGroups.List(ctx, stackUpdated.LatestStackConfiguration.ID, options)
85+
require.NoError(t, err)
86+
require.NotNil(t, sdgl)
87+
require.Equal(t, 1, len(sdgl.Items))
88+
require.Equal(t, noOptionSdg.Items[0].Name, sdgl.Items[0].Name)
89+
})
7590
}
7691

7792
func TestStackDeploymentGroupsRead(t *testing.T) {

0 commit comments

Comments
 (0)