Skip to content

Commit

Permalink
Use framework default values for resources
Browse files Browse the repository at this point in the history
Also add default values for lists and sets.
  • Loading branch information
np5 committed Apr 24, 2023
1 parent fa2580f commit b4cc540
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 257 deletions.
39 changes: 0 additions & 39 deletions internal/planmodifiers/bool.go

This file was deleted.

39 changes: 0 additions & 39 deletions internal/planmodifiers/int64.go

This file was deleted.

39 changes: 0 additions & 39 deletions internal/planmodifiers/string.go

This file was deleted.

6 changes: 2 additions & 4 deletions internal/provider/meta_business_unit_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (

"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/int64planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/zentralopensource/goztl"
"github.com/zentralopensource/terraform-provider-zentral/internal/planmodifiers"
)

// Ensure provider defined types fully satisfy framework interfaces
Expand Down Expand Up @@ -55,9 +55,7 @@ func (r *MetaBusinessUnitResource) Schema(ctx context.Context, req resource.Sche
"Defaults to `true`.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Bool{
planmodifiers.BoolDefault(true),
},
Default: booldefault.StaticBool(true),
},
},
}
Expand Down
6 changes: 2 additions & 4 deletions internal/provider/monolith_catalog_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (

"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/zentralopensource/goztl"
"github.com/zentralopensource/terraform-provider-zentral/internal/planmodifiers"
)

// Ensure provider defined types fully satisfy framework interfaces
Expand Down Expand Up @@ -54,9 +54,7 @@ func (r *MonolithCatalogResource) Schema(ctx context.Context, req resource.Schem
MarkdownDescription: "Priority of the catalog.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Int64{
planmodifiers.Int64Default(int64(0)),
},
Default: int64default.StaticInt64(0),
},
},
}
Expand Down
19 changes: 9 additions & 10 deletions internal/provider/monolith_sub_manifest_pkg_info_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-framework/attr"
"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/int64default"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/setdefault"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/zentralopensource/goztl"
"github.com/zentralopensource/terraform-provider-zentral/internal/planmodifiers"
)

// Ensure provider defined types fully satisfy framework interfaces
Expand Down Expand Up @@ -65,9 +68,7 @@ func (r *MonolithSubManifestPkgInfoResource) Schema(ctx context.Context, req res
MarkdownDescription: "If `true`, this pkg info will be displayed in the featured items section in Managed Software Center. Defaults to `false`.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Bool{
planmodifiers.BoolDefault(false),
},
Default: booldefault.StaticBool(false),
},
"condition_id": schema.Int64Attribute{
Description: "The ID of the condition that is evaluated to decide if this pkg info is included.",
Expand All @@ -79,25 +80,22 @@ func (r *MonolithSubManifestPkgInfoResource) Schema(ctx context.Context, req res
MarkdownDescription: "The modulo used to calculate the shards. Defaults to `100`.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Int64{
planmodifiers.Int64Default(100),
},
Default: int64default.StaticInt64(100),
},
"default_shard": schema.Int64Attribute{
Description: "The default shard value. Defaults to 100.",
MarkdownDescription: "The default shard value. Defaults to `100`.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Int64{
planmodifiers.Int64Default(100),
},
Default: int64default.StaticInt64(100),
},
"excluded_tag_ids": schema.SetAttribute{
Description: "Machines tagged with one of these tags will not receive the pkg info.",
MarkdownDescription: "Machines tagged with one of these tags will not receive the pkg info.",
ElementType: types.Int64Type,
Optional: true,
Computed: true,
Default: setdefault.StaticValue(types.SetValueMust(types.Int64Type, []attr.Value{})),
},
"tag_shards": schema.SetNestedAttribute{
Description: "A set of tag shard values different from the default shard, to determine if the tagged machines will receive the pkg info.",
Expand All @@ -118,6 +116,7 @@ func (r *MonolithSubManifestPkgInfoResource) Schema(ctx context.Context, req res
},
Optional: true,
Computed: true,
Default: setdefault.StaticValue(types.SetValueMust(types.ObjectType{AttrTypes: tagShardAttrTypes}, []attr.Value{})),
},
},
}
Expand Down
6 changes: 2 additions & 4 deletions internal/provider/monolith_sub_manifest_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/zentralopensource/goztl"
"github.com/zentralopensource/terraform-provider-zentral/internal/planmodifiers"
)

