Skip to content
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

bot_service_*_bot - support for public network access #24125

Merged
merged 4 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions internal/services/batch/batch_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func resourceBatchAccountCreate(d *pluginsdk.ResourceData, meta interface{}) err
Location: location,
Properties: &batchaccount.BatchAccountCreateProperties{
PoolAllocationMode: &poolAllocationMode,
PublicNetworkAccess: utils.ToPtr(batchaccount.PublicNetworkAccessTypeEnabled),
PublicNetworkAccess: pointer.To(batchaccount.PublicNetworkAccessTypeEnabled),
Encryption: encryption,
AllowedAuthenticationModes: expandAllowedAuthenticationModes(d.Get("allowed_authentication_modes").(*pluginsdk.Set).List()),
},
Expand All @@ -231,7 +231,7 @@ func resourceBatchAccountCreate(d *pluginsdk.ResourceData, meta interface{}) err
}

if enabled := d.Get("public_network_access_enabled").(bool); !enabled {
parameters.Properties.PublicNetworkAccess = utils.ToPtr(batchaccount.PublicNetworkAccessTypeDisabled)
parameters.Properties.PublicNetworkAccess = pointer.To(batchaccount.PublicNetworkAccessTypeDisabled)
}

if v, ok := d.GetOk("network_profile"); ok {
Expand Down Expand Up @@ -273,7 +273,7 @@ func resourceBatchAccountCreate(d *pluginsdk.ResourceData, meta interface{}) err
}
parameters.Properties.AutoStorage = &batchaccount.AutoStorageBaseProperties{
StorageAccountId: &storageAccountId,
AuthenticationMode: utils.ToPtr(batchaccount.AutoStorageAuthenticationMode(authMode)),
AuthenticationMode: pointer.To(batchaccount.AutoStorageAuthenticationMode(authMode)),
}
}

Expand Down Expand Up @@ -422,9 +422,9 @@ func resourceBatchAccountUpdate(d *pluginsdk.ResourceData, meta interface{}) err

if d.HasChange("public_network_access_enabled") {
if d.Get("public_network_access_enabled").(bool) {
parameters.Properties.PublicNetworkAccess = utils.ToPtr(batchaccount.PublicNetworkAccessTypeEnabled)
parameters.Properties.PublicNetworkAccess = pointer.To(batchaccount.PublicNetworkAccessTypeEnabled)
} else {
parameters.Properties.PublicNetworkAccess = utils.ToPtr(batchaccount.PublicNetworkAccessTypeDisabled)
parameters.Properties.PublicNetworkAccess = pointer.To(batchaccount.PublicNetworkAccessTypeDisabled)
}
}

Expand Down Expand Up @@ -453,7 +453,7 @@ func resourceBatchAccountUpdate(d *pluginsdk.ResourceData, meta interface{}) err
if storageAccountId != "" {
parameters.Properties.AutoStorage = &batchaccount.AutoStorageBaseProperties{
StorageAccountId: &storageAccountId,
AuthenticationMode: utils.ToPtr(batchaccount.AutoStorageAuthenticationMode(authMode)),
AuthenticationMode: pointer.To(batchaccount.AutoStorageAuthenticationMode(authMode)),
}
}

Expand Down Expand Up @@ -492,7 +492,7 @@ func resourceBatchAccountDelete(d *pluginsdk.ResourceData, meta interface{}) err

