Skip to content

Commit

Permalink
feat: migrate client resource to plugin framework default value funct…
Browse files Browse the repository at this point in the history
…ions (#18)
  • Loading branch information
gmichels authored Mar 24, 2023
1 parent 95f2a97 commit b51438a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 24 deletions.
26 changes: 7 additions & 19 deletions adguard/client_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/terraform-community-providers/terraform-plugin-framework-utils/modifiers"
)

// ensure the implementation satisfies the expected interfaces
Expand Down Expand Up @@ -96,49 +96,37 @@ func (r *clientResource) Schema(_ context.Context, _ resource.SchemaRequest, res
Description: "Whether to use global settings on this client",
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.Bool{
modifiers.DefaultBool(true),
},
Default: booldefault.StaticBool(true),
},
"filtering_enabled": schema.BoolAttribute{
Description: "Whether to have filtering enabled on this client",
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.Bool{
modifiers.DefaultBool(false),
},
Default: booldefault.StaticBool(false),
},
"parental_enabled": schema.BoolAttribute{
Description: "Whether to have AdGuard parental controls enabled on this client",
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.Bool{
modifiers.DefaultBool(false),
},
Default: booldefault.StaticBool(false),
},
"safebrowsing_enabled": schema.BoolAttribute{
Description: "Whether to have AdGuard browsing security enabled on this client",
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.Bool{
modifiers.DefaultBool(false),
},
Default: booldefault.StaticBool(false),
},
"safesearch_enabled": schema.BoolAttribute{
Description: "Whether to enforce safe search on this client",
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.Bool{
modifiers.DefaultBool(false),
},
Default: booldefault.StaticBool(false),
},
"use_global_blocked_services": schema.BoolAttribute{
Description: "Whether to use global settings for blocked services",
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.Bool{
modifiers.DefaultBool(true),
},
Default: booldefault.StaticBool(true),
},
"blocked_services": schema.ListAttribute{
Description: "List of blocked services for this client",
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ require (
github.com/hashicorp/terraform-plugin-go v0.14.3
github.com/hashicorp/terraform-plugin-log v0.8.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.26.1
github.com/terraform-community-providers/terraform-plugin-framework-utils v0.3.0
)

require (
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBD
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
github.com/gmichels/adguard-client-go v0.2.0 h1:uozTy5NCQj3gt1/ifaeIs58PIOzHcHqAFxX/04BRxgA=
github.com/gmichels/adguard-client-go v0.2.0/go.mod h1:77E8dDI1mhRP5E7tNJWvtF2PLqZiqwcmMrgBUCCc4KY=
github.com/gmichels/adguard-client-go v0.2.1 h1:N+SArVllJixvN1jA2zSp+vsrtmZVmAQymY5q0dzhsMU=
github.com/gmichels/adguard-client-go v0.2.1/go.mod h1:77E8dDI1mhRP5E7tNJWvtF2PLqZiqwcmMrgBUCCc4KY=
github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4=
Expand Down Expand Up @@ -199,8 +197,6 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/terraform-community-providers/terraform-plugin-framework-utils v0.3.0 h1:9p3a6Y9H/RiBpeY+V28R3nSPLAOG8z4lP17QyunXMfE=
github.com/terraform-community-providers/terraform-plugin-framework-utils v0.3.0/go.mod h1:qxBCEJqhF0NPLX+FrRYALlpxXSi1nhTx/x1aimUEqRY=
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
Expand Down

0 comments on commit b51438a

Please sign in to comment.