Merge pull request #17071 from MarkFreebairn/Issue-16360-empty-target-points-to-all-resources-in-state
command: Fix #16360 - Fail fast if -target is specified but empty
This commit is contained in:
commit
2f8532407a
|
@ -487,6 +487,13 @@ func (c *Context) Input(mode InputMode) error {
|
||||||
func (c *Context) Apply() (*State, error) {
|
func (c *Context) Apply() (*State, error) {
|
||||||
defer c.acquireRun("apply")()
|
defer c.acquireRun("apply")()
|
||||||
|
|
||||||
|
// Check there are no empty target parameter values
|
||||||
|
for _, target := range c.targets {
|
||||||
|
if target == "" {
|
||||||
|
return nil, fmt.Errorf("Target parameter must not have empty value")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Copy our own state
|
// Copy our own state
|
||||||
c.state = c.state.DeepCopy()
|
c.state = c.state.DeepCopy()
|
||||||
|
|
||||||
|
@ -524,6 +531,13 @@ func (c *Context) Apply() (*State, error) {
|
||||||
func (c *Context) Plan() (*Plan, error) {
|
func (c *Context) Plan() (*Plan, error) {
|
||||||
defer c.acquireRun("plan")()
|
defer c.acquireRun("plan")()
|
||||||
|
|
||||||
|
// Check there are no empty target parameter values
|
||||||
|
for _, target := range c.targets {
|
||||||
|
if target == "" {
|
||||||
|
return nil, fmt.Errorf("Target parameter must not have empty value")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
p := &Plan{
|
p := &Plan{
|
||||||
Module: c.module,
|
Module: c.module,
|
||||||
Vars: c.variables,
|
Vars: c.variables,
|
||||||
|
|
|
@ -7485,6 +7485,27 @@ aws_instance.foo:
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContext2Apply_targetEmpty(t *testing.T) {
|
||||||
|
m := testModule(t, "apply-targeted")
|
||||||
|
p := testProvider("aws")
|
||||||
|
p.ApplyFn = testApplyFn
|
||||||
|
p.DiffFn = testDiffFn
|
||||||
|
ctx := testContext2(t, &ContextOpts{
|
||||||
|
Module: m,
|
||||||
|
ProviderResolver: ResourceProviderResolverFixed(
|
||||||
|
map[string]ResourceProviderFactory{
|
||||||
|
"aws": testProviderFuncFixed(p),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
Targets: []string{""},
|
||||||
|
})
|
||||||
|
|
||||||
|
_, err := ctx.Apply()
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("should error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestContext2Apply_targetedCount(t *testing.T) {
|
func TestContext2Apply_targetedCount(t *testing.T) {
|
||||||
m := testModule(t, "apply-targeted-count")
|
m := testModule(t, "apply-targeted-count")
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
|
|
|
@ -2733,6 +2733,26 @@ STATE:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContext2Plan_targetEmpty(t *testing.T) {
|
||||||
|
m := testModule(t, "plan-targeted")
|
||||||
|
p := testProvider("aws")
|
||||||
|
p.DiffFn = testDiffFn
|
||||||
|
ctx := testContext2(t, &ContextOpts{
|
||||||
|
Module: m,
|
||||||
|
ProviderResolver: ResourceProviderResolverFixed(
|
||||||
|
map[string]ResourceProviderFactory{
|
||||||
|
"aws": testProviderFuncFixed(p),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
Targets: []string{""},
|
||||||
|
})
|
||||||
|
|
||||||
|
_, err := ctx.Plan()
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("should error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Test that targeting a module properly plans any inputs that depend
|
// Test that targeting a module properly plans any inputs that depend
|
||||||
// on another module.
|
// on another module.
|
||||||
func TestContext2Plan_targetedCrossModule(t *testing.T) {
|
func TestContext2Plan_targetedCrossModule(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue