Skip to content

Commit

Permalink
Turn resource lifecycle into a func (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanck authored Nov 2, 2022
1 parent 619c765 commit 620ab91
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions internal/schema/0.12/resource_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func resourceBlockSchema(v *version.Version) *schema.BlockSchema {
},
},
Blocks: map[string]*schema.BlockSchema{
"lifecycle": lifecycleBlock,
"lifecycle": lifecycleBlock(),
"connection": connectionBlock(v),
"provisioner": provisionerBlock(v),
},
Expand All @@ -81,34 +81,36 @@ func resourceBlockSchema(v *version.Version) *schema.BlockSchema {
return bs
}

var lifecycleBlock = &schema.BlockSchema{
Description: lang.Markdown("Lifecycle customizations to change default resource behaviours during apply"),
Body: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"create_before_destroy": {
Expr: schema.LiteralTypeOnly(cty.Bool),
IsOptional: true,
Description: lang.Markdown("Whether to reverse the default order of operations (destroy -> create) during apply " +
"when the resource requires replacement (cannot be updated in-place)"),
},
"prevent_destroy": {
Expr: schema.LiteralTypeOnly(cty.Bool),
IsOptional: true,
Description: lang.Markdown("Whether to prevent accidental destruction of the resource and cause Terraform " +
"to reject with an error any plan that would destroy the resource"),
},
"ignore_changes": {
Expr: schema.ExprConstraints{
schema.TupleConsExpr{},
schema.KeywordExpr{
Keyword: "all",
Description: lang.Markdown("Ignore all attributes, which means that Terraform can create" +
" and destroy the remote object but will never propose updates to it"),
func lifecycleBlock() *schema.BlockSchema {
return &schema.BlockSchema{
Description: lang.Markdown("Lifecycle customizations to change default resource behaviours during apply"),
Body: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"create_before_destroy": {
Expr: schema.LiteralTypeOnly(cty.Bool),
IsOptional: true,
Description: lang.Markdown("Whether to reverse the default order of operations (destroy -> create) during apply " +
"when the resource requires replacement (cannot be updated in-place)"),
},
"prevent_destroy": {
Expr: schema.LiteralTypeOnly(cty.Bool),
IsOptional: true,
Description: lang.Markdown("Whether to prevent accidental destruction of the resource and cause Terraform " +
"to reject with an error any plan that would destroy the resource"),
},
"ignore_changes": {
Expr: schema.ExprConstraints{
schema.TupleConsExpr{},
schema.KeywordExpr{
Keyword: "all",
Description: lang.Markdown("Ignore all attributes, which means that Terraform can create" +
" and destroy the remote object but will never propose updates to it"),
},
},
IsOptional: true,
Description: lang.Markdown("A set of fields (references) of which to ignore changes to, e.g. `tags`"),
},
IsOptional: true,
Description: lang.Markdown("A set of fields (references) of which to ignore changes to, e.g. `tags`"),
},
},
},
}
}

0 comments on commit 620ab91

Please sign in to comment.