Skip to content

Commit

Permalink
fix(automations): use req.Plan in Create() for default value (#318)
Browse files Browse the repository at this point in the history
* fix(automations): use req.Plan in Create() for default value

* remove some logs

* fix types
  • Loading branch information
parkedwards authored Dec 6, 2024
1 parent 462bb31 commit eaefddc
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion internal/api/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type DeploymentCreate struct {
// DeploymentUpdate is a subset of Deployment used when updating deployments.
type DeploymentUpdate struct {
ConcurrencyLimit *int64 `json:"concurrency_limit,omitempty"`
ConcurrencyOptions *ConcurrencyOptions `json:"concurrency_options,omitempty"`
ConcurrencyOptions *ConcurrencyOptions `json:"concurrency_options"`
Description string `json:"description,omitempty"`
EnforceParameterSchema bool `json:"enforce_parameter_schema,omitempty"`
Entrypoint string `json:"entrypoint,omitempty"`
Expand Down
4 changes: 3 additions & 1 deletion internal/client/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ func request(ctx context.Context, client *http.Client, cfg requestConfig) (*http
}

if !success {
return nil, fmt.Errorf("status code %s", resp.Status)
body, _ := io.ReadAll(resp.Body)

return nil, fmt.Errorf("status code=%s, error=%s", resp.Status, body)
}

return resp, nil
Expand Down
5 changes: 1 addition & 4 deletions internal/provider/resources/automation_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"

"github.com/prefecthq/terraform-provider-prefect/internal/api"
"github.com/prefecthq/terraform-provider-prefect/internal/provider/customtypes"
Expand Down Expand Up @@ -79,7 +78,7 @@ func (r *AutomationResource) Create(ctx context.Context, req resource.CreateRequ
var plan AutomationResourceModel

// Populate the model from resource configuration and emit diagnostics on error
resp.Diagnostics.Append(req.Config.Get(ctx, &plan)...)
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
if resp.Diagnostics.HasError() {
return
}
Expand Down Expand Up @@ -180,8 +179,6 @@ func (r *AutomationResource) Update(ctx context.Context, req resource.UpdateRequ
return
}

tflog.Info(ctx, fmt.Sprintf("planID: %+v", plan.ID.ValueString()))

automationID, err := uuid.Parse(plan.ID.ValueString())
if err != nil {
resp.Diagnostics.Append(helpers.ParseUUIDErrorDiagnostic("Automation", err))
Expand Down
10 changes: 6 additions & 4 deletions internal/provider/resources/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/listdefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
Expand Down Expand Up @@ -238,6 +239,7 @@ func (r *DeploymentResource) Schema(_ context.Context, _ resource.SchemaRequest,
Optional: true,
Computed: true,
CustomType: jsontypes.NormalizedType{},
Default: stringdefault.StaticString("{}"),
},
"work_queue_name": schema.StringAttribute{
Description: "The work queue for the deployment. If no work queue is set, work will not be scheduled.",
Expand Down Expand Up @@ -299,12 +301,14 @@ func (r *DeploymentResource) Schema(_ context.Context, _ resource.SchemaRequest,
Optional: true,
Computed: true,
CustomType: jsontypes.NormalizedType{},
Default: stringdefault.StaticString("{}"),
},
"parameter_openapi_schema": schema.StringAttribute{
Description: "The parameter schema of the flow, including defaults.",
Optional: true,
Computed: true,
CustomType: jsontypes.NormalizedType{},
Default: stringdefault.StaticString("{}"),
// OpenAPI schema is also only set on create, and
// we do not support modifying this value. Therefore, any changes
// to this attribute will force a replacement.
Expand All @@ -315,15 +319,13 @@ func (r *DeploymentResource) Schema(_ context.Context, _ resource.SchemaRequest,
"concurrency_limit": schema.Int64Attribute{
Description: "The deployment's concurrency limit.",
Optional: true,
Computed: true,
Validators: []validator.Int64{
int64validator.AtLeast(1),
},
},
"concurrency_options": schema.SingleNestedAttribute{
Description: "Concurrency options for the deployment.",
Optional: true,
Computed: true,
Attributes: map[string]schema.Attribute{
"collision_strategy": schema.StringAttribute{
Description: "Enumeration of concurrency collision strategies.",
Expand Down Expand Up @@ -527,7 +529,7 @@ func (r *DeploymentResource) Create(ctx context.Context, req resource.CreateRequ
var plan DeploymentResourceModel

// Populate the model from resource configuration and emit diagnostics on error
resp.Diagnostics.Append(req.Config.Get(ctx, &plan)...)
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
if resp.Diagnostics.HasError() {
return
}
Expand Down Expand Up @@ -762,7 +764,7 @@ func (r *DeploymentResource) Update(ctx context.Context, req resource.UpdateRequ
WorkQueueName: model.WorkQueueName.ValueString(),
}

if !model.ConcurrencyOptions.CollisionStrategy.IsNull() {
if model.ConcurrencyOptions != nil {
payload.ConcurrencyOptions = &api.ConcurrencyOptions{
CollisionStrategy: model.ConcurrencyOptions.CollisionStrategy.ValueString(),
}
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resources/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (r *FlowResource) Create(ctx context.Context, req resource.CreateRequest, r
var plan FlowResourceModel

// Populate the model from resource configuration and emit diagnostics on error
resp.Diagnostics.Append(req.Config.Get(ctx, &plan)...)
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
if resp.Diagnostics.HasError() {
return
}
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resources/service_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ func (r *ServiceAccountResource) Update(ctx context.Context, req resource.Update
return
}

// Practitioners can rotate their Service Account API Key my modifying the
// Practitioners can rotate their Service Account API Key by modifying the
// `api_key_expiration` attribute. If the provided value is different than the current
// value, we'll call the RotateKey method on the client, which returns the
// ServiceAccount object with the new API Key value included in the response.
Expand Down

0 comments on commit eaefddc

Please sign in to comment.