-
Notifications
You must be signed in to change notification settings - Fork 5k
[New Resource] azurerm_machine_learning_workspace_network_outbound_rule_service_tag
#27931
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
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
344 changes: 344 additions & 0 deletions
344
.../machinelearning/machine_learning_workspace_network_outbound_rule_service_tag_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,344 @@ | ||
| // Copyright (c) HashiCorp, Inc. | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package machinelearning | ||
|
|
||
| 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/machinelearningservices/2024-04-01/managednetwork" | ||
| "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" | ||
| "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/validation" | ||
| ) | ||
|
|
||
| var _ sdk.ResourceWithUpdate = WorkspaceNetworkOutboundRuleServiceTag{} | ||
|
|
||
| type machineLearningWorkspaceServiceTagOutboundRuleModel struct { | ||
| Name string `tfschema:"name"` | ||
| WorkspaceId string `tfschema:"workspace_id"` | ||
| ServiceTag string `tfschema:"service_tag"` | ||
| Protocol string `tfschema:"protocol"` | ||
| PortRanges string `tfschema:"port_ranges"` | ||
| } | ||
|
|
||
| type WorkspaceNetworkOutboundRuleServiceTag struct{} | ||
|
|
||
| var _ sdk.Resource = WorkspaceNetworkOutboundRuleServiceTag{} | ||
|
|
||
| func (r WorkspaceNetworkOutboundRuleServiceTag) ResourceType() string { | ||
| return "azurerm_machine_learning_workspace_network_outbound_rule_service_tag" | ||
| } | ||
|
|
||
| func (r WorkspaceNetworkOutboundRuleServiceTag) ModelObject() interface{} { | ||
| return &machineLearningWorkspaceServiceTagOutboundRuleModel{} | ||
| } | ||
|
|
||
| func (r WorkspaceNetworkOutboundRuleServiceTag) IDValidationFunc() pluginsdk.SchemaValidateFunc { | ||
| return managednetwork.ValidateOutboundRuleID | ||
| } | ||
|
|
||
| func (r WorkspaceNetworkOutboundRuleServiceTag) Arguments() map[string]*pluginsdk.Schema { | ||
| arguments := map[string]*pluginsdk.Schema{ | ||
| "name": { | ||
| Type: pluginsdk.TypeString, | ||
| Required: true, | ||
| ForceNew: true, | ||
| ValidateFunc: validation.StringIsNotEmpty, | ||
| }, | ||
|
|
||
| "workspace_id": { | ||
| Type: pluginsdk.TypeString, | ||
| Required: true, | ||
| ForceNew: true, | ||
| ValidateFunc: managednetwork.ValidateWorkspaceID, | ||
| }, | ||
|
|
||
| "service_tag": { | ||
| Type: pluginsdk.TypeString, | ||
| Required: true, | ||
| ValidateFunc: validation.StringInSlice([]string{ | ||
| "AppConfiguration", | ||
| "AppService", | ||
| "AzureActiveDirectory", | ||
| "AzureAdvancedThreatProtection", | ||
| "AzureArcInfrastructure", | ||
| "AzureAttestation", | ||
| "AzureBackup", | ||
| "AzureBotService", | ||
| "AzureContainerRegistry", | ||
| "AzureCosmosDB", | ||
| "AzureDataLake", | ||
| "AzureDevSpaces", | ||
| "AzureInformationProtection", | ||
| "AzureIoTHub", | ||
| "AzureKeyVault", | ||
| "AzureManagedGrafana", | ||
| "AzureMonitor", | ||
| "AzureOpenDatasets", | ||
| "AzurePlatformDNS", | ||
| "AzurePlatformIMDS", | ||
| "AzurePlatformLKM", | ||
| "AzureResourceManager", | ||
| "AzureSignalR", | ||
| "AzureSiteRecovery", | ||
| "AzureSpringCloud", | ||
| "AzureStack", | ||
| "AzureUpdateDelivery", | ||
| "DataFactoryManagement", | ||
| "EventHub", | ||
| "GuestAndHybridManagement", | ||
| "M365ManagementActivityApi", | ||
| "M365ManagementActivityApi", | ||
| "MicrosoftAzureFluidRelay", | ||
| "MicrosoftCloudAppSecurity", | ||
| "MicrosoftContainerRegistry", | ||
| "PowerPlatformInfra", | ||
| "ServiceBus", | ||
| "Sql", | ||
| "Storage", | ||
| "WindowsAdminCenter", | ||
| "AppServiceManagement", | ||
| "AutonomousDevelopmentPlatform", | ||
| "AzureActiveDirectoryDomainServices", | ||
| "AzureCloud", | ||
| "AzureConnectors", | ||
| "AzureContainerAppsService", | ||
| "AzureDatabricks", | ||
| "AzureDeviceUpdate", | ||
| "AzureEventGrid", | ||
| "AzureFrontDoor.Frontend", | ||
| "AzureFrontDoor.Backend", | ||
| "AzureFrontDoor.FirstParty", | ||
| "AzureHealthcareAPIs", | ||
| "AzureLoadBalancer", | ||
| "AzureMachineLearning", | ||
| "AzureSphere", | ||
| "AzureWebPubSub", | ||
| "BatchNodeManagement", | ||
| "ChaosStudio", | ||
| "CognitiveServicesFrontend", | ||
| "CognitiveServicesManagement", | ||
| "DataFactory", | ||
| "Dynamics365ForMarketingEmail", | ||
| "Dynamics365BusinessCentral", | ||
| "EOPExternalPublishedIPs", | ||
| "Internet", | ||
| "LogicApps", | ||
| "Marketplace", | ||
| "MicrosoftDefenderForEndpoint", | ||
| "PowerBI", | ||
| "PowerQueryOnline", | ||
| "ServiceFabric", | ||
| "SqlManagement", | ||
| "StorageSyncService", | ||
| "WindowsVirtualDesktop", | ||
| "VirtualNetwork", | ||
| }, false), | ||
| }, | ||
|
|
||
| "protocol": { | ||
| Type: pluginsdk.TypeString, | ||
| Required: true, | ||
| ValidateFunc: validation.StringInSlice([]string{"*", "TCP", "UDP", "ICMP"}, false), | ||
| }, | ||
|
|
||
| "port_ranges": { | ||
| Type: pluginsdk.TypeString, | ||
| Required: true, | ||
| ValidateFunc: validation.StringIsNotEmpty, | ||
| }, | ||
| } | ||
| return arguments | ||
| } | ||
|
|
||
| func (r WorkspaceNetworkOutboundRuleServiceTag) Attributes() map[string]*pluginsdk.Schema { | ||
| return map[string]*pluginsdk.Schema{} | ||
| } | ||
|
|
||
| func (r WorkspaceNetworkOutboundRuleServiceTag) Create() sdk.ResourceFunc { | ||
| return sdk.ResourceFunc{ | ||
| Timeout: 30 * time.Minute, | ||
| Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { | ||
| var model machineLearningWorkspaceServiceTagOutboundRuleModel | ||
| if err := metadata.Decode(&model); err != nil { | ||
| return fmt.Errorf("decoding: %+v", err) | ||
| } | ||
|
|
||
| client := metadata.Client.MachineLearning.ManagedNetwork | ||
| subscriptionId := metadata.Client.Account.SubscriptionId | ||
|
stephybun marked this conversation as resolved.
Outdated
|
||
|
|
||
| workspaceId, err := managednetwork.ParseWorkspaceID(model.WorkspaceId) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| id := managednetwork.NewOutboundRuleID(subscriptionId, workspaceId.ResourceGroupName, workspaceId.WorkspaceName, model.Name) | ||
| existing, err := client.SettingsRuleGet(ctx, id) | ||
| if err != nil { | ||
| if !response.WasNotFound(existing.HttpResponse) { | ||
| return fmt.Errorf("checking for presence of existing %s: %+v", id, err) | ||
| } | ||
| } | ||
| if !response.WasNotFound(existing.HttpResponse) { | ||
| return tf.ImportAsExistsError("azurerm_machine_learning_workspace_network_outbound_rule_service_tag", id.ID()) | ||
| } | ||
|
|
||
| outboundRule := managednetwork.OutboundRuleBasicResource{ | ||
| Name: pointer.To(model.Name), | ||
| Type: pointer.To(string(managednetwork.RuleTypeServiceTag)), | ||
| Properties: managednetwork.ServiceTagOutboundRule{ | ||
| Category: pointer.To(managednetwork.RuleCategoryUserDefined), | ||
| Destination: &managednetwork.ServiceTagDestination{ | ||
| PortRanges: &model.PortRanges, | ||
| Protocol: &model.Protocol, | ||
| ServiceTag: &model.ServiceTag, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| if err = client.SettingsRuleCreateOrUpdateThenPoll(ctx, id, outboundRule); err != nil { | ||
| return fmt.Errorf("creating %s: %+v", id, err) | ||
| } | ||
|
|
||
| metadata.SetID(id) | ||
| return nil | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func (r WorkspaceNetworkOutboundRuleServiceTag) Update() sdk.ResourceFunc { | ||
| return sdk.ResourceFunc{ | ||
| Timeout: 30 * time.Minute, | ||
| Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { | ||
| var model machineLearningWorkspaceServiceTagOutboundRuleModel | ||
| if err := metadata.Decode(&model); err != nil { | ||
| return fmt.Errorf("decoding: %+v", err) | ||
| } | ||
|
|
||
| client := metadata.Client.MachineLearning.ManagedNetwork | ||
|
stephybun marked this conversation as resolved.
Outdated
|
||
| id, err := managednetwork.ParseOutboundRuleID(metadata.ResourceData.Id()) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| existing, err := client.SettingsRuleGet(ctx, *id) | ||
| if err != nil { | ||
| return fmt.Errorf("retrieving %s: %+v", id, err) | ||
| } | ||
|
|
||
| if existing.Model == nil { | ||
| return fmt.Errorf("retrieving %s: `model` was nil", id) | ||
| } | ||
|
|
||
| if existing.Model.Properties == nil { | ||
| return fmt.Errorf("retrieving %s: `properties` was nil", id) | ||
| } | ||
|
|
||
| payload := existing.Model | ||
|
|
||
| serviceTagOutboundRule := managednetwork.ServiceTagOutboundRule{ | ||
| Type: managednetwork.RuleTypeServiceTag, | ||
| Category: pointer.To(managednetwork.RuleCategoryUserDefined), | ||
| Destination: &managednetwork.ServiceTagDestination{}, | ||
| } | ||
|
stephybun marked this conversation as resolved.
Outdated
|
||
|
|
||
| if metadata.ResourceData.HasChange("service_tag") { | ||
| serviceTagOutboundRule.Destination.ServiceTag = pointer.To(model.ServiceTag) | ||
| } | ||
|
|
||
| if metadata.ResourceData.HasChange("protocol") { | ||
| serviceTagOutboundRule.Destination.Protocol = pointer.To(model.Protocol) | ||
| } | ||
|
|
||
| if metadata.ResourceData.HasChange("port_ranges") { | ||
| serviceTagOutboundRule.Destination.PortRanges = pointer.To(model.PortRanges) | ||
| } | ||
|
|
||
| payload.Properties = serviceTagOutboundRule | ||
| if err := client.SettingsRuleCreateOrUpdateThenPoll(ctx, *id, *payload); err != nil { | ||
| return fmt.Errorf("updating %s: %+v", id, err) | ||
| } | ||
| return nil | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func (r WorkspaceNetworkOutboundRuleServiceTag) Read() sdk.ResourceFunc { | ||
| return sdk.ResourceFunc{ | ||
| Timeout: 5 * time.Minute, | ||
| Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { | ||
| client := metadata.Client.MachineLearning.ManagedNetwork | ||
|
|
||
| id, err := managednetwork.ParseOutboundRuleID(metadata.ResourceData.Id()) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| resp, err := client.SettingsRuleGet(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) | ||
| } | ||
|
|
||
| state := machineLearningWorkspaceServiceTagOutboundRuleModel{ | ||
| Name: id.OutboundRuleName, | ||
| } | ||
|
|
||
| if props := model.Properties; props != nil { | ||
| if prop, ok := props.(managednetwork.ServiceTagOutboundRule); ok && prop.Destination != nil { | ||
| if prop.Destination.ServiceTag != nil { | ||
| state.ServiceTag = *prop.Destination.ServiceTag | ||
| } | ||
|
|
||
| if prop.Destination.Protocol != nil { | ||
| state.Protocol = *prop.Destination.Protocol | ||
| } | ||
|
|
||
| if prop.Destination.PortRanges != nil { | ||
| state.PortRanges = *prop.Destination.PortRanges | ||
| } | ||
| } | ||
| } | ||
|
stephybun marked this conversation as resolved.
Outdated
|
||
| state.WorkspaceId = managednetwork.NewWorkspaceID(id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName).ID() | ||
| return metadata.Encode(&state) | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func (r WorkspaceNetworkOutboundRuleServiceTag) Delete() sdk.ResourceFunc { | ||
| return sdk.ResourceFunc{ | ||
| Timeout: 30 * time.Minute, | ||
| Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { | ||
| client := metadata.Client.MachineLearning.ManagedNetwork | ||
|
|
||
| id, err := managednetwork.ParseOutboundRuleID(metadata.ResourceData.Id()) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| future, err := client.SettingsRuleDelete(ctx, *id) | ||
| if err != nil { | ||
| return fmt.Errorf("deleting Machine Learning Workspace Service Tag Network Outbound Rule %q (Resource Group %q, Workspace %q): %+v", id.OutboundRuleName, id.ResourceGroupName, id.WorkspaceName, err) | ||
| } | ||
|
|
||
| if err = future.Poller.PollUntilDone(ctx); err != nil { | ||
| return fmt.Errorf("waiting for deletion of Machine Learning Workspace Service Tag Network Outbound Rule %q (Resource Group %q, Workspace %q): %+v", id.OutboundRuleName, id.ResourceGroupName, id.WorkspaceName, err) | ||
| } | ||
|
stephybun marked this conversation as resolved.
Outdated
|
||
|
|
||
| return nil | ||
| }, | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.