Skip to content

Commit

Permalink
Update based on comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sreallymatt committed Jan 14, 2025
1 parent a5fdc59 commit 7485914
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
10 changes: 5 additions & 5 deletions internal/services/mssql/mssql_job_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
type MsSqlJobResource struct{}

type MsSqlJobResourceModel struct {
Description string `tfschema:"description"`
JobAgentID string `tfschema:"job_agent_id"`
Name string `tfschema:"name"`
JobAgentID string `tfschema:"job_agent_id"`
Description string `tfschema:"description"`
}

var _ sdk.ResourceWithUpdate = MsSqlJobResource{}
Expand Down Expand Up @@ -147,14 +147,14 @@ func (MsSqlJobResource) Update() sdk.ResourceFunc {
return err
}

var state MsSqlJobResourceModel
if err := metadata.Decode(&state); err != nil {
var config MsSqlJobResourceModel
if err := metadata.Decode(&config); err != nil {
return fmt.Errorf("decoding: %+v", err)
}

param := jobs.Job{
Properties: pointer.To(jobs.JobProperties{
Description: pointer.To(state.Description),
Description: pointer.To(config.Description),
}),
}

Expand Down
36 changes: 23 additions & 13 deletions internal/services/mssql/mssql_job_schedule_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-08-01-preview/jobs"
"github.com/hashicorp/terraform-provider-azurerm/helpers/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/locks"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/suppress"
Expand All @@ -18,12 +19,12 @@ import (
type MsSqlJobScheduleResource struct{}

type MsSqlJobScheduleResourceModel struct {
JobID string `tfschema:"job_id"`
Type string `tfschema:"type"`
Enabled bool `tfschema:"enabled"`
EndTime string `tfschema:"end_time"`
Interval string `tfschema:"interval"`
JobID string `tfschema:"job_id"`
StartTime string `tfschema:"start_time"`
Type string `tfschema:"type"`
}

var (
Expand All @@ -33,6 +34,17 @@ var (

func (MsSqlJobScheduleResource) Arguments() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"job_id": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: jobs.ValidateJobID,
},
"type": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(jobs.PossibleValuesForJobScheduleType(), false),
},
"enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Expand All @@ -52,12 +64,6 @@ func (MsSqlJobScheduleResource) Arguments() map[string]*pluginsdk.Schema {
Optional: true,
ValidateFunc: validate.ISO8601Duration,
},
"job_id": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: jobs.ValidateJobID,
},
"start_time": {
Type: pluginsdk.TypeString,
Optional: true,
Expand All @@ -66,11 +72,6 @@ func (MsSqlJobScheduleResource) Arguments() map[string]*pluginsdk.Schema {
DiffSuppressFunc: suppress.RFC3339MinuteTime,
ValidateFunc: validation.IsRFC3339Time,
},
"type": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(jobs.PossibleValuesForJobScheduleType(), false),
},
}
}

Expand Down Expand Up @@ -120,6 +121,9 @@ func (r MsSqlJobScheduleResource) Create() sdk.ResourceFunc {
return err
}

locks.ByID(jobId.ID())
defer locks.UnlockByID(jobId.ID())

existing, err := client.Get(ctx, *jobId)
if err != nil {
if response.WasNotFound(existing.HttpResponse) {
Expand Down Expand Up @@ -223,6 +227,9 @@ func (MsSqlJobScheduleResource) Update() sdk.ResourceFunc {
return err
}

locks.ByID(jobId.ID())
defer locks.UnlockByID(jobId.ID())

var config MsSqlJobScheduleResourceModel
if err := metadata.Decode(&config); err != nil {
return fmt.Errorf("decoding: %+v", err)
Expand Down Expand Up @@ -286,6 +293,9 @@ func (MsSqlJobScheduleResource) Delete() sdk.ResourceFunc {
return err
}

locks.ByID(jobId.ID())
defer locks.UnlockByID(jobId.ID())

existing, err := client.Get(ctx, *jobId)
if err != nil {
if response.WasNotFound(existing.HttpResponse) {
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/mssql_job.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ resource "azurerm_mssql_job" "example" {

The following arguments are supported:

* `job_agent_id` - (Required) The ID of the Elastic Job Agent. Changing this forces a new Elastic Job to be created.

* `name` - (Required) The name which should be used for this Elastic Job. Changing this forces a new Elastic Job to be created.

* `job_agent_id` - (Required) The ID of the Elastic Job Agent. Changing this forces a new Elastic Job to be created.

---

* `description` - (Optional) The description of the Elastic Job.
Expand Down

0 comments on commit 7485914

Please sign in to comment.