@ -805,6 +805,127 @@ func TestContext2Plan_preventDestroy_good(t *testing.T) {
}
}
func TestContext2Plan_preventDestroy_countBad ( t * testing . T ) {
m := testModule ( t , "plan-prevent-destroy-count-bad" )
p := testProvider ( "aws" )
p . DiffFn = testDiffFn
ctx := testContext2 ( t , & ContextOpts {
Module : m ,
Providers : map [ string ] ResourceProviderFactory {
"aws" : testProviderFuncFixed ( p ) ,
} ,
State : & State {
Modules : [ ] * ModuleState {
& ModuleState {
Path : rootModulePath ,
Resources : map [ string ] * ResourceState {
"aws_instance.foo.0" : & ResourceState {
Type : "aws_instance" ,
Primary : & InstanceState {
ID : "i-abc123" ,
} ,
} ,
"aws_instance.foo.1" : & ResourceState {
Type : "aws_instance" ,
Primary : & InstanceState {
ID : "i-abc345" ,
} ,
} ,
} ,
} ,
} ,
} ,
} )
plan , err := ctx . Plan ( )
expectedErr := "aws_instance.foo.1: the plan would destroy"
if ! strings . Contains ( fmt . Sprintf ( "%s" , err ) , expectedErr ) {
t . Fatalf ( "expected err would contain %q\nerr: %s\nplan: %s" ,
expectedErr , err , plan )
}
}
func TestContext2Plan_preventDestroy_countGood ( t * testing . T ) {
m := testModule ( t , "plan-prevent-destroy-count-good" )
p := testProvider ( "aws" )
p . DiffFn = testDiffFn
ctx := testContext2 ( t , & ContextOpts {
Module : m ,
Providers : map [ string ] ResourceProviderFactory {
"aws" : testProviderFuncFixed ( p ) ,
} ,
State : & State {
Modules : [ ] * ModuleState {
& ModuleState {
Path : rootModulePath ,
Resources : map [ string ] * ResourceState {
"aws_instance.foo.0" : & ResourceState {
Type : "aws_instance" ,
Primary : & InstanceState {
ID : "i-abc123" ,
} ,
} ,
"aws_instance.foo.1" : & ResourceState {
Type : "aws_instance" ,
Primary : & InstanceState {
ID : "i-abc345" ,
} ,
} ,
} ,
} ,
} ,
} ,
} )
plan , err := ctx . Plan ( )
if err != nil {
t . Fatalf ( "err: %s" , err )
}
if plan . Diff . Empty ( ) {
t . Fatalf ( "Expected non-empty plan, got %s" , plan . String ( ) )
}
}
func TestContext2Plan_preventDestroy_countGoodNoChange ( t * testing . T ) {
m := testModule ( t , "plan-prevent-destroy-count-good" )
p := testProvider ( "aws" )
p . DiffFn = testDiffFn
ctx := testContext2 ( t , & ContextOpts {
Module : m ,
Providers : map [ string ] ResourceProviderFactory {
"aws" : testProviderFuncFixed ( p ) ,
} ,
State : & State {
Modules : [ ] * ModuleState {
& ModuleState {
Path : rootModulePath ,
Resources : map [ string ] * ResourceState {
"aws_instance.foo.0" : & ResourceState {
Type : "aws_instance" ,
Primary : & InstanceState {
ID : "i-abc123" ,
Attributes : map [ string ] string {
"current" : "0" ,
"type" : "aws_instance" ,
} ,
} ,
} ,
} ,
} ,
} ,
} ,
} )
plan , err := ctx . Plan ( )
if err != nil {
t . Fatalf ( "err: %s" , err )
}
if ! plan . Diff . Empty ( ) {
t . Fatalf ( "Expected empty plan, got %s" , plan . String ( ) )
}
}
func TestContext2Plan_preventDestroy_destroyPlan ( t * testing . T ) {
m := testModule ( t , "plan-prevent-destroy-good" )
p := testProvider ( "aws" )