Skip to content

Commit 17b2cd5

Browse files
authored
Merge pull request #1104 from hashicorp/sebasslash/tf-25028_add-policies-paths-runs-param
beta: add policy-paths run param
2 parents 74ac650 + f58a3f0 commit 17b2cd5

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

run.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ type Run struct {
141141
IsDestroy bool `jsonapi:"attr,is-destroy"`
142142
Message string `jsonapi:"attr,message"`
143143
Permissions *RunPermissions `jsonapi:"attr,permissions"`
144+
PolicyPaths []string `jsonapi:"attr,policy-paths,omitempty"`
144145
PositionInQueue int `jsonapi:"attr,position-in-queue"`
145146
PlanOnly bool `jsonapi:"attr,plan-only"`
146147
Refresh bool `jsonapi:"attr,refresh"`
@@ -385,6 +386,12 @@ type RunCreateOptions struct {
385386
// resource addresses.
386387
ReplaceAddrs []string `jsonapi:"attr,replace-addrs,omitempty"`
387388

389+
// PolicyPaths is a list of relative directory paths that point to policy
390+
// configuration files.
391+
//
392+
// **Note: This field is in BETA and subject to change.**
393+
PolicyPaths []string `jsonapi:"attr,policy-paths,omitempty"`
394+
388395
// AutoApply determines if the run should be applied automatically without
389396
// user confirmation. It defaults to the Workspace.AutoApply setting.
390397
AutoApply *bool `jsonapi:"attr,auto-apply,omitempty"`

run_integration_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,24 @@ func TestRunsCreate(t *testing.T) {
353353
}
354354
}
355355
})
356+
357+
t.Run("with policy paths", func(t *testing.T) {
358+
skipUnlessBeta(t)
359+
360+
opts := RunCreateOptions{
361+
Message: String("creating with policy paths"),
362+
Workspace: wTest,
363+
PolicyPaths: []string{"./path/to/dir1", "./path/to/dir2"},
364+
}
365+
366+
r, err := client.Runs.Create(ctx, opts)
367+
require.NoError(t, err)
368+
require.NotEmpty(t, r.PolicyPaths)
369+
370+
assert.Len(t, r.PolicyPaths, 2)
371+
assert.Contains(t, r.PolicyPaths, "./path/to/dir1")
372+
assert.Contains(t, r.PolicyPaths, "./path/to/dir2")
373+
})
356374
}
357375

358376
func TestRunsRead_CostEstimate(t *testing.T) {
@@ -403,6 +421,31 @@ func TestRunsReadWithOptions(t *testing.T) {
403421
})
404422
}
405423

424+
func TestRunsReadWithPolicyPaths(t *testing.T) {
425+
skipUnlessBeta(t)
426+
427+
client := testClient(t)
428+
ctx := context.Background()
429+
430+
wTest, wTestCleanup := createWorkspace(t, client, nil)
431+
t.Cleanup(wTestCleanup)
432+
433+
_, cvCleanup := createUploadedConfigurationVersion(t, client, wTest)
434+
t.Cleanup(cvCleanup)
435+
436+
r, err := client.Runs.Create(ctx, RunCreateOptions{
437+
Workspace: wTest,
438+
PolicyPaths: []string{"./foo"},
439+
})
440+
require.NoError(t, err)
441+
442+
r, err = client.Runs.Read(ctx, r.ID)
443+
require.NoError(t, err)
444+
445+
require.NotEmpty(t, r.PolicyPaths)
446+
assert.Contains(t, r.PolicyPaths, "./foo")
447+
}
448+
406449
func TestRunsApply(t *testing.T) {
407450
client := testClient(t)
408451
ctx := context.Background()

0 commit comments

Comments
 (0)