From 2cdcd9cdcb567c35a66deb32f53d31d89666927f Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 26 May 2021 14:23:55 +0800 Subject: [PATCH 1/8] update --- .../storage/storage_account_resource.go | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/azurerm/internal/services/storage/storage_account_resource.go b/azurerm/internal/services/storage/storage_account_resource.go index 8a41cab84efe..2882b9192109 100644 --- a/azurerm/internal/services/storage/storage_account_resource.go +++ b/azurerm/internal/services/storage/storage_account_resource.go @@ -934,6 +934,12 @@ func resourceStorageAccountCreate(d *pluginsdk.ResourceData, meta interface{}) e blobProperties := expandBlobProperties(val.([]interface{})) + if v := d.Get("blob_properties.0.last_access_time_enabled").(bool); v { + blobProperties.LastAccessTimeTrackingPolicy = &storage.LastAccessTimeTrackingPolicy{ + Enable: utils.Bool(v), + } + } + if _, err = blobClient.SetServiceProperties(ctx, resourceGroupName, storageAccountName, *blobProperties); err != nil { return fmt.Errorf("Error updating Azure Storage Account `blob_properties` %q: %+v", storageAccountName, err) } @@ -1268,6 +1274,16 @@ func resourceStorageAccountUpdate(d *pluginsdk.ResourceData, meta interface{}) e blobClient := meta.(*clients.Client).Storage.BlobServicesClient blobProperties := expandBlobProperties(d.Get("blob_properties").([]interface{})) + if d.HasChange("blob_properties.0.last_access_time_enabled") { + lastAccessTimeTracking := false + if v := d.Get("blob_properties.0.last_access_time_enabled").(bool); v { + lastAccessTimeTracking = true + } + blobProperties.LastAccessTimeTrackingPolicy = &storage.LastAccessTimeTrackingPolicy{ + Enable: utils.Bool(lastAccessTimeTracking), + } + } + if _, err = blobClient.SetServiceProperties(ctx, resourceGroupName, storageAccountName, *blobProperties); err != nil { return fmt.Errorf("Error updating Azure Storage Account `blob_properties` %q: %+v", storageAccountName, err) } @@ -1806,10 +1822,6 @@ func expandBlobProperties(input []interface{}) *storage.BlobServiceProperties { ChangeFeed: &storage.ChangeFeed{ Enabled: utils.Bool(false), }, - LastAccessTimeTrackingPolicy: &storage.LastAccessTimeTrackingPolicy{ - Enable: utils.Bool(false), - }, - DeleteRetentionPolicy: &storage.DeleteRetentionPolicy{ Enabled: utils.Bool(false), }, @@ -1839,9 +1851,6 @@ func expandBlobProperties(input []interface{}) *storage.BlobServiceProperties { props.DefaultServiceVersion = utils.String(version) } - props.LastAccessTimeTrackingPolicy = &storage.LastAccessTimeTrackingPolicy{ - Enable: utils.Bool(v["last_access_time_enabled"].(bool)), - } return &props } From 420097aea475404628519522fb8de050c7189211 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Tue, 1 Jun 2021 14:42:33 +0800 Subject: [PATCH 2/8] revert --- .../storage/storage_account_resource.go | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/azurerm/internal/services/storage/storage_account_resource.go b/azurerm/internal/services/storage/storage_account_resource.go index d2ef87926891..ba3c153654f6 100644 --- a/azurerm/internal/services/storage/storage_account_resource.go +++ b/azurerm/internal/services/storage/storage_account_resource.go @@ -933,12 +933,6 @@ func resourceStorageAccountCreate(d *pluginsdk.ResourceData, meta interface{}) e blobProperties := expandBlobProperties(val.([]interface{})) - if v := d.Get("blob_properties.0.last_access_time_enabled").(bool); v { - blobProperties.LastAccessTimeTrackingPolicy = &storage.LastAccessTimeTrackingPolicy{ - Enable: utils.Bool(v), - } - } - if _, err = blobClient.SetServiceProperties(ctx, resourceGroupName, storageAccountName, *blobProperties); err != nil { return fmt.Errorf("Error updating Azure Storage Account `blob_properties` %q: %+v", storageAccountName, err) } @@ -1273,16 +1267,6 @@ func resourceStorageAccountUpdate(d *pluginsdk.ResourceData, meta interface{}) e blobClient := meta.(*clients.Client).Storage.BlobServicesClient blobProperties := expandBlobProperties(d.Get("blob_properties").([]interface{})) - if d.HasChange("blob_properties.0.last_access_time_enabled") { - lastAccessTimeTracking := false - if v := d.Get("blob_properties.0.last_access_time_enabled").(bool); v { - lastAccessTimeTracking = true - } - blobProperties.LastAccessTimeTrackingPolicy = &storage.LastAccessTimeTrackingPolicy{ - Enable: utils.Bool(lastAccessTimeTracking), - } - } - if _, err = blobClient.SetServiceProperties(ctx, resourceGroupName, storageAccountName, *blobProperties); err != nil { return fmt.Errorf("Error updating Azure Storage Account `blob_properties` %q: %+v", storageAccountName, err) } @@ -1821,6 +1805,10 @@ func expandBlobProperties(input []interface{}) *storage.BlobServiceProperties { ChangeFeed: &storage.ChangeFeed{ Enabled: utils.Bool(false), }, + LastAccessTimeTrackingPolicy: &storage.LastAccessTimeTrackingPolicy{ + Enable: utils.Bool(false), + }, + DeleteRetentionPolicy: &storage.DeleteRetentionPolicy{ Enabled: utils.Bool(false), }, @@ -1850,6 +1838,9 @@ func expandBlobProperties(input []interface{}) *storage.BlobServiceProperties { props.DefaultServiceVersion = utils.String(version) } + props.LastAccessTimeTrackingPolicy = &storage.LastAccessTimeTrackingPolicy{ + Enable: utils.Bool(v["last_access_time_enabled"].(bool)), + } return &props } From 2ca44dbc064333f98eb4e74309632edb01e120a1 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 2 Jun 2021 10:25:33 +0800 Subject: [PATCH 3/8] update --- .../apimanagement/api_management_resource.go | 53 +++++ .../api_management_resource_test.go | 224 ++++++++++++++++++ 2 files changed, 277 insertions(+) diff --git a/azurerm/internal/services/apimanagement/api_management_resource.go b/azurerm/internal/services/apimanagement/api_management_resource.go index ebabd0de34e9..2a364ccf0e2b 100644 --- a/azurerm/internal/services/apimanagement/api_management_resource.go +++ b/azurerm/internal/services/apimanagement/api_management_resource.go @@ -151,6 +151,23 @@ func resourceApiManagementService() *pluginsdk.Resource { }, }, + "client_certificate_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + }, + + "gateway_disabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + + "min_api_version": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + "notification_sender_email": { Type: pluginsdk.TypeString, Optional: true, @@ -485,6 +502,8 @@ func resourceApiManagementService() *pluginsdk.Resource { }, }, + "zones": azure.SchemaZones(), + "gateway_url": { Type: pluginsdk.TypeString, Computed: true, @@ -626,6 +645,7 @@ func resourceApiManagementServiceCreateUpdate(d *pluginsdk.ResourceData, meta in PublisherEmail: utils.String(publisherEmail), CustomProperties: customProperties, Certificates: certificates, + DisableGateway: utils.Bool(d.Get("gateway_disabled").(bool)), }, Tags: tags.Expand(t), Sku: sku, @@ -667,6 +687,26 @@ func resourceApiManagementServiceCreateUpdate(d *pluginsdk.ResourceData, meta in } } + if d.HasChange("client_certificate_enabled") { + if sku.Name != apimanagement.SkuTypeConsumption { + return fmt.Errorf("`client_certificate_enabled` is only supported when sku type is `Consumption`") + } + properties.ServiceProperties.EnableClientCertificate = utils.Bool(d.Get("client_certificate_enabled").(bool)) + } + + if v, ok := d.GetOk("min_api_version"); ok { + properties.ServiceProperties.APIVersionConstraint = &apimanagement.APIVersionConstraint{ + MinAPIVersion: utils.String(v.(string)), + } + } + + if d.HasChange("zones") { + if sku.Name != apimanagement.SkuTypePremium { + return fmt.Errorf("`zones` is only supported when sku type is `Premium`") + } + properties.Zones = azure.ExpandZones(d.Get("zones").([]interface{})) + } + future, err := client.CreateOrUpdate(ctx, resourceGroup, name, properties) if err != nil { return fmt.Errorf("creating/updating API Management Service %q (Resource Group %q): %+v", name, resourceGroup, err) @@ -814,6 +854,7 @@ func resourceApiManagementServiceRead(d *pluginsdk.ResourceData, meta interface{ d.Set("public_ip_addresses", props.PublicIPAddresses) d.Set("private_ip_addresses", props.PrivateIPAddresses) d.Set("virtual_network_type", props.VirtualNetworkType) + d.Set("gateway_disabled", props.DisableGateway) if resp.Sku != nil && resp.Sku.Name != "" { if err := d.Set("security", flattenApiManagementSecurityCustomProperties(props.CustomProperties, resp.Sku.Name == apimanagement.SkuTypeConsumption)); err != nil { @@ -838,6 +879,14 @@ func resourceApiManagementServiceRead(d *pluginsdk.ResourceData, meta interface{ if err := d.Set("virtual_network_configuration", flattenApiManagementVirtualNetworkConfiguration(props.VirtualNetworkConfiguration)); err != nil { return fmt.Errorf("setting `virtual_network_configuration`: %+v", err) } + + if props.APIVersionConstraint != nil && props.APIVersionConstraint.MinAPIVersion != nil { + d.Set("min_api_version", props.APIVersionConstraint.MinAPIVersion) + } + + if props.EnableClientCertificate != nil { + d.Set("client_certificate_enabled", props.EnableClientCertificate) + } } if err := d.Set("sku_name", flattenApiManagementServiceSkuName(resp.Sku)); err != nil { @@ -848,6 +897,10 @@ func resourceApiManagementServiceRead(d *pluginsdk.ResourceData, meta interface{ return fmt.Errorf("setting `policy`: %+v", err) } + if resp.Zones != nil { + d.Set("zones", azure.FlattenZones(resp.Zones)) + } + if resp.Sku.Name != apimanagement.SkuTypeConsumption { signInSettings, err := signInClient.Get(ctx, resourceGroup, name) if err != nil { diff --git a/azurerm/internal/services/apimanagement/api_management_resource_test.go b/azurerm/internal/services/apimanagement/api_management_resource_test.go index e6bfeee8e709..b6791139748d 100644 --- a/azurerm/internal/services/apimanagement/api_management_resource_test.go +++ b/azurerm/internal/services/apimanagement/api_management_resource_test.go @@ -289,6 +289,85 @@ func TestAccApiManagement_consumption(t *testing.T) { ), }, data.ImportStep(), + { + Config: r.consumptionClientCertificateEnabled(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.consumptionClientCertificateDisabled(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccApiManagement_gatewayDiabled(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_api_management", "test") + r := ApiManagementResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.consumptionMultipleLocations(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.consumptionGatewayDiabled(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.consumptionMultipleLocations(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccApiManagement_minApiVersion(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_api_management", "test") + r := ApiManagementResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.consumption(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.consumptionMinApiVersion(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.consumptionMinApiVersionUpdate(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.consumption(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), }) } @@ -872,6 +951,8 @@ resource "azurerm_api_management" "test" { sku_name = "Premium_1" + zones = [1, 2] + tags = { "Acceptance" = "Test" } @@ -1329,6 +1410,149 @@ resource "azurerm_api_management" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } +func (ApiManagementResource) consumptionMultipleLocations(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_api_management" "test" { + name = "acctestAM-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + publisher_name = "pub1" + publisher_email = "pub1@email.com" + sku_name = "Consumption_0" + additional_location { + location = "%s" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Secondary) +} + +func (ApiManagementResource) consumptionClientCertificateEnabled(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_api_management" "test" { + name = "acctestAM-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + publisher_name = "pub1" + publisher_email = "pub1@email.com" + sku_name = "Consumption_0" + client_certificate_enabled = true +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +} + +func (ApiManagementResource) consumptionClientCertificateDisabled(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_api_management" "test" { + name = "acctestAM-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + publisher_name = "pub1" + publisher_email = "pub1@email.com" + sku_name = "Consumption_0" + client_certificate_enabled = false +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +} + +func (ApiManagementResource) consumptionGatewayDiabled(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_api_management" "test" { + name = "acctestAM-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + publisher_name = "pub1" + publisher_email = "pub1@email.com" + sku_name = "Consumption_0" + gateway_disabled = true + additional_location { + location = "%s" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Secondary) +} + +func (ApiManagementResource) consumptionMinApiVersion(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_api_management" "test" { + name = "acctestAM-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + publisher_name = "pub1" + publisher_email = "pub1@email.com" + sku_name = "Consumption_0" + min_api_version = "2019-12-01" +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +} + +func (ApiManagementResource) consumptionMinApiVersionUpdate(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_api_management" "test" { + name = "acctestAM-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + publisher_name = "pub1" + publisher_email = "pub1@email.com" + sku_name = "Consumption_0" + min_api_version = "2020-12-01" +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +} + func (ApiManagementResource) tenantAccess(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { From bbb371eae196a41b3a0abba050ae2f071dcc1511 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 9 Jun 2021 10:29:08 +0800 Subject: [PATCH 4/8] update --- .../apimanagement/api_management_resource.go | 4 +- .../api_management_resource_test.go | 69 +++++++++++-------- 2 files changed, 45 insertions(+), 28 deletions(-) diff --git a/azurerm/internal/services/apimanagement/api_management_resource.go b/azurerm/internal/services/apimanagement/api_management_resource.go index 2a364ccf0e2b..590f7b00f978 100644 --- a/azurerm/internal/services/apimanagement/api_management_resource.go +++ b/azurerm/internal/services/apimanagement/api_management_resource.go @@ -880,9 +880,11 @@ func resourceApiManagementServiceRead(d *pluginsdk.ResourceData, meta interface{ return fmt.Errorf("setting `virtual_network_configuration`: %+v", err) } + var minApiVersion string if props.APIVersionConstraint != nil && props.APIVersionConstraint.MinAPIVersion != nil { - d.Set("min_api_version", props.APIVersionConstraint.MinAPIVersion) + minApiVersion = *props.APIVersionConstraint.MinAPIVersion } + d.Set("min_api_version", minApiVersion) if props.EnableClientCertificate != nil { d.Set("client_certificate_enabled", props.EnableClientCertificate) diff --git a/azurerm/internal/services/apimanagement/api_management_resource_test.go b/azurerm/internal/services/apimanagement/api_management_resource_test.go index f0f3447e8a39..6e8a843641c9 100644 --- a/azurerm/internal/services/apimanagement/api_management_resource_test.go +++ b/azurerm/internal/services/apimanagement/api_management_resource_test.go @@ -281,6 +281,21 @@ func TestAccApiManagement_consumption(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_api_management", "test") r := ApiManagementResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.consumption(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccApiManagement_clientCertificate(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_api_management", "test") + r := ApiManagementResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.consumption(data), @@ -312,21 +327,21 @@ func TestAccApiManagement_gatewayDiabled(t *testing.T) { data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.consumptionMultipleLocations(data), + Config: r.multipleLocations(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { - Config: r.consumptionGatewayDiabled(data), + Config: r.gatewayDiabled(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { - Config: r.consumptionMultipleLocations(data), + Config: r.multipleLocations(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), @@ -1502,7 +1517,7 @@ resource "azurerm_api_management" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func (ApiManagementResource) consumptionMultipleLocations(data acceptance.TestData) string { +func (ApiManagementResource) consumptionClientCertificateEnabled(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -1514,20 +1529,18 @@ resource "azurerm_resource_group" "test" { } resource "azurerm_api_management" "test" { - name = "acctestAM-%d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - publisher_name = "pub1" - publisher_email = "pub1@email.com" - sku_name = "Consumption_0" - additional_location { - location = "%s" - } + name = "acctestAM-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + publisher_name = "pub1" + publisher_email = "pub1@email.com" + sku_name = "Consumption_0" + client_certificate_enabled = true } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Secondary) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func (ApiManagementResource) consumptionClientCertificateEnabled(data acceptance.TestData) string { +func (ApiManagementResource) consumptionClientCertificateDisabled(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -1545,12 +1558,12 @@ resource "azurerm_api_management" "test" { publisher_name = "pub1" publisher_email = "pub1@email.com" sku_name = "Consumption_0" - client_certificate_enabled = true + client_certificate_enabled = false } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func (ApiManagementResource) consumptionClientCertificateDisabled(data acceptance.TestData) string { +func (ApiManagementResource) multipleLocations(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -1562,18 +1575,20 @@ resource "azurerm_resource_group" "test" { } resource "azurerm_api_management" "test" { - name = "acctestAM-%d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - publisher_name = "pub1" - publisher_email = "pub1@email.com" - sku_name = "Consumption_0" - client_certificate_enabled = false + name = "acctestAM-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + publisher_name = "pub1" + publisher_email = "pub1@email.com" + sku_name = "Premium_1" + additional_location { + location = "%s" + } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Secondary) } -func (ApiManagementResource) consumptionGatewayDiabled(data acceptance.TestData) string { +func (ApiManagementResource) gatewayDiabled(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -1590,7 +1605,7 @@ resource "azurerm_api_management" "test" { resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" - sku_name = "Consumption_0" + sku_name = "Premium_1" gateway_disabled = true additional_location { location = "%s" From 94763544104f2a44ff8d079be170af481e022e71 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 9 Jun 2021 11:35:03 +0800 Subject: [PATCH 5/8] update --- .../services/apimanagement/api_management_resource.go | 8 +++++++- .../apimanagement/api_management_resource_test.go | 4 ++-- website/docs/r/api_management.html.markdown | 8 ++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/azurerm/internal/services/apimanagement/api_management_resource.go b/azurerm/internal/services/apimanagement/api_management_resource.go index 590f7b00f978..f315ab13db36 100644 --- a/azurerm/internal/services/apimanagement/api_management_resource.go +++ b/azurerm/internal/services/apimanagement/api_management_resource.go @@ -645,7 +645,6 @@ func resourceApiManagementServiceCreateUpdate(d *pluginsdk.ResourceData, meta in PublisherEmail: utils.String(publisherEmail), CustomProperties: customProperties, Certificates: certificates, - DisableGateway: utils.Bool(d.Get("gateway_disabled").(bool)), }, Tags: tags.Expand(t), Sku: sku, @@ -694,6 +693,13 @@ func resourceApiManagementServiceCreateUpdate(d *pluginsdk.ResourceData, meta in properties.ServiceProperties.EnableClientCertificate = utils.Bool(d.Get("client_certificate_enabled").(bool)) } + if d.HasChange("gateway_disabled") { + if len(*properties.AdditionalLocations) == 0 { + return fmt.Errorf("`gateway_disabled` is only supported when `additional_location` is set") + } + properties.ServiceProperties.DisableGateway = utils.Bool(d.Get("gateway_disabled").(bool)) + } + if v, ok := d.GetOk("min_api_version"); ok { properties.ServiceProperties.APIVersionConstraint = &apimanagement.APIVersionConstraint{ MinAPIVersion: utils.String(v.(string)), diff --git a/azurerm/internal/services/apimanagement/api_management_resource_test.go b/azurerm/internal/services/apimanagement/api_management_resource_test.go index 6e8a843641c9..4e62d3ac4bb5 100644 --- a/azurerm/internal/services/apimanagement/api_management_resource_test.go +++ b/azurerm/internal/services/apimanagement/api_management_resource_test.go @@ -964,9 +964,9 @@ resource "azurerm_api_management" "test" { } } - sku_name = "Premium_1" + sku_name = "Premium_2" - zones = [1, 2] + zones = [1,2] tags = { "Acceptance" = "Test" diff --git a/website/docs/r/api_management.html.markdown b/website/docs/r/api_management.html.markdown index 6d922697e920..0ae6e79e998d 100644 --- a/website/docs/r/api_management.html.markdown +++ b/website/docs/r/api_management.html.markdown @@ -67,6 +67,14 @@ The following arguments are supported: * `certificate` - (Optional) One or more (up to 10) `certificate` blocks as defined below. +* `client_certificate_enabled` - (Optional) Enforce a client certificate to be presented on each request to the gateway? This is only supported when sku type is `Consumption`. + +* `gateway_disabled` - (Optional) Disable the gateway in master region? This is only supported when `additional_location` is set. + +* `min_api_version` - (Optional) The version which the control plane API calls to API Management service are limited with version equal to or newer than. + +* `zones` - (Optional) A list of availability zones. + * `identity` - (Optional) An `identity` block is documented below. * `hostname_configuration` - (Optional) A `hostname_configuration` block as defined below. From 8494854ed79d4ce81734df8dad343c13b6bcf529 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 9 Jun 2021 14:18:16 +0800 Subject: [PATCH 6/8] update --- .../apimanagement/api_management_resource.go | 22 ++++++++----------- .../api_management_resource_test.go | 2 +- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/azurerm/internal/services/apimanagement/api_management_resource.go b/azurerm/internal/services/apimanagement/api_management_resource.go index f315ab13db36..b0da40c59f8b 100644 --- a/azurerm/internal/services/apimanagement/api_management_resource.go +++ b/azurerm/internal/services/apimanagement/api_management_resource.go @@ -154,6 +154,7 @@ func resourceApiManagementService() *pluginsdk.Resource { "client_certificate_enabled": { Type: pluginsdk.TypeBool, Optional: true, + Default: false, }, "gateway_disabled": { @@ -686,18 +687,18 @@ func resourceApiManagementServiceCreateUpdate(d *pluginsdk.ResourceData, meta in } } - if d.HasChange("client_certificate_enabled") { + if v := d.Get("client_certificate_enabled").(bool); v { if sku.Name != apimanagement.SkuTypeConsumption { return fmt.Errorf("`client_certificate_enabled` is only supported when sku type is `Consumption`") } - properties.ServiceProperties.EnableClientCertificate = utils.Bool(d.Get("client_certificate_enabled").(bool)) + properties.ServiceProperties.EnableClientCertificate = utils.Bool(v) } - if d.HasChange("gateway_disabled") { + if v := d.Get("gateway_disabled").(bool); v { if len(*properties.AdditionalLocations) == 0 { return fmt.Errorf("`gateway_disabled` is only supported when `additional_location` is set") } - properties.ServiceProperties.DisableGateway = utils.Bool(d.Get("gateway_disabled").(bool)) + properties.ServiceProperties.DisableGateway = utils.Bool(v) } if v, ok := d.GetOk("min_api_version"); ok { @@ -706,11 +707,11 @@ func resourceApiManagementServiceCreateUpdate(d *pluginsdk.ResourceData, meta in } } - if d.HasChange("zones") { + if v := d.Get("zones").([]interface{}); len(v) > 0 { if sku.Name != apimanagement.SkuTypePremium { return fmt.Errorf("`zones` is only supported when sku type is `Premium`") } - properties.Zones = azure.ExpandZones(d.Get("zones").([]interface{})) + properties.Zones = azure.ExpandZones(v) } future, err := client.CreateOrUpdate(ctx, resourceGroup, name, properties) @@ -860,6 +861,7 @@ func resourceApiManagementServiceRead(d *pluginsdk.ResourceData, meta interface{ d.Set("public_ip_addresses", props.PublicIPAddresses) d.Set("private_ip_addresses", props.PrivateIPAddresses) d.Set("virtual_network_type", props.VirtualNetworkType) + d.Set("client_certificate_enabled", props.EnableClientCertificate) d.Set("gateway_disabled", props.DisableGateway) if resp.Sku != nil && resp.Sku.Name != "" { @@ -891,10 +893,6 @@ func resourceApiManagementServiceRead(d *pluginsdk.ResourceData, meta interface{ minApiVersion = *props.APIVersionConstraint.MinAPIVersion } d.Set("min_api_version", minApiVersion) - - if props.EnableClientCertificate != nil { - d.Set("client_certificate_enabled", props.EnableClientCertificate) - } } if err := d.Set("sku_name", flattenApiManagementServiceSkuName(resp.Sku)); err != nil { @@ -905,9 +903,7 @@ func resourceApiManagementServiceRead(d *pluginsdk.ResourceData, meta interface{ return fmt.Errorf("setting `policy`: %+v", err) } - if resp.Zones != nil { - d.Set("zones", azure.FlattenZones(resp.Zones)) - } + d.Set("zones", azure.FlattenZones(resp.Zones)) if resp.Sku.Name != apimanagement.SkuTypeConsumption { signInSettings, err := signInClient.Get(ctx, resourceGroup, name) diff --git a/azurerm/internal/services/apimanagement/api_management_resource_test.go b/azurerm/internal/services/apimanagement/api_management_resource_test.go index 4e62d3ac4bb5..2041499fd32d 100644 --- a/azurerm/internal/services/apimanagement/api_management_resource_test.go +++ b/azurerm/internal/services/apimanagement/api_management_resource_test.go @@ -966,7 +966,7 @@ resource "azurerm_api_management" "test" { sku_name = "Premium_2" - zones = [1,2] + zones = [1, 2] tags = { "Acceptance" = "Test" From 1a122f7a0822aaf2f80b94448ac96522c9ca6135 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 9 Jun 2021 16:11:55 +0800 Subject: [PATCH 7/8] update --- .../apimanagement/api_management_resource.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/azurerm/internal/services/apimanagement/api_management_resource.go b/azurerm/internal/services/apimanagement/api_management_resource.go index b0da40c59f8b..7bdda8820189 100644 --- a/azurerm/internal/services/apimanagement/api_management_resource.go +++ b/azurerm/internal/services/apimanagement/api_management_resource.go @@ -687,19 +687,17 @@ func resourceApiManagementServiceCreateUpdate(d *pluginsdk.ResourceData, meta in } } - if v := d.Get("client_certificate_enabled").(bool); v { - if sku.Name != apimanagement.SkuTypeConsumption { - return fmt.Errorf("`client_certificate_enabled` is only supported when sku type is `Consumption`") - } - properties.ServiceProperties.EnableClientCertificate = utils.Bool(v) + enableClientCertificate := d.Get("client_certificate_enabled").(bool) + if enableClientCertificate && sku.Name != apimanagement.SkuTypeConsumption { + return fmt.Errorf("`client_certificate_enabled` is only supported when sku type is `Consumption`") } + properties.ServiceProperties.EnableClientCertificate = utils.Bool(enableClientCertificate) - if v := d.Get("gateway_disabled").(bool); v { - if len(*properties.AdditionalLocations) == 0 { - return fmt.Errorf("`gateway_disabled` is only supported when `additional_location` is set") - } - properties.ServiceProperties.DisableGateway = utils.Bool(v) + gateWayDisabled := d.Get("gateway_disabled").(bool) + if gateWayDisabled && len(*properties.AdditionalLocations) == 0 { + return fmt.Errorf("`gateway_disabled` is only supported when `additional_location` is set") } + properties.ServiceProperties.DisableGateway = utils.Bool(gateWayDisabled) if v, ok := d.GetOk("min_api_version"); ok { properties.ServiceProperties.APIVersionConstraint = &apimanagement.APIVersionConstraint{ From 84dd922fd17f93b2da89931243c3905de9510108 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 9 Jun 2021 16:21:11 +0800 Subject: [PATCH 8/8] update --- .../services/apimanagement/api_management_resource.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/azurerm/internal/services/apimanagement/api_management_resource.go b/azurerm/internal/services/apimanagement/api_management_resource.go index 7bdda8820189..c45e90551649 100644 --- a/azurerm/internal/services/apimanagement/api_management_resource.go +++ b/azurerm/internal/services/apimanagement/api_management_resource.go @@ -687,11 +687,13 @@ func resourceApiManagementServiceCreateUpdate(d *pluginsdk.ResourceData, meta in } } - enableClientCertificate := d.Get("client_certificate_enabled").(bool) - if enableClientCertificate && sku.Name != apimanagement.SkuTypeConsumption { - return fmt.Errorf("`client_certificate_enabled` is only supported when sku type is `Consumption`") + if d.HasChange("client_certificate_enabled") { + enableClientCertificate := d.Get("client_certificate_enabled").(bool) + if enableClientCertificate && sku.Name != apimanagement.SkuTypeConsumption { + return fmt.Errorf("`client_certificate_enabled` is only supported when sku type is `Consumption`") + } + properties.ServiceProperties.EnableClientCertificate = utils.Bool(enableClientCertificate) } - properties.ServiceProperties.EnableClientCertificate = utils.Bool(enableClientCertificate) gateWayDisabled := d.Get("gateway_disabled").(bool) if gateWayDisabled && len(*properties.AdditionalLocations) == 0 {