func expandEncryption(e []interface{}) *batchaccount.EncryptionProperties {
defaultEnc := batchaccount.EncryptionProperties{
KeySource: utils.ToPtr(batchaccount.KeySourceMicrosoftPointBatch),
KeySource: pointer.To(batchaccount.KeySourceMicrosoftPointBatch),
}

if len(e) == 0 || e[0] == nil {
Expand All @@ -502,7 +502,7 @@ func expandEncryption(e []interface{}) *batchaccount.EncryptionProperties {
v := e[0].(map[string]interface{})
keyId := v["key_vault_key_id"].(string)
encryptionProperty := batchaccount.EncryptionProperties{
KeySource: utils.ToPtr(batchaccount.KeySourceMicrosoftPointKeyVault),
KeySource: pointer.To(batchaccount.KeySourceMicrosoftPointKeyVault),
KeyVaultProperties: &batchaccount.KeyVaultProperties{
KeyIdentifier: &keyId,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ resource "azurerm_bot_service_azure_bot" "test" {
microsoft_app_id = data.azurerm_client_config.current.client_id
sku = "F0"
local_authentication_enabled = false
public_network_access_enabled = false
icon_url = "https://registry.terraform.io/images/providers/azure.png"
endpoint = "https://example.com"
developer_app_insights_api_key = azurerm_application_insights_api_key.test.api_key
Expand Down
179 changes: 103 additions & 76 deletions internal/services/bot/bot_service_resource_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ func (br botBaseResource) arguments(fields map[string]*pluginsdk.Schema) map[str
ValidateFunc: validation.StringIsNotEmpty,
},

"public_network_access_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: true,
},

"streaming_endpoint_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Expand Down Expand Up @@ -181,24 +187,30 @@ func (br botBaseResource) createFunc(resourceName, botKind string) sdk.ResourceF
displayName = id.Name
}

publicNetworkEnabled := botservice.PublicNetworkAccessEnabled
if !metadata.ResourceData.Get("public_network_access_enabled").(bool) {
publicNetworkEnabled = botservice.PublicNetworkAccessDisabled
}

props := botservice.Bot{
Location: utils.String(metadata.ResourceData.Get("location").(string)),
Sku: &botservice.Sku{
Name: botservice.SkuName(metadata.ResourceData.Get("sku").(string)),
},
Kind: botservice.Kind(botKind),
Properties: &botservice.BotProperties{
DisplayName: utils.String(displayName),
Endpoint: utils.String(metadata.ResourceData.Get("endpoint").(string)),
MsaAppID: utils.String(metadata.ResourceData.Get("microsoft_app_id").(string)),
DeveloperAppInsightKey: utils.String(metadata.ResourceData.Get("developer_app_insights_key").(string)),
DeveloperAppInsightsAPIKey: utils.String(metadata.ResourceData.Get("developer_app_insights_api_key").(string)),
DeveloperAppInsightsApplicationID: utils.String(metadata.ResourceData.Get("developer_app_insights_application_id").(string)),
DisableLocalAuth: utils.Bool(!metadata.ResourceData.Get("local_authentication_enabled").(bool)),
DisplayName: pointer.To(displayName),
Endpoint: pointer.To(metadata.ResourceData.Get("endpoint").(string)),
MsaAppID: pointer.To(metadata.ResourceData.Get("microsoft_app_id").(string)),
DeveloperAppInsightKey: pointer.To(metadata.ResourceData.Get("developer_app_insights_key").(string)),
DeveloperAppInsightsAPIKey: pointer.To(metadata.ResourceData.Get("developer_app_insights_api_key").(string)),
DeveloperAppInsightsApplicationID: pointer.To(metadata.ResourceData.Get("developer_app_insights_application_id").(string)),
DisableLocalAuth: pointer.To(!metadata.ResourceData.Get("local_authentication_enabled").(bool)),
LuisAppIds: utils.ExpandStringSlice(metadata.ResourceData.Get("luis_app_ids").([]interface{})),
LuisKey: utils.String(metadata.ResourceData.Get("luis_key").(string)),
IsStreamingSupported: utils.Bool(metadata.ResourceData.Get("streaming_endpoint_enabled").(bool)),
IconURL: utils.String(metadata.ResourceData.Get("icon_url").(string)),
LuisKey: pointer.To(metadata.ResourceData.Get("luis_key").(string)),
PublicNetworkAccess: publicNetworkEnabled,
IsStreamingSupported: pointer.To(metadata.ResourceData.Get("streaming_endpoint_enabled").(bool)),
IconURL: pointer.To(metadata.ResourceData.Get("icon_url").(string)),
},
Tags: tags.Expand(metadata.ResourceData.Get("tags").(map[string]interface{})),
}
Expand All @@ -208,11 +220,11 @@ func (br botBaseResource) createFunc(resourceName, botKind string) sdk.ResourceF
}

if v, ok := metadata.ResourceData.GetOk("microsoft_app_tenant_id"); ok {
props.Properties.MsaAppTenantID = utils.String(v.(string))
props.Properties.MsaAppTenantID = pointer.To(v.(string))
}

if v, ok := metadata.ResourceData.GetOk("microsoft_app_msi_id"); ok {
props.Properties.MsaAppMSIResourceID = utils.String(v.(string))
props.Properties.MsaAppMSIResourceID = pointer.To(v.(string))
}

if _, err := client.Create(ctx, id.ResourceGroup, id.Name, props); err != nil {
Expand All @@ -225,6 +237,79 @@ func (br botBaseResource) createFunc(resourceName, botKind string) sdk.ResourceF
}
}

func (br botBaseResource) updateFunc() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 30 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.Bot.BotClient
id, err := parse.BotServiceID(metadata.ResourceData.Id())
if err != nil {
return err
}

existing, err := client.Get(ctx, id.ResourceGroup, id.Name)
if err != nil {
return fmt.Errorf("retrieving %s: %+v", *id, err)
}

if metadata.ResourceData.HasChange("display_name") {
existing.Properties.DisplayName = utils.String(metadata.ResourceData.Get("display_name").(string))
}

if metadata.ResourceData.HasChange("endpoint") {
existing.Properties.Endpoint = utils.String(metadata.ResourceData.Get("endpoint").(string))
}

if metadata.ResourceData.HasChange("developer_app_insights_key") {
existing.Properties.DeveloperAppInsightKey = utils.String(metadata.ResourceData.Get("developer_app_insights_key").(string))
}

if metadata.ResourceData.HasChange("developer_app_insights_api_key") {
existing.Properties.DeveloperAppInsightsAPIKey = utils.String(metadata.ResourceData.Get("developer_app_insights_api_key").(string))
}

if metadata.ResourceData.HasChange("developer_app_insights_application_id") {
existing.Properties.DeveloperAppInsightsApplicationID = utils.String(metadata.ResourceData.Get("developer_app_insights_application_id").(string))
}

if metadata.ResourceData.HasChange("local_authentication_enabled") {
existing.Properties.DisableLocalAuth = utils.Bool(!metadata.ResourceData.Get("local_authentication_enabled").(bool))
}

if metadata.ResourceData.HasChange("luis_app_ids") {
existing.Properties.LuisAppIds = utils.ExpandStringSlice(metadata.ResourceData.Get("luis_app_ids").([]interface{}))
}

if metadata.ResourceData.HasChange("luis_key") {
existing.Properties.LuisKey = utils.String(metadata.ResourceData.Get("luis_key").(string))
}

if metadata.ResourceData.HasChange("public_network_access_enabled") {
if metadata.ResourceData.Get("public_network_access_enabled").(bool) {
existing.Properties.PublicNetworkAccess = botservice.PublicNetworkAccessEnabled
} else {
existing.Properties.PublicNetworkAccess = botservice.PublicNetworkAccessDisabled
}
existing.Properties.LuisKey = utils.String(metadata.ResourceData.Get("public_network_access_enabled").(string))
}

if metadata.ResourceData.HasChange("streaming_endpoint_enabled") {
existing.Properties.IsStreamingSupported = utils.Bool(metadata.ResourceData.Get("streaming_endpoint_enabled").(bool))
}

if metadata.ResourceData.HasChange("icon_url") {
existing.Properties.IconURL = utils.String(metadata.ResourceData.Get("icon_url").(string))
}

if _, err := client.Update(ctx, id.ResourceGroup, id.Name, existing); err != nil {
return fmt.Errorf("updating %s: %+v", *id, err)
}

return nil
},
}
}

