Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schema: add 1.2 lifecycle replace_triggered_by attribute #123

Merged
merged 2 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions internal/schema/1.2/data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package schema

import (
"github.com/hashicorp/hcl-lang/lang"
"github.com/hashicorp/hcl-lang/schema"
)

var datasourceLifecycleBlock = &schema.BlockSchema{
Description: lang.Markdown("Lifecycle customizations to set validity conditions of the datasource"),
Body: &schema.BodySchema{
Blocks: map[string]*schema.BlockSchema{
"precondition": {
Body: conditionBody,
},
"postcondition": {
Body: conditionBody,
},
},
},
}
17 changes: 17 additions & 0 deletions internal/schema/1.2/output.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package schema

import (
"github.com/hashicorp/hcl-lang/lang"
"github.com/hashicorp/hcl-lang/schema"
)

var outputLifecycleBlock = &schema.BlockSchema{
Description: lang.Markdown("Lifecycle customizations, to set a validity condition of the output"),
Body: &schema.BodySchema{
Blocks: map[string]*schema.BlockSchema{
"precondition": {
Body: conditionBody,
},
},
},
}
61 changes: 61 additions & 0 deletions internal/schema/1.2/resource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package schema

import (
"github.com/hashicorp/hcl-lang/lang"
"github.com/hashicorp/hcl-lang/schema"
"github.com/hashicorp/terraform-schema/internal/schema/refscope"
"github.com/zclconf/go-cty/cty"
)

var resourceLifecycleBlock = &schema.BlockSchema{
Description: lang.Markdown("Lifecycle customizations to change default resource behaviours during plan or 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`"),
},
"replace_triggered_by": {
Expr: schema.ExprConstraints{
schema.TupleConsExpr{
Name: "set of references",
AnyElem: schema.ExprConstraints{
schema.TraversalExpr{OfScopeId: refscope.ResourceScope},
},
},
},
IsOptional: true,
Description: lang.Markdown("Set of references to any other resources which when changed cause " +
"this resource to be proposed for replacement"),
},
},
Blocks: map[string]*schema.BlockSchema{
"precondition": {
Body: conditionBody,
},
"postcondition": {
Body: conditionBody,
},
},
},
}
79 changes: 6 additions & 73 deletions internal/schema/1.2/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,84 +13,17 @@ var v1_2 = version.Must(version.NewVersion("1.2.0"))

func ModuleSchema(v *version.Version) *schema.BodySchema {
bs := v1_1_mod.ModuleSchema(v)
if v.GreaterThanOrEqual(v1_2) {
bs.Blocks["data"].Body.Blocks = map[string]*schema.BlockSchema{
"lifecycle": datasourceLifecycleBlock,
}
bs.Blocks["resource"].Body.Blocks["lifecycle"] = resourceLifecycleBlock
bs.Blocks["output"].Body.Blocks = map[string]*schema.BlockSchema{
"lifecycle": outputLifecycleBlock,
}
bs.Blocks["data"].Body.Blocks = map[string]*schema.BlockSchema{
"lifecycle": datasourceLifecycleBlock,
}
bs.Blocks["resource"].Body.Blocks["lifecycle"] = resourceLifecycleBlock
bs.Blocks["output"].Body.Blocks = map[string]*schema.BlockSchema{
"lifecycle": outputLifecycleBlock,
}

return bs
}

var datasourceLifecycleBlock = &schema.BlockSchema{
Description: lang.Markdown("Lifecycle customizations to set validity conditions of the datasource"),
Body: &schema.BodySchema{
Blocks: map[string]*schema.BlockSchema{
"precondition": {
Body: conditionBody,
},
"postcondition": {
Body: conditionBody,
},
},
},
}

var outputLifecycleBlock = &schema.BlockSchema{
Description: lang.Markdown("Lifecycle customizations, to set a validity condition of the output"),
Body: &schema.BodySchema{
Blocks: map[string]*schema.BlockSchema{
"precondition": {
Body: conditionBody,
},
},
},
}

var resourceLifecycleBlock = &schema.BlockSchema{
Description: lang.Markdown("Lifecycle customizations to change default resource behaviours during plan or 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: conditionBody,
},
"postcondition": {
Body: conditionBody,
},
},
},
}

var conditionBody = &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"condition": {
Expand Down