Skip to content

Commit

Permalink
Add sync resource active attribute (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeNeyer authored Jul 31, 2023
1 parent 6e25956 commit 843d692
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/resources/sync.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ resource "polytomic_sync" "sync" {

### Optional

- `active` (Boolean)
- `filter_logic` (String)
- `filters` (Attributes Set) (see [below for nested schema](#nestedatt--filters))
- `identity` (Attributes) (see [below for nested schema](#nestedatt--identity))
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.27.0
github.com/mitchellh/mapstructure v1.5.0
github.com/polytomic/polytomic-go v0.0.0-20230619163938-090057d1ea3d
github.com/polytomic/polytomic-go v0.0.0-20230728194459-f98ea2ba4638
github.com/rs/zerolog v1.30.0
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.16.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/polytomic/polytomic-go v0.0.0-20230619163938-090057d1ea3d h1:g8OR+Uz2+l+ixRCnpVRk4j4w7RAA5joUjpc79jOkzvQ=
github.com/polytomic/polytomic-go v0.0.0-20230619163938-090057d1ea3d/go.mod h1:+XkC/jjW7clbyvuUrL973eCzno0HmGoYZO5qNMUNSfU=
github.com/polytomic/polytomic-go v0.0.0-20230728194459-f98ea2ba4638 h1:S/3enkkzfuzjl1UQRGKpStuZtgbkm5n/yUYGyC7XozM=
github.com/polytomic/polytomic-go v0.0.0-20230728194459-f98ea2ba4638/go.mod h1:+XkC/jjW7clbyvuUrL973eCzno0HmGoYZO5qNMUNSfU=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo=
github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s=
Expand Down
11 changes: 11 additions & 0 deletions provider/resource_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ func (r *syncResource) Schema(ctx context.Context, req resource.SchemaRequest, r
},
Required: true,
},
"active": schema.BoolAttribute{
MarkdownDescription: "",
Optional: true,
Computed: true,
},
"mode": schema.StringAttribute{
MarkdownDescription: "",
Required: true,
Expand Down Expand Up @@ -325,6 +330,7 @@ type syncResourceResourceData struct {
Schedule types.Object `tfsdk:"schedule"`
Identity types.Object `tfsdk:"identity"`
SyncAllRecords types.Bool `tfsdk:"sync_all_records"`
Active types.Bool `tfsdk:"active"`
}

type Filter struct {
Expand Down Expand Up @@ -515,6 +521,7 @@ func (r *syncResource) Create(ctx context.Context, req resource.CreateRequest, r
Overrides: poverrides,
Schedule: schedule,
SyncAllRecords: data.SyncAllRecords.ValueBool(),
Active: data.Active.ValueBool(),
}

if identity.Source.ModelID != "" && identity.Source.Field != "" {
Expand Down Expand Up @@ -719,6 +726,7 @@ func (r *syncResource) Create(ctx context.Context, req resource.CreateRequest, r
return
}
data.SyncAllRecords = types.BoolValue(sync.SyncAllRecords)
data.Active = types.BoolValue(sync.Active)

diags = resp.State.Set(ctx, &data)
resp.Diagnostics.Append(diags...)
Expand Down Expand Up @@ -939,6 +947,7 @@ func (r *syncResource) Read(ctx context.Context, req resource.ReadRequest, resp
return
}
data.SyncAllRecords = types.BoolValue(sync.SyncAllRecords)
data.Active = types.BoolValue(sync.Active)

diags = resp.State.Set(ctx, &data)
resp.Diagnostics.Append(diags...)
Expand Down Expand Up @@ -1111,6 +1120,7 @@ func (r *syncResource) Update(ctx context.Context, req resource.UpdateRequest, r
Schedule: schedule,
Identity: identity,
SyncAllRecords: data.SyncAllRecords.ValueBool(),
Active: data.Active.ValueBool(),
}
sync, err := r.client.Syncs().Update(ctx, data.ID.ValueString(), request)
if err != nil {
Expand Down Expand Up @@ -1311,6 +1321,7 @@ func (r *syncResource) Update(ctx context.Context, req resource.UpdateRequest, r
return
}
data.SyncAllRecords = types.BoolValue(sync.SyncAllRecords)
data.Active = types.BoolValue(sync.Active)

diags = resp.State.Set(ctx, &data)
resp.Diagnostics.Append(diags...)
Expand Down

0 comments on commit 843d692

Please sign in to comment.