Skip to content

Commit

Permalink
Add support for name in schedules.
Browse files Browse the repository at this point in the history
  • Loading branch information
steveworley committed Dec 13, 2024
1 parent a84e35a commit dc78571
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions docs/resources/crawler_schedule.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Manages a Quant crawler schedule.
resource "quant_crawler_schedule" "crawler_schedule" {
project = quant_project.test.machine_name
crawler = quant_crawler.crawler.uuid
name = "test-crawler-schedule"
schedule_cron_string = "0 0 * * *"
}
```
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/hashicorp/terraform-plugin-go v0.25.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.35.0
github.com/hashicorp/terraform-plugin-testing v1.11.0
github.com/quantcdn/quant-admin-go v0.0.0-20241213023303-ad9791a191a1
github.com/quantcdn/quant-admin-go v0.0.0-20241213052824-c4a71d2f4cb1
github.com/stretchr/testify v1.9.0
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ github.com/quantcdn/quant-admin-go v0.0.0-20241213014220-d9bb395a27b6 h1:lWQyzMi
github.com/quantcdn/quant-admin-go v0.0.0-20241213014220-d9bb395a27b6/go.mod h1:JDPQsgcOJGMBj3RnIbqWGHh9w5qZ+/zqrI3S3de9FWY=
github.com/quantcdn/quant-admin-go v0.0.0-20241213023303-ad9791a191a1 h1:RQtT4/S4AHBl7OEDajYj+uuUHpmT5RyUVdS3y7l9b0Y=
github.com/quantcdn/quant-admin-go v0.0.0-20241213023303-ad9791a191a1/go.mod h1:JDPQsgcOJGMBj3RnIbqWGHh9w5qZ+/zqrI3S3de9FWY=
github.com/quantcdn/quant-admin-go v0.0.0-20241213052824-c4a71d2f4cb1 h1:D79X5OQtyKUOR18GGQkVvUSV3MvnLIgdaDnWWeTnN0E=
github.com/quantcdn/quant-admin-go v0.0.0-20241213052824-c4a71d2f4cb1/go.mod h1:JDPQsgcOJGMBj3RnIbqWGHh9w5qZ+/zqrI3S3de9FWY=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L3A=
Expand Down
17 changes: 6 additions & 11 deletions internal/provider/crawler_schedule_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ func callCrawlerScheduleCreateAPI(ctx context.Context, r *crawlerScheduleResourc
req := *openapi.NewCrawlerScheduleRequestWithDefaults()

req.SetScheduleCronString(schedule.ScheduleCronString.ValueString())
req.SetName(schedule.Name.ValueString())

api, _, err := r.client.Instance.CrawlerSchedulesAPI.CrawlerSchedulesCreate(r.client.AuthContext, r.client.Organization, schedule.Project.ValueString(), schedule.Crawler.ValueString()).CrawlerScheduleRequest(req).Execute()
_, _, err := r.client.Instance.CrawlerSchedulesAPI.CrawlerSchedulesCreate(r.client.AuthContext, r.client.Organization, schedule.Project.ValueString(), schedule.Crawler.ValueString()).CrawlerScheduleRequest(req).Execute()

if err != nil {
diags.AddError(
Expand All @@ -141,13 +142,7 @@ func callCrawlerScheduleCreateAPI(ctx context.Context, r *crawlerScheduleResourc
return diags
}

schedule.Id = types.Int64Value(int64(api.GetId()))
schedule.CrawlerConfigId = types.Int64Value(int64(api.GetCrawlerConfigId()))
schedule.ProjectId = types.Int64Value(int64(api.GetProjectId()))
schedule.CrawlerLastRunId = types.Int64Value(int64(api.GetCrawlerLastRunId()))
schedule.CreatedAt = types.StringValue(api.GetCreatedAt())

return diags
return callCrawlerScheduleReadAPI(ctx, r, schedule)
}

func callCrawlerScheduleReadAPI(ctx context.Context, r *crawlerScheduleResource, schedule *resource_crawler_schedule.CrawlerScheduleModel) (diags diag.Diagnostics) {
Expand All @@ -157,7 +152,7 @@ func callCrawlerScheduleReadAPI(ctx context.Context, r *crawlerScheduleResource,
"Missing schedule.id attribute",
"To read schedule information, id must be provided.",
)
return
return diags
}

if schedule.Project.IsNull() || schedule.Project.IsUnknown() {
Expand All @@ -178,7 +173,7 @@ func callCrawlerScheduleReadAPI(ctx context.Context, r *crawlerScheduleResource,
api, _, err := r.client.Instance.CrawlerSchedulesAPI.CrawlerSchedulesRead(ctx, org, schedule.Project.ValueString(), schedule.Crawler.ValueString(), scheduleId).Execute()
if err != nil {
diags.AddError("Unable to load crawler schedule", fmt.Sprintf("Error: %s", err.Error()))
return
return diags
}

schedule.CrawlerConfigId = types.Int64Value(int64(api.GetCrawlerConfigId()))
Expand All @@ -187,7 +182,7 @@ func callCrawlerScheduleReadAPI(ctx context.Context, r *crawlerScheduleResource,
schedule.ScheduleCronString = types.StringValue(api.GetScheduleCronString())
schedule.CreatedAt = types.StringValue(api.GetCreatedAt())

return
return diags
}

func callCrawlerScheduleDeleteAPI(ctx context.Context, r *crawlerScheduleResource, schedule *resource_crawler_schedule.CrawlerScheduleModel) (diags diag.Diagnostics) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dc78571

Please sign in to comment.