func (br botBaseResource) readFunc() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 5 * time.Minute,
Expand Down Expand Up @@ -317,6 +402,12 @@ func (br botBaseResource) readFunc() sdk.ResourceFunc {
}
metadata.ResourceData.Set("local_authentication_enabled", localAuthEnabled)

publicNetworkAccessEnabled := true
if v := props.PublicNetworkAccess; v != botservice.PublicNetworkAccessDisabled {
publicNetworkAccessEnabled = false
}
metadata.ResourceData.Set("public_network_access_enabled", publicNetworkAccessEnabled)

var luisAppIds []string
if v := props.LuisAppIds; v != nil {
luisAppIds = *v
Expand Down Expand Up @@ -356,70 +447,6 @@ func (br botBaseResource) deleteFunc() sdk.ResourceFunc {
}
}

func (br botBaseResource) updateFunc() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 30 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.Bot.BotClient
id, err := parse.BotServiceID(metadata.ResourceData.Id())
if err != nil {
return err
}

existing, err := client.Get(ctx, id.ResourceGroup, id.Name)
if err != nil {
return fmt.Errorf("retrieving %s: %+v", *id, err)
}

if metadata.ResourceData.HasChange("display_name") {
existing.Properties.DisplayName = utils.String(metadata.ResourceData.Get("display_name").(string))
}

