Skip to content

Commit

Permalink
Merge pull request #338 from hashicorp/dependabot/go_modules/github.c…
Browse files Browse the repository at this point in the history
…om/hashicorp/terraform-plugin-framework-0.17.0

Bump github.com/hashicorp/terraform-plugin-framework from 0.16.0 to 0.17.0
  • Loading branch information
bendbennett committed Dec 14, 2022
2 parents caf4fd1 + 2a1f9c0 commit 6c1912d
Show file tree
Hide file tree
Showing 16 changed files with 696 additions and 942 deletions.
4 changes: 2 additions & 2 deletions go.mod
Expand Up @@ -7,8 +7,8 @@ require (
github.com/google/go-cmp v0.5.9
github.com/hashicorp/go-uuid v1.0.3
github.com/hashicorp/terraform-plugin-docs v0.13.0
github.com/hashicorp/terraform-plugin-framework v0.16.0
github.com/hashicorp/terraform-plugin-framework-validators v0.6.0
github.com/hashicorp/terraform-plugin-framework v0.17.0
github.com/hashicorp/terraform-plugin-framework-validators v0.7.0
github.com/hashicorp/terraform-plugin-go v0.14.2
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Expand Up @@ -141,10 +141,10 @@ github.com/hashicorp/terraform-json v0.14.0 h1:sh9iZ1Y8IFJLx+xQiKHGud6/TSUCM0N8e
github.com/hashicorp/terraform-json v0.14.0/go.mod h1:5A9HIWPkk4e5aeeXIBbkcOvaZbIYnAIkEyqP2pNSckM=
github.com/hashicorp/terraform-plugin-docs v0.13.0 h1:6e+VIWsVGb6jYJewfzq2ok2smPzZrt1Wlm9koLeKazY=
github.com/hashicorp/terraform-plugin-docs v0.13.0/go.mod h1:W0oCmHAjIlTHBbvtppWHe8fLfZ2BznQbuv8+UD8OucQ=
github.com/hashicorp/terraform-plugin-framework v0.16.0 h1:kEHh0d6dp5Ig/ey6PYXkWDZPMLIW8Me41T/Oa7bpO4s=
github.com/hashicorp/terraform-plugin-framework v0.16.0/go.mod h1:Vk5MuIJoE1qksHZawAZr6psx6YXsQBFIKDrWbROrwus=
github.com/hashicorp/terraform-plugin-framework-validators v0.6.0 h1:j8GlgzuTjbbkMnsbiOXerwJTW8Us4saQwo4FfJKd2I0=
github.com/hashicorp/terraform-plugin-framework-validators v0.6.0/go.mod h1:iOYhZQinlZ0R/M3Q3nCXS4dikZ7P41d5b7ezpe9uoIw=
github.com/hashicorp/terraform-plugin-framework v0.17.0 h1:0KUOY/oe1GPLFqaXnKDnd1rhCrnUtt8pV9wGEwNUFlU=
github.com/hashicorp/terraform-plugin-framework v0.17.0/go.mod h1:FV97t2BZOARkL7NNlsc/N25c84MyeSSz72uPp7Vq1lg=
github.com/hashicorp/terraform-plugin-framework-validators v0.7.0 h1:tIYOMNmEMQIc6mwun8nX3e5U3TkgZg1TpXRlBEBQHwY=
github.com/hashicorp/terraform-plugin-framework-validators v0.7.0/go.mod h1:e1RKREyEVdd3FK8Jfgz8L/ThQgcJKLb4ZJxNzsuIH0A=
github.com/hashicorp/terraform-plugin-go v0.14.2 h1:rhsVEOGCnY04msNymSvbUsXfRLKh9znXZmHlf5e8mhE=
github.com/hashicorp/terraform-plugin-go v0.14.2/go.mod h1:Q12UjumPNGiFsZffxOsA40Tlz1WVXt2Evh865Zj0+UA=
github.com/hashicorp/terraform-plugin-log v0.7.0 h1:SDxJUyT8TwN4l5b5/VkiTIaQgY6R+Y2BQ0sRZftGKQs=
Expand Down
263 changes: 0 additions & 263 deletions internal/planmodifiers/attribute.go

This file was deleted.

99 changes: 99 additions & 0 deletions internal/planmodifiers/bool/boolplanmodifiers.go
@@ -0,0 +1,99 @@
package boolplanmodifiers

import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
)

// DefaultValue accepts a types.Bool value and uses the supplied value to set a default
// if the config for the attribute is null.
func DefaultValue(val types.Bool) planmodifier.Bool {
return &defaultValueAttributePlanModifier{val}
}

type defaultValueAttributePlanModifier struct {
val types.Bool
}

func (d *defaultValueAttributePlanModifier) Description(ctx context.Context) string {
return fmt.Sprintf("If not configured, defaults to %t", d.val.ValueBool())
}

func (d *defaultValueAttributePlanModifier) MarkdownDescription(ctx context.Context) string {
return d.Description(ctx)
}

// PlanModifyBool checks that the value of the attribute in the configuration and assigns the default value if
// the value in the config is null. This is a destructive operation in that it will overwrite any value
// present in the plan.
func (d *defaultValueAttributePlanModifier) PlanModifyBool(ctx context.Context, req planmodifier.BoolRequest, resp *planmodifier.BoolResponse) {
// Do not set default if the attribute configuration has been set.
if !req.ConfigValue.IsNull() {
return
}

resp.PlanValue = d.val
}

// NumberNumericAttributePlanModifier returns a plan modifier that keep the values
// held in number and numeric attributes synchronised.
func NumberNumericAttributePlanModifier() planmodifier.Bool {
return &numberNumericAttributePlanModifier{}
}

type numberNumericAttributePlanModifier struct {
}

func (d *numberNumericAttributePlanModifier) Description(ctx context.Context) string {
return "Ensures that number and numeric attributes are kept synchronised."
}

func (d *numberNumericAttributePlanModifier) MarkdownDescription(ctx context.Context) string {
return d.Description(ctx)
}

func (d *numberNumericAttributePlanModifier) PlanModifyBool(ctx context.Context, req planmodifier.BoolRequest, resp *planmodifier.BoolResponse) {
numberConfig := types.Bool{}
diags := req.Config.GetAttribute(ctx, path.Root("number"), &numberConfig)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

numericConfig := types.Bool{}
diags = req.Config.GetAttribute(ctx, path.Root("numeric"), &numericConfig)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

if !numberConfig.IsNull() && !numericConfig.IsNull() && (numberConfig.ValueBool() != numericConfig.ValueBool()) {
resp.Diagnostics.AddError(
"Number and numeric are both configured with different values",
"Number is deprecated, use numeric instead",
)
return
}

// Default to true for both number and numeric when both are null.
if numberConfig.IsNull() && numericConfig.IsNull() {
resp.PlanValue = types.BoolValue(true)
return
}

// Default to using value for numeric if number is null.
if numberConfig.IsNull() && !numericConfig.IsNull() {
resp.PlanValue = numericConfig
return
}

// Default to using value for number if numeric is null.
if !numberConfig.IsNull() && numericConfig.IsNull() {
resp.PlanValue = numberConfig
return
}
}

0 comments on commit 6c1912d

Please sign in to comment.