|
|
|
|
@ -66,6 +66,61 @@ func TestRemote_applyBasic(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestRemote_applyWithAutoApply(t *testing.T) {
|
|
|
|
|
b := testBackendNoDefault(t)
|
|
|
|
|
|
|
|
|
|
// Create a named workspace that auto applies.
|
|
|
|
|
_, err := b.client.Workspaces.Create(
|
|
|
|
|
context.Background(),
|
|
|
|
|
b.organization,
|
|
|
|
|
tfe.WorkspaceCreateOptions{
|
|
|
|
|
AutoApply: tfe.Bool(true),
|
|
|
|
|
Name: tfe.String(b.prefix + "prod"),
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("error creating named workspace: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mod, modCleanup := module.TestTree(t, "./test-fixtures/apply")
|
|
|
|
|
defer modCleanup()
|
|
|
|
|
|
|
|
|
|
input := testInput(t, map[string]string{
|
|
|
|
|
"approve": "yes",
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
op := testOperationApply()
|
|
|
|
|
op.Module = mod
|
|
|
|
|
op.UIIn = input
|
|
|
|
|
op.UIOut = b.CLI
|
|
|
|
|
op.Workspace = "prod"
|
|
|
|
|
|
|
|
|
|
run, err := b.Operation(context.Background(), op)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("error starting operation: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<-run.Done()
|
|
|
|
|
if run.Err != nil {
|
|
|
|
|
t.Fatalf("error running operation: %v", run.Err)
|
|
|
|
|
}
|
|
|
|
|
if run.PlanEmpty {
|
|
|
|
|
t.Fatalf("expected a non-empty plan")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(input.answers) != 1 {
|
|
|
|
|
t.Fatalf("expected an unused answer, got: %v", input.answers)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
output := b.CLI.(*cli.MockUi).OutputWriter.String()
|
|
|
|
|
if !strings.Contains(output, "1 to add, 0 to change, 0 to destroy") {
|
|
|
|
|
t.Fatalf("missing plan summery in output: %s", output)
|
|
|
|
|
}
|
|
|
|
|
if !strings.Contains(output, "1 added, 0 changed, 0 destroyed") {
|
|
|
|
|
t.Fatalf("missing apply summery in output: %s", output)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestRemote_applyWithoutPermissions(t *testing.T) {
|
|
|
|
|
b := testBackendNoDefault(t)
|
|
|
|
|
|
|
|
|
|
@ -93,8 +148,8 @@ func TestRemote_applyWithoutPermissions(t *testing.T) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("error starting operation: %v", err)
|
|
|
|
|
}
|
|
|
|
|
<-run.Done()
|
|
|
|
|
|
|
|
|
|
<-run.Done()
|
|
|
|
|
if run.Err == nil {
|
|
|
|
|
t.Fatalf("expected an apply error, got: %v", run.Err)
|
|
|
|
|
}
|
|
|
|
|
@ -130,8 +185,8 @@ func TestRemote_applyWithVCS(t *testing.T) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("error starting operation: %v", err)
|
|
|
|
|
}
|
|
|
|
|
<-run.Done()
|
|
|
|
|
|
|
|
|
|
<-run.Done()
|
|
|
|
|
if run.Err == nil {
|
|
|
|
|
t.Fatalf("expected an apply error, got: %v", run.Err)
|
|
|
|
|
}
|
|
|
|
|
@ -158,8 +213,8 @@ func TestRemote_applyWithParallelism(t *testing.T) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("error starting operation: %v", err)
|
|
|
|
|
}
|
|
|
|
|
<-run.Done()
|
|
|
|
|
|
|
|
|
|
<-run.Done()
|
|
|
|
|
if run.Err == nil {
|
|
|
|
|
t.Fatalf("expected an apply error, got: %v", run.Err)
|
|
|
|
|
}
|
|
|
|
|
@ -183,8 +238,8 @@ func TestRemote_applyWithPlan(t *testing.T) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("error starting operation: %v", err)
|
|
|
|
|
}
|
|
|
|
|
<-run.Done()
|
|
|
|
|
|
|
|
|
|
<-run.Done()
|
|
|
|
|
if run.Err == nil {
|
|
|
|
|
t.Fatalf("expected an apply error, got: %v", run.Err)
|
|
|
|
|
}
|
|
|
|
|
@ -211,8 +266,8 @@ func TestRemote_applyWithoutRefresh(t *testing.T) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("error starting operation: %v", err)
|
|
|
|
|
}
|
|
|
|
|
<-run.Done()
|
|
|
|
|
|
|
|
|
|
<-run.Done()
|
|
|
|
|
if run.Err == nil {
|
|
|
|
|
t.Fatalf("expected an apply error, got: %v", run.Err)
|
|
|
|
|
}
|
|
|
|
|
@ -236,8 +291,8 @@ func TestRemote_applyWithTarget(t *testing.T) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("error starting operation: %v", err)
|
|
|
|
|
}
|
|
|
|
|
<-run.Done()
|
|
|
|
|
|
|
|
|
|
<-run.Done()
|
|
|
|
|
if run.Err == nil {
|
|
|
|
|
t.Fatalf("expected an apply error, got: %v", run.Err)
|
|
|
|
|
}
|
|
|
|
|
@ -264,8 +319,8 @@ func TestRemote_applyWithVariables(t *testing.T) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("error starting operation: %v", err)
|
|
|
|
|
}
|
|
|
|
|
<-run.Done()
|
|
|
|
|
|
|
|
|
|
<-run.Done()
|
|
|
|
|
if run.Err == nil {
|
|
|
|
|
t.Fatalf("expected an apply error, got: %v", run.Err)
|
|
|
|
|
}
|
|
|
|
|
@ -285,8 +340,8 @@ func TestRemote_applyNoConfig(t *testing.T) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("error starting operation: %v", err)
|
|
|
|
|
}
|
|
|
|
|
<-run.Done()
|
|
|
|
|
|
|
|
|
|
<-run.Done()
|
|
|
|
|
if run.Err == nil {
|
|
|
|
|
t.Fatalf("expected an apply error, got: %v", run.Err)
|
|
|
|
|
}
|
|
|
|
|
@ -690,6 +745,65 @@ func TestRemote_applyPolicySoftFail(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestRemote_applyPolicySoftFailAutoApply(t *testing.T) {
|
|
|
|
|
b := testBackendDefault(t)
|
|
|
|
|
|
|
|
|
|
// Create a named workspace that auto applies.
|
|
|
|
|
_, err := b.client.Workspaces.Create(
|
|
|
|
|
context.Background(),
|
|
|
|
|
b.organization,
|
|
|
|
|
tfe.WorkspaceCreateOptions{
|
|
|
|
|
AutoApply: tfe.Bool(true),
|
|
|
|
|
Name: tfe.String(b.prefix + "prod"),
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("error creating named workspace: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mod, modCleanup := module.TestTree(t, "./test-fixtures/apply-policy-soft-failed")
|
|
|
|
|
defer modCleanup()
|
|
|
|
|
|
|
|
|
|
input := testInput(t, map[string]string{
|
|
|
|
|
"override": "override",
|
|
|
|
|
"approve": "yes",
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
op := testOperationApply()
|
|
|
|
|
op.Module = mod
|
|
|
|
|
op.UIIn = input
|
|
|
|
|
op.UIOut = b.CLI
|
|
|
|
|
op.Workspace = "prod"
|
|
|
|
|
|
|
|
|
|
run, err := b.Operation(context.Background(), op)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("error starting operation: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<-run.Done()
|
|
|
|
|
if run.Err != nil {
|
|
|
|
|
t.Fatalf("error running operation: %v", run.Err)
|
|
|
|
|
}
|
|
|
|
|
if run.PlanEmpty {
|
|
|
|
|
t.Fatalf("expected a non-empty plan")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(input.answers) != 1 {
|
|
|
|
|
t.Fatalf("expected an unused answer, got: %v", input.answers)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
output := b.CLI.(*cli.MockUi).OutputWriter.String()
|
|
|
|
|
if !strings.Contains(output, "1 to add, 0 to change, 0 to destroy") {
|
|
|
|
|
t.Fatalf("missing plan summery in output: %s", output)
|
|
|
|
|
}
|
|
|
|
|
if !strings.Contains(output, "Sentinel Result: false") {
|
|
|
|
|
t.Fatalf("missing policy check result in output: %s", output)
|
|
|
|
|
}
|
|
|
|
|
if !strings.Contains(output, "1 added, 0 changed, 0 destroyed") {
|
|
|
|
|
t.Fatalf("missing apply summery in output: %s", output)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestRemote_applyPolicySoftFailAutoApprove(t *testing.T) {
|
|
|
|
|
b := testBackendDefault(t)
|
|
|
|
|
|
|
|
|
|
|