-
Notifications
You must be signed in to change notification settings - Fork 5k
New Resource: azurerm_durable_task_scheduler, azurerm_durable_task_hub, azurerm_durable_task_retention_policy & New Data Source: azurerm_durable_task_scheduler
#32194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
stemaMSFT
wants to merge
22
commits into
hashicorp:main
Choose a base branch
from
stemaMSFT:feature/durable-task-service-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
2267556
Add Azure Durable Task service implementation with comprehensive tests
stemaMSFT e77acc1
upgrade sdk
stemaMSFT 4728bb7
following contributor guidelines added docs and testing. tests pass
stemaMSFT 0f8a50c
fixing website test failing
stemaMSFT 9cc8735
renamed files per guidelines
stemaMSFT 812b391
fixing doc errors
stemaMSFT e114fdd
fix make generate issue
stemaMSFT 24f0cf4
added forcenew to sku
stemaMSFT feb5fc1
fix copyright headers - no code changes made
stemaMSFT d2dd8dd
fixed static analysis test fails
stemaMSFT 6f41cc8
add data source/test for durable task scheduler. fixed docs.
stemaMSFT ef8c492
Remove unrelated managed redis changes from branch
stemaMSFT 11324da
fix: regenerate API section in durable task data source docs
stemaMSFT f6a8894
resync and push with doc fixes
stemaMSFT 6bd2218
go mod tidy && go mod vendor after rebase
stemaMSFT 36ea7cd
revert unrelated managedredis changes
stemaMSFT 60b697e
fix: address PR #32194 review - schema ordering, delta update, Customβ¦
stemaMSFT 6eb4255
style: remove unnecessary comments and redundant test checks per review
stemaMSFT 18c813f
test: align acceptance tests with contributor guidelines
stemaMSFT 4e8c68f
style: fix gofmt formatting in scheduler resource
stemaMSFT 56217a1
address PR #32194 review feedback from WodansSon
stemaMSFT cc2ce17
fix: gofmt alignment on sku_name field in scheduler resource
stemaMSFT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Copyright IBM Corp. 2014, 2025 | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package client | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/hashicorp/go-azure-sdk/resource-manager/durabletask/2025-11-01/retentionpolicies" | ||
| "github.com/hashicorp/go-azure-sdk/resource-manager/durabletask/2025-11-01/schedulers" | ||
| "github.com/hashicorp/go-azure-sdk/resource-manager/durabletask/2025-11-01/taskhubs" | ||
| "github.com/hashicorp/terraform-provider-azurerm/internal/common" | ||
| ) | ||
|
|
||
| type Client struct { | ||
| SchedulersClient *schedulers.SchedulersClient | ||
| TaskHubsClient *taskhubs.TaskHubsClient | ||
| RetentionPoliciesClient *retentionpolicies.RetentionPoliciesClient | ||
| } | ||
|
|
||
| func NewClient(o *common.ClientOptions) (*Client, error) { | ||
| schedulersClient, err := schedulers.NewSchedulersClientWithBaseURI(o.Environment.ResourceManager) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("building Schedulers client: %+v", err) | ||
| } | ||
| o.Configure(schedulersClient.Client, o.Authorizers.ResourceManager) | ||
|
|
||
| taskHubsClient, err := taskhubs.NewTaskHubsClientWithBaseURI(o.Environment.ResourceManager) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("building TaskHubs client: %+v", err) | ||
| } | ||
| o.Configure(taskHubsClient.Client, o.Authorizers.ResourceManager) | ||
|
|
||
| retentionPoliciesClient, err := retentionpolicies.NewRetentionPoliciesClientWithBaseURI(o.Environment.ResourceManager) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("building RetentionPolicies client: %+v", err) | ||
| } | ||
| o.Configure(retentionPoliciesClient.Client, o.Authorizers.ResourceManager) | ||
|
|
||
| return &Client{ | ||
| SchedulersClient: schedulersClient, | ||
| TaskHubsClient: taskHubsClient, | ||
| RetentionPoliciesClient: retentionPoliciesClient, | ||
| }, nil | ||
| } |
173 changes: 173 additions & 0 deletions
173
internal/services/durabletask/durable_task_hub_resource.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| // Copyright IBM Corp. 2014, 2025 | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package durabletask | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "time" | ||
|
|
||
| "github.com/hashicorp/go-azure-helpers/lang/pointer" | ||
| "github.com/hashicorp/go-azure-helpers/lang/response" | ||
| "github.com/hashicorp/go-azure-sdk/resource-manager/durabletask/2025-11-01/schedulers" | ||
| "github.com/hashicorp/go-azure-sdk/resource-manager/durabletask/2025-11-01/taskhubs" | ||
| "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" | ||
| "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
| ) | ||
|
|
||
| type TaskHubResourceModel struct { | ||
| Name string `tfschema:"name"` | ||
| SchedulerId string `tfschema:"scheduler_id"` | ||
| DashboardUrl string `tfschema:"dashboard_url"` | ||
| } | ||
|
|
||
| type TaskHubResource struct{} | ||
|
|
||
| var _ sdk.Resource = TaskHubResource{} | ||
|
|
||
| func (r TaskHubResource) ResourceType() string { | ||
| return "azurerm_durable_task_hub" | ||
| } | ||
|
|
||
| func (r TaskHubResource) ModelObject() interface{} { | ||
| return &TaskHubResourceModel{} | ||
| } | ||
|
|
||
| func (r TaskHubResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { | ||
| return taskhubs.ValidateTaskHubID | ||
| } | ||
|
|
||
| func (r TaskHubResource) Arguments() map[string]*pluginsdk.Schema { | ||
| return map[string]*pluginsdk.Schema{ | ||
| "name": { | ||
| Type: pluginsdk.TypeString, | ||
| Required: true, | ||
| ForceNew: true, | ||
| ValidateFunc: ValidateTaskHubName, | ||
| }, | ||
|
|
||
| "scheduler_id": { | ||
| Type: pluginsdk.TypeString, | ||
| Required: true, | ||
| ForceNew: true, | ||
| ValidateFunc: schedulers.ValidateSchedulerID, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func (r TaskHubResource) Attributes() map[string]*pluginsdk.Schema { | ||
| return map[string]*pluginsdk.Schema{ | ||
| "dashboard_url": { | ||
| Type: pluginsdk.TypeString, | ||
| Computed: true, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func (r TaskHubResource) Create() sdk.ResourceFunc { | ||
| return sdk.ResourceFunc{ | ||
| Timeout: 30 * time.Minute, | ||
| Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { | ||
| client := metadata.Client.DurableTask.TaskHubsClient | ||
|
|
||
| var model TaskHubResourceModel | ||
| if err := metadata.Decode(&model); err != nil { | ||
| return fmt.Errorf("decoding: %+v", err) | ||
| } | ||
|
|
||
| schedulerId, err := schedulers.ParseSchedulerID(model.SchedulerId) | ||
| if err != nil { | ||
| return fmt.Errorf("parsing scheduler ID: %+v", err) | ||
| } | ||
|
|
||
| id := taskhubs.NewTaskHubID(schedulerId.SubscriptionId, schedulerId.ResourceGroupName, schedulerId.SchedulerName, model.Name) | ||
|
|
||
| metadata.Logger.Infof("Import check for %s", id) | ||
| existing, err := client.Get(ctx, id) | ||
| if err != nil && !response.WasNotFound(existing.HttpResponse) { | ||
| return fmt.Errorf("checking for presence of existing %s: %+v", id, err) | ||
| } | ||
|
|
||
| if !response.WasNotFound(existing.HttpResponse) { | ||
| return metadata.ResourceRequiresImport(r.ResourceType(), id) | ||
| } | ||
|
|
||
| metadata.Logger.Infof("Creating %s", id) | ||
|
|
||
| properties := taskhubs.TaskHub{ | ||
| Properties: &taskhubs.TaskHubProperties{}, | ||
| } | ||
|
|
||
| if err := client.CreateOrUpdateThenPoll(ctx, id, properties); err != nil { | ||
| return fmt.Errorf("creating %s: %+v", id, err) | ||
| } | ||
|
|
||
| metadata.SetID(id) | ||
| return nil | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func (r TaskHubResource) Read() sdk.ResourceFunc { | ||
| return sdk.ResourceFunc{ | ||
| Timeout: 5 * time.Minute, | ||
| Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { | ||
| client := metadata.Client.DurableTask.TaskHubsClient | ||
|
|
||
| id, err := taskhubs.ParseTaskHubID(metadata.ResourceData.Id()) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| metadata.Logger.Infof("Reading %s", id) | ||
| resp, err := client.Get(ctx, *id) | ||
| if err != nil { | ||
| if response.WasNotFound(resp.HttpResponse) { | ||
| return metadata.MarkAsGone(id) | ||
| } | ||
| return fmt.Errorf("retrieving %s: %+v", *id, err) | ||
| } | ||
|
|
||
| model := resp.Model | ||
| if model == nil { | ||
| return fmt.Errorf("retrieving %s: model was nil", id) | ||
| } | ||
|
|
||
| schedulerId := schedulers.NewSchedulerID(id.SubscriptionId, id.ResourceGroupName, id.SchedulerName) | ||
|
|
||
| state := TaskHubResourceModel{ | ||
| Name: id.TaskHubName, | ||
| SchedulerId: schedulerId.ID(), | ||
| } | ||
|
|
||
| if props := model.Properties; props != nil { | ||
| state.DashboardUrl = pointer.From(props.DashboardURL) | ||
| } | ||
|
|
||
| return metadata.Encode(&state) | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func (r TaskHubResource) Delete() sdk.ResourceFunc { | ||
| return sdk.ResourceFunc{ | ||
| Timeout: 30 * time.Minute, | ||
| Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { | ||
| client := metadata.Client.DurableTask.TaskHubsClient | ||
|
|
||
| id, err := taskhubs.ParseTaskHubID(metadata.ResourceData.Id()) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| metadata.Logger.Infof("Deleting %s", id) | ||
|
|
||
| if err := client.DeleteThenPoll(ctx, *id); err != nil { | ||
| return fmt.Errorf("deleting %s: %+v", id, err) | ||
| } | ||
|
|
||
| return nil | ||
| }, | ||
| } | ||
| } | ||
107 changes: 107 additions & 0 deletions
107
internal/services/durabletask/durable_task_hub_resource_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| // Copyright IBM Corp. 2014, 2025 | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package durabletask_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/hashicorp/go-azure-helpers/lang/pointer" | ||
| "github.com/hashicorp/go-azure-sdk/resource-manager/durabletask/2025-11-01/taskhubs" | ||
| "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" | ||
| "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" | ||
| "github.com/hashicorp/terraform-provider-azurerm/internal/clients" | ||
| "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
| ) | ||
|
|
||
| type TaskHubResource struct{} | ||
|
|
||
| func TestAccDurableTaskHub_basic(t *testing.T) { | ||
| data := acceptance.BuildTestData(t, "azurerm_durable_task_hub", "test") | ||
| r := TaskHubResource{} | ||
|
|
||
| data.ResourceTest(t, r, []acceptance.TestStep{ | ||
| { | ||
| Config: r.basic(data), | ||
| Check: acceptance.ComposeTestCheckFunc( | ||
| check.That(data.ResourceName).ExistsInAzure(r), | ||
| ), | ||
| }, | ||
| data.ImportStep(), | ||
| }) | ||
| } | ||
|
|
||
| func TestAccDurableTaskHub_requiresImport(t *testing.T) { | ||
| data := acceptance.BuildTestData(t, "azurerm_durable_task_hub", "test") | ||
| r := TaskHubResource{} | ||
|
|
||
| data.ResourceTest(t, r, []acceptance.TestStep{ | ||
| { | ||
| Config: r.basic(data), | ||
| Check: acceptance.ComposeTestCheckFunc( | ||
| check.That(data.ResourceName).ExistsInAzure(r), | ||
| ), | ||
| }, | ||
| data.RequiresImportErrorStep(r.requiresImport), | ||
| }) | ||
| } | ||
|
|
||
| func (r TaskHubResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { | ||
| id, err := taskhubs.ParseTaskHubID(state.ID) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| if _, err = client.DurableTask.TaskHubsClient.Get(ctx, *id); err != nil { | ||
| return nil, fmt.Errorf("retrieving %s: %v", id, err) | ||
| } | ||
|
|
||
| return pointer.To(true), nil | ||
| } | ||
|
|
||
| func (r TaskHubResource) template(data acceptance.TestData) string { | ||
| return fmt.Sprintf(` | ||
| provider "azurerm" { | ||
| features {} | ||
| } | ||
|
|
||
| resource "azurerm_resource_group" "test" { | ||
| name = "acctestRG-durabletask-%d" | ||
| location = "%s" | ||
| } | ||
|
|
||
| resource "azurerm_durable_task_scheduler" "test" { | ||
| name = "acctestdts%s" | ||
| resource_group_name = azurerm_resource_group.test.name | ||
| location = azurerm_resource_group.test.location | ||
| sku_name = "Consumption" | ||
| ip_allow_list = ["0.0.0.0/0"] | ||
| } | ||
| `, data.RandomInteger, data.Locations.Primary, data.RandomString) | ||
| } | ||
|
|
||
| func (r TaskHubResource) basic(data acceptance.TestData) string { | ||
| template := r.template(data) | ||
| return fmt.Sprintf(` | ||
| %s | ||
|
|
||
| resource "azurerm_durable_task_hub" "test" { | ||
| name = "acctestdth%s" | ||
| scheduler_id = azurerm_durable_task_scheduler.test.id | ||
| } | ||
| `, template, data.RandomString) | ||
| } | ||
|
|
||
| func (r TaskHubResource) requiresImport(data acceptance.TestData) string { | ||
| template := r.basic(data) | ||
| return fmt.Sprintf(` | ||
| %s | ||
|
|
||
| resource "azurerm_durable_task_hub" "import" { | ||
| name = azurerm_durable_task_hub.test.name | ||
| scheduler_id = azurerm_durable_task_hub.test.scheduler_id | ||
| } | ||
| `, template) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move the validate code and tests into their own validate sub-folder/package to follow the providers resource validation pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.