-
Notifications
You must be signed in to change notification settings - Fork 5k
New resource: azurerm_managed_lustre_file_system_auto_export_job
#29908
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
base: main
Are you sure you want to change the base?
Changes from 9 commits
b75bbeb
c7425fa
7b4e382
87af82d
4e97673
16ec007
e73602e
5a17cc5
9502dc4
fa3d5f6
a7ec3ca
05a6ded
e9e0f83
57eadd4
4303806
32ea5c7
d705489
0fc76ed
bd306e8
1bce4da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,244 @@ | ||||||||||||||||||||||||||||||||||||
| package storagecache | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||||||||||||||
| "context" | ||||||||||||||||||||||||||||||||||||
| "fmt" | ||||||||||||||||||||||||||||||||||||
| "regexp" | ||||||||||||||||||||||||||||||||||||
| "time" | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| "github.com/hashicorp/go-azure-helpers/lang/pointer" | ||||||||||||||||||||||||||||||||||||
| "github.com/hashicorp/go-azure-helpers/lang/response" | ||||||||||||||||||||||||||||||||||||
| "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" | ||||||||||||||||||||||||||||||||||||
| "github.com/hashicorp/go-azure-helpers/resourcemanager/location" | ||||||||||||||||||||||||||||||||||||
| "github.com/hashicorp/go-azure-sdk/resource-manager/storagecache/2024-07-01/autoexportjob" | ||||||||||||||||||||||||||||||||||||
| "github.com/hashicorp/go-azure-sdk/resource-manager/storagecache/2024-07-01/autoexportjobs" | ||||||||||||||||||||||||||||||||||||
| "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" | ||||||||||||||||||||||||||||||||||||
| "github.com/hashicorp/terraform-provider-azurerm/internal/services/storagecache/validate" | ||||||||||||||||||||||||||||||||||||
| "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||||||||||||||||||||||||||||||||||||
| "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" | ||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| type ManagedLustreFileSystemAutoExportJobModel struct { | ||||||||||||||||||||||||||||||||||||
| Name string `tfschema:"name"` | ||||||||||||||||||||||||||||||||||||
| ResourceGroupName string `tfschema:"resource_group_name"` | ||||||||||||||||||||||||||||||||||||
| AmlFileSystemName string `tfschema:"aml_file_system_name"` | ||||||||||||||||||||||||||||||||||||
| Location string `tfschema:"location"` | ||||||||||||||||||||||||||||||||||||
| AutoExportPrefixes []string `tfschema:"auto_export_prefixes"` | ||||||||||||||||||||||||||||||||||||
| AdminStatusEnabled bool `tfschema:"admin_status_enabled"` | ||||||||||||||||||||||||||||||||||||
| Tags map[string]string `tfschema:"tags"` | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| type ManagedLustreFileSystemAutoExportJobResource struct{} | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| var _ sdk.ResourceWithUpdate = ManagedLustreFileSystemAutoExportJobResource{} | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| func (r ManagedLustreFileSystemAutoExportJobResource) Attributes() map[string]*pluginsdk.Schema { | ||||||||||||||||||||||||||||||||||||
| return map[string]*pluginsdk.Schema{} | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| func (r ManagedLustreFileSystemAutoExportJobResource) ModelObject() interface{} { | ||||||||||||||||||||||||||||||||||||
| return &ManagedLustreFileSystemAutoExportJobModel{} | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| func (r ManagedLustreFileSystemAutoExportJobResource) ResourceType() string { | ||||||||||||||||||||||||||||||||||||
| return "azurerm_managed_lustre_file_system_auto_export_job" | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| func (r ManagedLustreFileSystemAutoExportJobResource) Arguments() map[string]*pluginsdk.Schema { | ||||||||||||||||||||||||||||||||||||
| return map[string]*pluginsdk.Schema{ | ||||||||||||||||||||||||||||||||||||
| "name": { | ||||||||||||||||||||||||||||||||||||
| Type: pluginsdk.TypeString, | ||||||||||||||||||||||||||||||||||||
| Required: true, | ||||||||||||||||||||||||||||||||||||
| ForceNew: true, | ||||||||||||||||||||||||||||||||||||
| ValidateFunc: validation.StringMatch(regexp.MustCompile(`^[0-9a-zA-Z][-0-9a-zA-Z_]{0,78}[0-9a-zA-Z]$`), "name must be 3-80 characters long and can only contain alphanumeric characters, underscores, and hyphens, and must start and end with an alphanumeric character"), | ||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| "location": commonschema.Location(), | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| "resource_group_name": commonschema.ResourceGroupName(), | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| "aml_file_system_name": { | ||||||||||||||||||||||||||||||||||||
| Type: pluginsdk.TypeString, | ||||||||||||||||||||||||||||||||||||
| Required: true, | ||||||||||||||||||||||||||||||||||||
| ForceNew: true, | ||||||||||||||||||||||||||||||||||||
| ValidateFunc: validate.ManagedLustreFileSystemName, | ||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| "auto_export_prefixes": { | ||||||||||||||||||||||||||||||||||||
| Type: pluginsdk.TypeList, | ||||||||||||||||||||||||||||||||||||
| Required: true, | ||||||||||||||||||||||||||||||||||||
| MaxItems: 1, | ||||||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is Unless this is meant to be
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, this should be |
||||||||||||||||||||||||||||||||||||
| Elem: &pluginsdk.Schema{ | ||||||||||||||||||||||||||||||||||||
| Type: pluginsdk.TypeString, | ||||||||||||||||||||||||||||||||||||
| ValidateFunc: validation.StringIsNotEmpty, | ||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+60
to
+70
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Number of maximum allowed paths for now is 1, so we should enforce that in the schema. Since this is an array of
Suggested change
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will change. |
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| "admin_status_enabled": { | ||||||||||||||||||||||||||||||||||||
| Type: pluginsdk.TypeBool, | ||||||||||||||||||||||||||||||||||||
| Optional: true, | ||||||||||||||||||||||||||||||||||||
| Default: true, | ||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| "tags": commonschema.Tags(), | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| func (r ManagedLustreFileSystemAutoExportJobResource) Create() sdk.ResourceFunc { | ||||||||||||||||||||||||||||||||||||
| return sdk.ResourceFunc{ | ||||||||||||||||||||||||||||||||||||
| Timeout: 60 * time.Minute, | ||||||||||||||||||||||||||||||||||||
| Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { | ||||||||||||||||||||||||||||||||||||
| var model ManagedLustreFileSystemAutoExportJobModel | ||||||||||||||||||||||||||||||||||||
| if err := metadata.Decode(&model); err != nil { | ||||||||||||||||||||||||||||||||||||
| return fmt.Errorf("decoding model: %w", err) | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| autoExportJobsClient := metadata.Client.StorageCache.AutoExportJobs | ||||||||||||||||||||||||||||||||||||
| autoExportJobClient := metadata.Client.StorageCache.AutoExportJob | ||||||||||||||||||||||||||||||||||||
| subscriptionId := metadata.Client.Account.SubscriptionId | ||||||||||||||||||||||||||||||||||||
| id := autoexportjobs.NewAutoExportJobID(subscriptionId, model.ResourceGroupName, model.AmlFileSystemName, model.Name) | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| existing, err := autoExportJobsClient.Get(ctx, id) | ||||||||||||||||||||||||||||||||||||
| if err != nil && !response.WasNotFound(existing.HttpResponse) { | ||||||||||||||||||||||||||||||||||||
| return fmt.Errorf("checking for existing Auto Export Job %s: %+v", id, err) | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
| return fmt.Errorf("checking for existing Auto Export Job %s: %+v", id, err) | |
| return fmt.Errorf("checking for existing %s: %+v", id, err) |
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.
Will fix.
Outdated
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.
We could simplify this to:
| if props.AdminStatus != nil && string(pointer.From(props.AdminStatus)) == string(autoexportjob.AutoExportJobAdminStatusEnable) { | |
| state.AdminStatusEnabled = true | |
| } else { | |
| state.AdminStatusEnabled = false | |
| } | |
| state.AdminStatusEnabled = pointer.From(props.AdminStatus) == autoexportjobs.AutoExportJobAdminStatusEnable |
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.
Will fix.
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,148 @@ | ||||||||
| package storagecache_test | ||||||||
|
|
||||||||
| import ( | ||||||||
| "context" | ||||||||
| "fmt" | ||||||||
| "testing" | ||||||||
|
|
||||||||
| "github.com/hashicorp/go-azure-helpers/lang/pointer" | ||||||||
| "github.com/hashicorp/go-azure-helpers/lang/response" | ||||||||
| "github.com/hashicorp/go-azure-sdk/resource-manager/storagecache/2024-07-01/autoexportjobs" | ||||||||
| "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 ManagedLustreFileSystemAutoExportJobResource struct{} | ||||||||
|
|
||||||||
| func (r ManagedLustreFileSystemAutoExportJobResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { | ||||||||
| id, err := autoexportjobs.ParseAutoExportJobID(state.ID) | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add some more tests here, at least a
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do. |
||||||||
| if err != nil { | ||||||||
| return nil, err | ||||||||
| } | ||||||||
|
|
||||||||
| client := clients.StorageCache.AutoExportJobs | ||||||||
| resp, err := client.Get(ctx, *id) | ||||||||
| if err != nil { | ||||||||
| if response.WasNotFound(resp.HttpResponse) { | ||||||||
| return pointer.To(false), nil | ||||||||
| } | ||||||||
|
||||||||
| if response.WasNotFound(resp.HttpResponse) { | |
| return pointer.To(false), nil | |
| } |
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.
Will remove.
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.
Could you update this value so it's different from the value specified in the basic test?
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.
Sure.
Outdated
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.
Since this defaults to true, could you change it to false for the complete test to ensure we can update this property?
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.
Will do.
Outdated
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.
import config should match referenced config (r.basic)
| admin_status_enabled = azurerm_managed_lustre_file_system_auto_export_job.test.admin_status_enabled |
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.
Will fix.
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.
When there are multiple properties required to create the parent resource's ID, we generally expose it as a single resource ID property, e.g.
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.
Sure. Will address this.