// Ensure provider defined types fully satisfy framework interfaces
Expand Down Expand Up @@ -54,9 +54,7 @@ func (r *MonolithSubManifestResource) Schema(ctx context.Context, req resource.S
MarkdownDescription: "Description of the sub manifest.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{
planmodifiers.StringDefault(""),
},
Default: stringdefault.StaticString(""),
},
"meta_business_unit_id": schema.Int64Attribute{
Description: "The ID of the meta business unit this sub manifest is restricted to.",
Expand Down
30 changes: 14 additions & 16 deletions internal/provider/munki_configuration_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-framework/attr"
"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/int64default"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/listdefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/setdefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/zentralopensource/goztl"
"github.com/zentralopensource/terraform-provider-zentral/internal/planmodifiers"
)

// Ensure provider defined types fully satisfy framework interfaces
Expand Down Expand Up @@ -55,66 +60,59 @@ func (r *MunkiConfigurationResource) Schema(ctx context.Context, req resource.Sc
MarkdownDescription: "Description of the Munki configuration.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{
planmodifiers.StringDefault(""),
},
Default: stringdefault.StaticString(""),
},
"inventory_apps_full_info_shard": schema.Int64Attribute{
Description: "Percentage of machines configured to collect the full inventory apps information. Defaults to 100.",
MarkdownDescription: "Percentage of machines configured to collect the full inventory apps information. Defaults to `100`.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Int64{
planmodifiers.Int64Default(int64(100)),
},
Default: int64default.StaticInt64(100),
},
"principal_user_detection_sources": schema.ListAttribute{
Description: "List of principal user detection sources.",
MarkdownDescription: "List of principal user detection sources.",
ElementType: types.StringType,
Optional: true,
Computed: true,
Default: listdefault.StaticValue(types.ListValueMust(types.StringType, []attr.Value{})),
},
"principal_user_detection_domains": schema.SetAttribute{
Description: "Set of principal user detection domains.",
MarkdownDescription: "Set of principal user detection domains.",
ElementType: types.StringType,
Optional: true,
Computed: true,
Default: setdefault.StaticValue(types.SetValueMust(types.StringType, []attr.Value{})),
},
"collected_condition_keys": schema.SetAttribute{
Description: "Set of the condition keys to collect.",
MarkdownDescription: "Set of the condition keys to collect.",
ElementType: types.StringType,
Optional: true,
Computed: true,
Default: setdefault.StaticValue(types.SetValueMust(types.StringType, []attr.Value{})),
},
"managed_installs_sync_interval_days": schema.Int64Attribute{
Description: "Interval in days between full managed installs sync. Defaults to 7 days.",
MarkdownDescription: "Interval in days between full managed installs sync. Defaults to 7 days.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Int64{
planmodifiers.Int64Default(int64(7)),
},
Default: int64default.StaticInt64(7),
},
"auto_reinstall_incidents": schema.BoolAttribute{
Description: "If true, incidents will be managed automatically when package reinstalls are observed. Defaults to false.",
MarkdownDescription: "If `true`, incidents will be managed automatically when package reinstalls are observed. Defaults to `false`.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Bool{
planmodifiers.BoolDefault(false),
},
Default: booldefault.StaticBool(false),
},
"auto_failed_install_incidents": schema.BoolAttribute{
Description: "If true, incidents will be managed automatically when package failed installs are observed. Defaults to false.",
MarkdownDescription: "If `true`, incidents will be managed automatically when package failed installs are observed. Defaults to `false`.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Bool{
planmodifiers.BoolDefault(false),
},
Default: booldefault.StaticBool(false),
},
"version": schema.Int64Attribute{
Description: "Version of the Munki configuration.",
Expand Down
6 changes: 2 additions & 4 deletions internal/provider/osquery_atc_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/zentralopensource/goztl"
"github.com/zentralopensource/terraform-provider-zentral/internal/planmodifiers"
)

// Ensure provider defined types fully satisfy framework interfaces
Expand Down Expand Up @@ -55,9 +55,7 @@ func (r *OsqueryATCResource) Schema(ctx context.Context, req resource.SchemaRequ
MarkdownDescription: "Description of the Osquery ATC.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{
planmodifiers.StringDefault(""),
},
Default: stringdefault.StaticString(""),
},
"table_name": schema.StringAttribute{
Description: "Name of the Osquery ATC table.",
Expand Down
Loading

0 comments on commit b4cc540

Please sign in to comment.