Skip to content

Commit

Permalink
Update containers_job_resource.go
Browse files Browse the repository at this point in the history
  • Loading branch information
JensWalter committed Sep 9, 2024
1 parent f8a7fa4 commit 9174e57
Showing 1 changed file with 45 additions and 13 deletions.
58 changes: 45 additions & 13 deletions internal/provider/containers_job_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,28 @@ func newContainersJobResource() resource.Resource {
}

type containersJobResource struct {
Id types.String `tfsdk:"id" json:"id"`
Name types.String `tfsdk:"name" json:"name"`
ContainerImage types.String `tfsdk:"container_image" json:"containerImage"`
ContainerPullUser types.String `tfsdk:"container_pull_user" json:"containerPullUser"`
ContainerPullPwd types.String `tfsdk:"container_pull_pwd" json:"containerPullPwd"`
ScheduleType types.String `tfsdk:"schedule_type" json:"scheduleType"`
ScheduleRepeat types.String `tfsdk:"schedule_repeat" json:"scheduleRepeat"`
ScheduleCron types.String `tfsdk:"schedule_cron" json:"scheduleCron"`
ScheduleCostOptimzation types.String `tfsdk:"schedule_cost_optimization" json:"scheduleCostOptimzation"`
Id types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
ContainerImage types.String `tfsdk:"container_image"`
ContainerPullUser types.String `tfsdk:"container_pull_user"`
ContainerPullPwd types.String `tfsdk:"container_pull_pwd""`

Check failure on line 30 in internal/provider/containers_job_resource.go

View workflow job for this annotation

GitHub Actions / Build

structtag: struct field tag `tfsdk:"container_pull_pwd""` not compatible with reflect.StructTag.Get: key:"value" pairs not separated by spaces (govet)

Check failure on line 30 in internal/provider/containers_job_resource.go

View workflow job for this annotation

GitHub Actions / Build

structtag: struct field tag `tfsdk:"container_pull_pwd""` not compatible with reflect.StructTag.Get: key:"value" pairs not separated by spaces (govet)
ScheduleType types.String `tfsdk:"schedule_type"`
ScheduleRepeat types.String `tfsdk:"schedule_repeat"`
ScheduleCron types.String `tfsdk:"schedule_cron"`
ScheduleCostOptimzation types.String `tfsdk:"schedule_cost_optimization"`
api_key string
}

type containersJobResponse struct {
Id string `json:"id"`
Name string `json:"name"`
ContainerImage string `json:"containerImage"`
ContainerPullUser string `json:"containerPullUser"`
ContainerPullPwd string `json:"containerPullPwd"`
ScheduleType string `json:"scheduleType"`
ScheduleRepeat string `json:"scheduleRepeat"`
ScheduleCron string `json:"scheduleCron"`
ScheduleCostOptimzation string `json:"scheduleCostOptimzation"`
api_key string

Check failure on line 48 in internal/provider/containers_job_resource.go

View workflow job for this annotation

GitHub Actions / Build

field `api_key` is unused (unused)

Check failure on line 48 in internal/provider/containers_job_resource.go

View workflow job for this annotation

GitHub Actions / Build

field `api_key` is unused (unused)
}

Expand Down Expand Up @@ -140,14 +153,23 @@ func (d *containersJobResource) Create(ctx context.Context, req resource.CreateR
return
}

var jobResponse containersJobResource
var jobResponse containersJobResponse
err = json.NewDecoder(res.Body).Decode(&jobResponse)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to parse response, got error: %s", err))
return
}

plan.Id = jobResponse.Id
plan.Id = types.StringValue(jobResponse.Id)
plan.Name = types.StringValue(jobResponse.Name)
plan.ContainerImage = types.StringValue(jobResponse.ContainerImage)
plan.ContainerPullUser = types.StringValue(jobResponse.ContainerPullUser)
plan.ContainerPullPwd = types.StringValue(jobResponse.ContainerPullPwd)
plan.ScheduleType = types.StringValue(jobResponse.ScheduleType)
plan.ScheduleRepeat = types.StringValue(jobResponse.ScheduleRepeat)
plan.ScheduleCron = types.StringValue(jobResponse.ScheduleCron)
plan.ScheduleCostOptimzation = types.StringValue(jobResponse.ScheduleCostOptimzation)

diags = resp.State.Set(ctx, plan)
resp.Diagnostics.Append(diags...)

Expand Down Expand Up @@ -268,14 +290,24 @@ func (d *containersJobResource) Update(ctx context.Context, req resource.UpdateR
return
}

var jobResponse containersJobResource
var jobResponse containersJobResponse
err = json.NewDecoder(res.Body).Decode(&jobResponse)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to parse response, got error: %s", err))
return
}

diags = resp.State.Set(ctx, jobResponse)
plan.Id = types.StringValue(jobResponse.Id)
plan.Name = types.StringValue(jobResponse.Name)
plan.ContainerImage = types.StringValue(jobResponse.ContainerImage)
plan.ContainerPullUser = types.StringValue(jobResponse.ContainerPullUser)
plan.ContainerPullPwd = types.StringValue(jobResponse.ContainerPullPwd)
plan.ScheduleType = types.StringValue(jobResponse.ScheduleType)
plan.ScheduleRepeat = types.StringValue(jobResponse.ScheduleRepeat)
plan.ScheduleCron = types.StringValue(jobResponse.ScheduleCron)
plan.ScheduleCostOptimzation = types.StringValue(jobResponse.ScheduleCostOptimzation)

diags = resp.State.Set(ctx, plan)
resp.Diagnostics.Append(diags...)

// Add debug log after receiving the response
Expand Down

0 comments on commit 9174e57

Please sign in to comment.