-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
schema: introduce lifecycle conditions
- Loading branch information
1 parent
9aece33
commit 3c85d94
Showing
1 changed file
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package schema | ||
|
||
import ( | ||
"github.com/hashicorp/go-version" | ||
"github.com/hashicorp/hcl-lang/lang" | ||
"github.com/hashicorp/hcl-lang/schema" | ||
"github.com/zclconf/go-cty/cty" | ||
|
||
v015_mod "github.com/hashicorp/terraform-schema/internal/schema/0.15" | ||
) | ||
|
||
var v1_2 = version.Must(version.NewVersion("1.2.0")) | ||
|
||
func ModuleSchema(v *version.Version) *schema.BodySchema { | ||
bs := v015_mod.ModuleSchema(v) | ||
if v.GreaterThanOrEqual(v1_2) { | ||
bs.Blocks["resource"].Body.Blocks["lifecycle"] = lifecycleBlock | ||
} | ||
|
||
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"), | ||
}, | ||
}, | ||
IsOptional: true, | ||
Description: lang.Markdown("A set of fields (references) of which to ignore changes to, e.g. `tags`"), | ||
}, | ||
}, | ||
Blocks: map[string]*schema.BlockSchema{ | ||
"precondition": { | ||
Body: &schema.BodySchema{ | ||
Attributes: map[string]*schema.AttributeSchema{ | ||
"condition": { | ||
Expr: schema.ExprConstraints{ | ||
schema.TraversalExpr{OfType: cty.Bool}, | ||
schema.LiteralTypeExpr{Type: cty.Bool}, | ||
}, | ||
IsRequired: true, | ||
}, | ||
"error_message": { | ||
Expr: schema.LiteralTypeOnly(cty.String), | ||
IsRequired: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"postcondition": { | ||
Body: &schema.BodySchema{ | ||
Attributes: map[string]*schema.AttributeSchema{ | ||
"condition": { | ||
Expr: schema.ExprConstraints{ | ||
schema.TraversalExpr{OfType: cty.Bool}, | ||
schema.LiteralTypeExpr{Type: cty.Bool}, | ||
}, | ||
IsRequired: true, | ||
}, | ||
"error_message": { | ||
Expr: schema.LiteralTypeOnly(cty.String), | ||
IsRequired: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} |