Merge pull request #10656 from hashicorp/b-muti-lifecycle
config: error when loading multiple lifecycle blocks
This commit is contained in:
commit
882a5c49d7
|
@ -781,6 +781,12 @@ func loadManagedResourcesHcl(list *ast.ObjectList) ([]*Resource, error) {
|
||||||
// destroying the existing instance
|
// destroying the existing instance
|
||||||
var lifecycle ResourceLifecycle
|
var lifecycle ResourceLifecycle
|
||||||
if o := listVal.Filter("lifecycle"); len(o.Items) > 0 {
|
if o := listVal.Filter("lifecycle"); len(o.Items) > 0 {
|
||||||
|
if len(o.Items) > 1 {
|
||||||
|
return nil, fmt.Errorf(
|
||||||
|
"%s[%s]: Multiple lifecycle blocks found, expected one",
|
||||||
|
t, k)
|
||||||
|
}
|
||||||
|
|
||||||
// Check for invalid keys
|
// Check for invalid keys
|
||||||
valid := []string{"create_before_destroy", "ignore_changes", "prevent_destroy"}
|
valid := []string{"create_before_destroy", "ignore_changes", "prevent_destroy"}
|
||||||
if err := checkHCLKeys(o.Items[0].Val, valid); err != nil {
|
if err := checkHCLKeys(o.Items[0].Val, valid); err != nil {
|
||||||
|
|
|
@ -78,6 +78,13 @@ func TestLoadFile_resourceArityMistake(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLoadFile_resourceMultiLifecycle(t *testing.T) {
|
||||||
|
_, err := LoadFile(filepath.Join(fixtureDir, "resource-multi-lifecycle.tf"))
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("should have error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestLoadFile_dataSourceArityMistake(t *testing.T) {
|
func TestLoadFile_dataSourceArityMistake(t *testing.T) {
|
||||||
_, err := LoadFile(filepath.Join(fixtureDir, "data-source-arity-mistake.tf"))
|
_, err := LoadFile(filepath.Join(fixtureDir, "data-source-arity-mistake.tf"))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
resource "aws_instance" "foo" {
|
||||||
|
lifecycle {}
|
||||||
|
lifecycle {}
|
||||||
|
}
|
Loading…
Reference in New Issue