Skip to content

Commit bffc95e

Browse files
Add IngressAttributes to PolicySetVersion (#1108)
* Fetch latest changelog * Updated changelog * Updated changelog * Updated re-use of IngressAttributes struct * Added upgrade organization subscription call * Updated ingress attributes test * Updated ingress attributes nil check * Fetch latest changelog * Updated changelog * Updated changelog * Updated re-use of IngressAttributes struct * Added upgrade organization subscription call * Updated ingress attributes test * Updated ingress attributes nil check * Updated changelog * Rebased "policysetversion/ingress-attributes" onto a local branch --------- Co-authored-by: jpadrianoGo <[email protected]>
1 parent ec54b2f commit bffc95e

File tree

3 files changed

+77
-8
lines changed

3 files changed

+77
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Unreleased
22

3+
## Enhancements
4+
* Adds `IngressAttributes` field to `PolicySetVersion` by @jpadrianoGo [#1092](https://github.com/hashicorp/go-tfe/pull/1092)
5+
36
# v1.80.0
47

58
## Enhancements

policy_set_version.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,15 @@ type PolicySetVersionStatusTimestamps struct {
6969

7070
// PolicySetVersion represents a Terraform Enterprise Policy Set Version
7171
type PolicySetVersion struct {
72-
ID string `jsonapi:"primary,policy-set-versions"`
73-
Source PolicySetVersionSource `jsonapi:"attr,source"`
74-
Status PolicySetVersionStatus `jsonapi:"attr,status"`
75-
StatusTimestamps PolicySetVersionStatusTimestamps `jsonapi:"attr,status-timestamps"`
76-
Error string `jsonapi:"attr,error"`
77-
ErrorMessage string `jsonapi:"attr,error-message"`
78-
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
79-
UpdatedAt time.Time `jsonapi:"attr,updated-at,iso8601"`
72+
ID string `jsonapi:"primary,policy-set-versions"`
73+
Source PolicySetVersionSource `jsonapi:"attr,source"`
74+
Status PolicySetVersionStatus `jsonapi:"attr,status"`
75+
StatusTimestamps PolicySetVersionStatusTimestamps `jsonapi:"attr,status-timestamps"`
76+
Error string `jsonapi:"attr,error"`
77+
ErrorMessage string `jsonapi:"attr,error-message"`
78+
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
79+
UpdatedAt time.Time `jsonapi:"attr,updated-at,iso8601"`
80+
IngressAttributes *IngressAttributes `jsonapi:"attr,ingress-attributes"`
8081

8182
// Relations
8283
PolicySet *PolicySet `jsonapi:"relation,policy-set"`

policy_set_version_integration_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package tfe
55

66
import (
77
"context"
8+
"os"
89
"testing"
910
"time"
1011

@@ -139,3 +140,67 @@ func TestPolicySetVersionsUploadURL(t *testing.T) {
139140
assert.EqualError(t, err, "the Policy Set Version upload URL is empty")
140141
})
141142
}
143+
144+
func TestPolicySetVersionsIngressAttributes(t *testing.T) {
145+
client := testClient(t)
146+
ctx := context.Background()
147+
148+
orgTest, orgTestCleanup := createOrganization(t, client)
149+
t.Cleanup(orgTestCleanup)
150+
151+
upgradeOrganizationSubscription(t, client, orgTest)
152+
153+
t.Run("with vcs", func(t *testing.T) {
154+
githubIdentifier := os.Getenv("GITHUB_POLICY_SET_IDENTIFIER")
155+
if githubIdentifier == "" {
156+
t.Skip("Export a valid GITHUB_POLICY_SET_IDENTIFIER before running this test")
157+
}
158+
159+
otTest, otTestCleanup := createOAuthToken(t, client, orgTest)
160+
t.Cleanup(otTestCleanup)
161+
162+
options := PolicySetCreateOptions{
163+
Name: String("vcs-policy-set"),
164+
Kind: Sentinel,
165+
PoliciesPath: String("policy-sets/foo"),
166+
VCSRepo: &VCSRepoOptions{
167+
Branch: String("policies"),
168+
Identifier: String(githubIdentifier),
169+
OAuthTokenID: String(otTest.ID),
170+
IngressSubmodules: Bool(true),
171+
},
172+
}
173+
174+
ps, err := client.PolicySets.Create(ctx, orgTest.Name, options)
175+
require.NoError(t, err)
176+
177+
ps, err = client.PolicySets.ReadWithOptions(ctx, ps.ID, &PolicySetReadOptions{
178+
Include: []PolicySetIncludeOpt{
179+
PolicySetNewestVersion,
180+
},
181+
})
182+
require.NoError(t, err)
183+
184+
psv, err := client.PolicySetVersions.Read(ctx, ps.NewestVersion.ID)
185+
require.NoError(t, err)
186+
187+
require.NotNil(t, psv.IngressAttributes)
188+
assert.NotZero(t, psv.IngressAttributes.CommitSHA)
189+
assert.NotZero(t, psv.IngressAttributes.CommitURL)
190+
assert.NotZero(t, psv.IngressAttributes.Identifier)
191+
})
192+
193+
t.Run("without vcs", func(t *testing.T) {
194+
psTest, psTestCleanup := createPolicySet(t, client, nil, nil, nil, nil, nil, "")
195+
t.Cleanup(psTestCleanup)
196+
197+
psv, err := client.PolicySetVersions.Create(ctx, psTest.ID)
198+
require.NoError(t, err)
199+
200+
assert.NotEmpty(t, psv.ID)
201+
assert.Equal(t, psv.Source, PolicySetVersionSourceAPI)
202+
assert.Equal(t, psv.PolicySet.ID, psTest.ID)
203+
204+
assert.Nil(t, psv.IngressAttributes)
205+
})
206+
}

0 commit comments

Comments
 (0)