if metadata.ResourceData.HasChange("endpoint") {
existing.Properties.Endpoint = utils.String(metadata.ResourceData.Get("endpoint").(string))
}

if metadata.ResourceData.HasChange("developer_app_insights_key") {
existing.Properties.DeveloperAppInsightKey = utils.String(metadata.ResourceData.Get("developer_app_insights_key").(string))
}

if metadata.ResourceData.HasChange("developer_app_insights_api_key") {
existing.Properties.DeveloperAppInsightsAPIKey = utils.String(metadata.ResourceData.Get("developer_app_insights_api_key").(string))
}

if metadata.ResourceData.HasChange("developer_app_insights_application_id") {
existing.Properties.DeveloperAppInsightsApplicationID = utils.String(metadata.ResourceData.Get("developer_app_insights_application_id").(string))
}

if metadata.ResourceData.HasChange("local_authentication_enabled") {
existing.Properties.DisableLocalAuth = utils.Bool(!metadata.ResourceData.Get("local_authentication_enabled").(bool))
}

if metadata.ResourceData.HasChange("luis_app_ids") {
existing.Properties.LuisAppIds = utils.ExpandStringSlice(metadata.ResourceData.Get("luis_app_ids").([]interface{}))
}

if metadata.ResourceData.HasChange("luis_key") {
existing.Properties.LuisKey = utils.String(metadata.ResourceData.Get("luis_key").(string))
}

if metadata.ResourceData.HasChange("streaming_endpoint_enabled") {
existing.Properties.IsStreamingSupported = utils.Bool(metadata.ResourceData.Get("streaming_endpoint_enabled").(bool))
}

if metadata.ResourceData.HasChange("icon_url") {
existing.Properties.IconURL = utils.String(metadata.ResourceData.Get("icon_url").(string))
}

if _, err := client.Update(ctx, id.ResourceGroup, id.Name, existing); err != nil {
return fmt.Errorf("updating %s: %+v", *id, err)
}

return nil
},
}
}

func (br botBaseResource) importerFunc(expectKind string) sdk.ResourceRunFunc {
return func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.Bot.BotClient
Expand Down
4 changes: 2 additions & 2 deletions internal/services/containers/kubernetes_addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

"github.com/Azure/go-autorest/autorest/azure"
"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-04-02-preview/managedclusters"
"github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2020-08-01/workspaces"
Expand All @@ -16,7 +17,6 @@ import (
applicationGatewayValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/network/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

const (
Expand Down Expand Up @@ -358,7 +358,7 @@ func expandKubernetesAddOns(d *pluginsdk.ResourceData, input map[string]interfac
v := input["azure_policy_enabled"].(bool)
props := managedclusters.ManagedClusterAddonProfile{
Enabled: v,
Config: utils.ToPtr(map[string]string{
Config: pointer.To(map[string]string{
"version": "v2",
}),
}
Expand Down
Loading
Loading