From 2cdcd9cdcb567c35a66deb32f53d31d89666927f Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 26 May 2021 14:23:55 +0800 Subject: [PATCH 1/9] 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/9] 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 3ba7898c3c4d71cc6287a17cf4d494631d980947 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Tue, 29 Jun 2021 17:09:35 +0800 Subject: [PATCH 3/9] update --- .../api_management_api_diagnostic_resource.go | 6 + ...management_api_diagnostic_resource_test.go | 138 +++++++++++++++++- .../apimanagement/schemaz/api_management.go | 111 ++++++++++++++ ...pi_management_api_diagnostic.html.markdown | 18 +++ 4 files changed, 272 insertions(+), 1 deletion(-) diff --git a/azurerm/internal/services/apimanagement/api_management_api_diagnostic_resource.go b/azurerm/internal/services/apimanagement/api_management_api_diagnostic_resource.go index 8a89fc0e39be..3a6fb3dd3e22 100644 --- a/azurerm/internal/services/apimanagement/api_management_api_diagnostic_resource.go +++ b/azurerm/internal/services/apimanagement/api_management_api_diagnostic_resource.go @@ -135,6 +135,7 @@ func resourceApiManagementApiDiagnosticAdditionalContentSchema() *pluginsdk.Sche }, Set: pluginsdk.HashString, }, + "data_masking": schemaz.SchemaApiManagementDataMasking(), }, }, } @@ -329,6 +330,8 @@ func expandApiManagementApiDiagnosticHTTPMessageDiagnostic(input []interface{}) result.Headers = &headers } + result.DataMasking = schemaz.ExpandApiManagementDataMasking(v["data_masking"].([]interface{})) + return result } @@ -348,6 +351,9 @@ func flattenApiManagementApiDiagnosticHTTPMessageDiagnostic(input *apimanagement if input.Headers != nil { diagnostic["headers_to_log"] = set.FromStringSlice(*input.Headers) } + + diagnostic["data_masking"] = schemaz.FlattenApiManagementDataMasking(input.DataMasking) + result = append(result, diagnostic) return result diff --git a/azurerm/internal/services/apimanagement/api_management_api_diagnostic_resource_test.go b/azurerm/internal/services/apimanagement/api_management_api_diagnostic_resource_test.go index 3baaba870917..f4ddc19f1f51 100644 --- a/azurerm/internal/services/apimanagement/api_management_api_diagnostic_resource_test.go +++ b/azurerm/internal/services/apimanagement/api_management_api_diagnostic_resource_test.go @@ -83,6 +83,28 @@ func TestAccApiManagementApiDiagnostic_complete(t *testing.T) { }) } +func TestAccApiManagementApiDiagnostic_dataMasking(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_api_management_api_diagnostic", "test") + r := ApiManagementApiDiagnosticResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.dataMaskingUpdate(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func (ApiManagementApiDiagnosticResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { id, err := parse.ApiDiagnosticID(state.ID) if err != nil { @@ -121,7 +143,7 @@ resource "azurerm_api_management" "test" { resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" - sku_name = "Developer_1" + sku_name = "Consumption_0" } resource "azurerm_api_management_logger" "test" { @@ -214,6 +236,88 @@ func (r ApiManagementApiDiagnosticResource) complete(data acceptance.TestData) s return fmt.Sprintf(` %s +resource "azurerm_api_management_api_diagnostic" "test" { + identifier = "applicationinsights" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name + api_name = azurerm_api_management_api.test.name + api_management_logger_id = azurerm_api_management_logger.test.id + sampling_percentage = 1.0 + always_log_errors = true + log_client_ip = true + http_correlation_protocol = "W3C" + verbosity = "verbose" + + backend_request { + body_bytes = 1 + headers_to_log = ["Host"] + data_masking { + query_params { + mode = "Hide" + value = "backend-Request-Test" + } + headers { + mode = "Mask" + value = "backend-Request-Header" + } + } + } + + backend_response { + body_bytes = 2 + headers_to_log = ["Content-Type"] + + data_masking { + query_params { + mode = "Mask" + value = "backend-Resp-Test" + } + } + } + + frontend_request { + body_bytes = 3 + headers_to_log = ["Accept"] + data_masking { + headers { + mode = "Mask" + value = "frontend-Request-Header" + } + } + } + + frontend_response { + body_bytes = 4 + headers_to_log = ["Content-Length"] + data_masking { + query_params { + mode = "Hide" + value = "frontend-Response-Test" + } + + query_params { + mode = "Mask" + value = "frontend-Response-Test-Alt" + } + headers { + mode = "Mask" + value = "frontend-Response-Header" + } + + headers { + mode = "Mask" + value = "frontend-Response-Header-Alt" + } + } + } +} +`, r.template(data)) +} + +func (r ApiManagementApiDiagnosticResource) dataMaskingUpdate(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + resource "azurerm_api_management_api_diagnostic" "test" { identifier = "applicationinsights" resource_group_name = azurerm_resource_group.test.name @@ -234,16 +338,48 @@ resource "azurerm_api_management_api_diagnostic" "test" { backend_response { body_bytes = 2 headers_to_log = ["Content-Type"] + data_masking { + query_params { + mode = "Hide" + value = "backend-Resp-Test-Update" + } + } } frontend_request { body_bytes = 3 headers_to_log = ["Accept"] + data_masking { + headers { + mode = "Mask" + value = "frontend-Request-Header-Update" + } + } } frontend_response { body_bytes = 4 headers_to_log = ["Content-Length"] + data_masking { + query_params { + mode = "Hide" + value = "frontend-Response-Test-Update" + } + + query_params { + mode = "Mask" + value = "frontend-Response-Test-Alt-Update" + } + + query_params { + mode = "Mask" + value = "frontend-Response-Test-Alt2-Update" + } + headers { + mode = "Mask" + value = "frontend-Response-Header-Update" + } + } } } `, r.template(data)) diff --git a/azurerm/internal/services/apimanagement/schemaz/api_management.go b/azurerm/internal/services/apimanagement/schemaz/api_management.go index 06df10b3a1d0..3efd820e1bf6 100644 --- a/azurerm/internal/services/apimanagement/schemaz/api_management.go +++ b/azurerm/internal/services/apimanagement/schemaz/api_management.go @@ -2,6 +2,7 @@ package schemaz import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/validation" "strings" "github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2020-12-01/apimanagement" @@ -317,3 +318,113 @@ func CopyCertificateAndPassword(vals []interface{}, hostName string, output map[ } } } + +func SchemaApiManagementDataMasking() *pluginsdk.Schema { + return &pluginsdk.Schema{ + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "query_params": SchemaApiManagementDataMaskingEntityList(), + + "headers": SchemaApiManagementDataMaskingEntityList(), + }, + }, + } +} + +func SchemaApiManagementDataMaskingEntityList() *pluginsdk.Schema { + return &pluginsdk.Schema{ + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "mode": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + string(apimanagement.Hide), + string(apimanagement.Mask), + }, false), + }, + + "value": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + }, + }, + } +} + +func ExpandApiManagementDataMasking(input []interface{}) *apimanagement.DataMasking { + if len(input) == 0 || input[0] == nil { + return nil + } + + inputRaw := input[0].(map[string]interface{}) + return &apimanagement.DataMasking{ + QueryParams: expandApiManagementDataMaskingEntityList(inputRaw["query_params"].([]interface{})), + Headers: expandApiManagementDataMaskingEntityList(inputRaw["headers"].([]interface{})), + } +} + +func expandApiManagementDataMaskingEntityList(input []interface{}) *[]apimanagement.DataMaskingEntity { + if len(input) == 0 || input[0] == nil { + return nil + } + + result := make([]apimanagement.DataMaskingEntity, 0) + for _, v := range input { + entity := v.(map[string]interface{}) + result = append(result, apimanagement.DataMaskingEntity{ + Mode: apimanagement.DataMaskingMode(entity["mode"].(string)), + Value: utils.String(entity["value"].(string)), + }) + } + return &result +} + +func FlattenApiManagementDataMasking(dataMasking *apimanagement.DataMasking) []interface{} { + if dataMasking == nil { + return []interface{}{} + } + + var queryParams, headers []interface{} + if dataMasking.QueryParams != nil { + queryParams = flattenApiManagementDataMaskingEntityList(dataMasking.QueryParams) + } + if dataMasking.Headers != nil { + headers = flattenApiManagementDataMaskingEntityList(dataMasking.Headers) + } + + return []interface{}{ + map[string]interface{}{ + "query_params": queryParams, + "headers": headers, + }, + } +} + +func flattenApiManagementDataMaskingEntityList(dataMaskingList *[]apimanagement.DataMaskingEntity) []interface{} { + if dataMaskingList == nil || len(*dataMaskingList) == 0 { + return []interface{}{} + } + + result := []interface{}{} + + for _, entity := range *dataMaskingList { + var value string + if entity.Value != nil { + value = *entity.Value + } + result = append(result, map[string]interface{}{ + "mode": string(entity.Mode), + "value": value, + }) + } + + return result +} diff --git a/website/docs/r/api_management_api_diagnostic.html.markdown b/website/docs/r/api_management_api_diagnostic.html.markdown index 6af509a33e8a..bccc187cd4c3 100644 --- a/website/docs/r/api_management_api_diagnostic.html.markdown +++ b/website/docs/r/api_management_api_diagnostic.html.markdown @@ -155,6 +155,24 @@ A `backend_request`, `backend_response`, `frontend_request` or `frontend_respons * `headers_to_log` - (Optional) Specifies a list of headers to log. +* `data_masking` - (Optional) A `data_masking` block as defined below. + +--- + +A `data_masking` block supports the following: + +* `query_params` - (Optional) A `query_params` block as defined below. + +* `headers` - (Optional) A `headers` block as defined below. + +--- + +A `query_params`, `headers` block supports the following: + +* `mode` - (Required) The data masking mode. Possible values are `Mask` and `Hide` for `query_params`. The only possible value is `Mask` for `headers`. + +* `value` - (Required) The name of the header or the uery parameter to mask. + ## Attributes Reference In addition to the Arguments listed above - the following Attributes are exported: From 2232902ffb6373443eb5570b49b363289e3a1185 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 30 Jun 2021 14:12:10 +0800 Subject: [PATCH 4/9] update --- .../internal/services/apimanagement/schemaz/api_management.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/apimanagement/schemaz/api_management.go b/azurerm/internal/services/apimanagement/schemaz/api_management.go index 3efd820e1bf6..8e493981bd59 100644 --- a/azurerm/internal/services/apimanagement/schemaz/api_management.go +++ b/azurerm/internal/services/apimanagement/schemaz/api_management.go @@ -2,12 +2,12 @@ package schemaz import ( "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/validation" "strings" "github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2020-12-01/apimanagement" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/apimanagement/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) From 30f6e07fefb2214d673db91ad1b3d2803622afd5 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Wed, 30 Jun 2021 14:56:02 +0800 Subject: [PATCH 5/9] update --- .../apimanagement/api_management_api_diagnostic_resource_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/azurerm/internal/services/apimanagement/api_management_api_diagnostic_resource_test.go b/azurerm/internal/services/apimanagement/api_management_api_diagnostic_resource_test.go index f4ddc19f1f51..175ca69ab6eb 100644 --- a/azurerm/internal/services/apimanagement/api_management_api_diagnostic_resource_test.go +++ b/azurerm/internal/services/apimanagement/api_management_api_diagnostic_resource_test.go @@ -266,7 +266,6 @@ resource "azurerm_api_management_api_diagnostic" "test" { backend_response { body_bytes = 2 headers_to_log = ["Content-Type"] - data_masking { query_params { mode = "Mask" From 9a54b2c3b615f6bc538cc455ad30e43b92869e45 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Fri, 9 Jul 2021 09:36:06 +0800 Subject: [PATCH 6/9] update --- .../api_management_api_diagnostic_resource.go | 112 +++++++++++++++++- .../apimanagement/schemaz/api_management.go | 111 ----------------- 2 files changed, 109 insertions(+), 114 deletions(-) diff --git a/azurerm/internal/services/apimanagement/api_management_api_diagnostic_resource.go b/azurerm/internal/services/apimanagement/api_management_api_diagnostic_resource.go index 3a6fb3dd3e22..b0345e9dd924 100644 --- a/azurerm/internal/services/apimanagement/api_management_api_diagnostic_resource.go +++ b/azurerm/internal/services/apimanagement/api_management_api_diagnostic_resource.go @@ -135,7 +135,18 @@ func resourceApiManagementApiDiagnosticAdditionalContentSchema() *pluginsdk.Sche }, Set: pluginsdk.HashString, }, - "data_masking": schemaz.SchemaApiManagementDataMasking(), + "data_masking": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "query_params": schemaApiManagementDataMaskingEntityList(), + + "headers": schemaApiManagementDataMaskingEntityList(), + }, + }, + }, }, }, } @@ -330,7 +341,7 @@ func expandApiManagementApiDiagnosticHTTPMessageDiagnostic(input []interface{}) result.Headers = &headers } - result.DataMasking = schemaz.ExpandApiManagementDataMasking(v["data_masking"].([]interface{})) + result.DataMasking = expandApiManagementDataMasking(v["data_masking"].([]interface{})) return result } @@ -352,9 +363,104 @@ func flattenApiManagementApiDiagnosticHTTPMessageDiagnostic(input *apimanagement diagnostic["headers_to_log"] = set.FromStringSlice(*input.Headers) } - diagnostic["data_masking"] = schemaz.FlattenApiManagementDataMasking(input.DataMasking) + diagnostic["data_masking"] = flattenApiManagementDataMasking(input.DataMasking) result = append(result, diagnostic) return result } + +func schemaApiManagementDataMaskingEntityList() *pluginsdk.Schema { + return &pluginsdk.Schema{ + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "mode": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + string(apimanagement.Hide), + string(apimanagement.Mask), + }, false), + }, + + "value": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + }, + }, + } +} + +func expandApiManagementDataMasking(input []interface{}) *apimanagement.DataMasking { + if len(input) == 0 || input[0] == nil { + return nil + } + + inputRaw := input[0].(map[string]interface{}) + return &apimanagement.DataMasking{ + QueryParams: expandApiManagementDataMaskingEntityList(inputRaw["query_params"].([]interface{})), + Headers: expandApiManagementDataMaskingEntityList(inputRaw["headers"].([]interface{})), + } +} + +func expandApiManagementDataMaskingEntityList(input []interface{}) *[]apimanagement.DataMaskingEntity { + if len(input) == 0 || input[0] == nil { + return nil + } + + result := make([]apimanagement.DataMaskingEntity, 0) + for _, v := range input { + entity := v.(map[string]interface{}) + result = append(result, apimanagement.DataMaskingEntity{ + Mode: apimanagement.DataMaskingMode(entity["mode"].(string)), + Value: utils.String(entity["value"].(string)), + }) + } + return &result +} + +func flattenApiManagementDataMasking(dataMasking *apimanagement.DataMasking) []interface{} { + if dataMasking == nil { + return []interface{}{} + } + + var queryParams, headers []interface{} + if dataMasking.QueryParams != nil { + queryParams = flattenApiManagementDataMaskingEntityList(dataMasking.QueryParams) + } + if dataMasking.Headers != nil { + headers = flattenApiManagementDataMaskingEntityList(dataMasking.Headers) + } + + return []interface{}{ + map[string]interface{}{ + "query_params": queryParams, + "headers": headers, + }, + } +} + +func flattenApiManagementDataMaskingEntityList(dataMaskingList *[]apimanagement.DataMaskingEntity) []interface{} { + if dataMaskingList == nil || len(*dataMaskingList) == 0 { + return []interface{}{} + } + + result := []interface{}{} + + for _, entity := range *dataMaskingList { + var value string + if entity.Value != nil { + value = *entity.Value + } + result = append(result, map[string]interface{}{ + "mode": string(entity.Mode), + "value": value, + }) + } + + return result +} diff --git a/azurerm/internal/services/apimanagement/schemaz/api_management.go b/azurerm/internal/services/apimanagement/schemaz/api_management.go index 2af3dd27905c..ac84ffe2a698 100644 --- a/azurerm/internal/services/apimanagement/schemaz/api_management.go +++ b/azurerm/internal/services/apimanagement/schemaz/api_management.go @@ -7,7 +7,6 @@ import ( "github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2020-12-01/apimanagement" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/apimanagement/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -324,113 +323,3 @@ func CopyCertificateAndPassword(vals []interface{}, hostName string, output map[ } } } - -func SchemaApiManagementDataMasking() *pluginsdk.Schema { - return &pluginsdk.Schema{ - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "query_params": SchemaApiManagementDataMaskingEntityList(), - - "headers": SchemaApiManagementDataMaskingEntityList(), - }, - }, - } -} - -func SchemaApiManagementDataMaskingEntityList() *pluginsdk.Schema { - return &pluginsdk.Schema{ - Type: pluginsdk.TypeList, - Optional: true, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "mode": { - Type: pluginsdk.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice([]string{ - string(apimanagement.Hide), - string(apimanagement.Mask), - }, false), - }, - - "value": { - Type: pluginsdk.TypeString, - Required: true, - ValidateFunc: validation.StringIsNotEmpty, - }, - }, - }, - } -} - -func ExpandApiManagementDataMasking(input []interface{}) *apimanagement.DataMasking { - if len(input) == 0 || input[0] == nil { - return nil - } - - inputRaw := input[0].(map[string]interface{}) - return &apimanagement.DataMasking{ - QueryParams: expandApiManagementDataMaskingEntityList(inputRaw["query_params"].([]interface{})), - Headers: expandApiManagementDataMaskingEntityList(inputRaw["headers"].([]interface{})), - } -} - -func expandApiManagementDataMaskingEntityList(input []interface{}) *[]apimanagement.DataMaskingEntity { - if len(input) == 0 || input[0] == nil { - return nil - } - - result := make([]apimanagement.DataMaskingEntity, 0) - for _, v := range input { - entity := v.(map[string]interface{}) - result = append(result, apimanagement.DataMaskingEntity{ - Mode: apimanagement.DataMaskingMode(entity["mode"].(string)), - Value: utils.String(entity["value"].(string)), - }) - } - return &result -} - -func FlattenApiManagementDataMasking(dataMasking *apimanagement.DataMasking) []interface{} { - if dataMasking == nil { - return []interface{}{} - } - - var queryParams, headers []interface{} - if dataMasking.QueryParams != nil { - queryParams = flattenApiManagementDataMaskingEntityList(dataMasking.QueryParams) - } - if dataMasking.Headers != nil { - headers = flattenApiManagementDataMaskingEntityList(dataMasking.Headers) - } - - return []interface{}{ - map[string]interface{}{ - "query_params": queryParams, - "headers": headers, - }, - } -} - -func flattenApiManagementDataMaskingEntityList(dataMaskingList *[]apimanagement.DataMaskingEntity) []interface{} { - if dataMaskingList == nil || len(*dataMaskingList) == 0 { - return []interface{}{} - } - - result := []interface{}{} - - for _, entity := range *dataMaskingList { - var value string - if entity.Value != nil { - value = *entity.Value - } - result = append(result, map[string]interface{}{ - "mode": string(entity.Mode), - "value": value, - }) - } - - return result -} From 1e70f990de85ff1c33588504cc46b1f2d11ced83 Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 9 Jul 2021 10:13:21 -0700 Subject: [PATCH 7/9] Update azurerm/internal/services/apimanagement/api_management_api_diagnostic_resource.go --- .../apimanagement/api_management_api_diagnostic_resource.go | 1 - 1 file changed, 1 deletion(-) diff --git a/azurerm/internal/services/apimanagement/api_management_api_diagnostic_resource.go b/azurerm/internal/services/apimanagement/api_management_api_diagnostic_resource.go index b0345e9dd924..49a0212a1ac3 100644 --- a/azurerm/internal/services/apimanagement/api_management_api_diagnostic_resource.go +++ b/azurerm/internal/services/apimanagement/api_management_api_diagnostic_resource.go @@ -142,7 +142,6 @@ func resourceApiManagementApiDiagnosticAdditionalContentSchema() *pluginsdk.Sche Elem: &pluginsdk.Resource{ Schema: map[string]*pluginsdk.Schema{ "query_params": schemaApiManagementDataMaskingEntityList(), - "headers": schemaApiManagementDataMaskingEntityList(), }, }, From 77cdd913990ee0c26f91b81f80c52e50ddf0e436 Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 9 Jul 2021 10:13:25 -0700 Subject: [PATCH 8/9] Update website/docs/r/api_management_api_diagnostic.html.markdown --- website/docs/r/api_management_api_diagnostic.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/api_management_api_diagnostic.html.markdown b/website/docs/r/api_management_api_diagnostic.html.markdown index bccc187cd4c3..dffe98d360dc 100644 --- a/website/docs/r/api_management_api_diagnostic.html.markdown +++ b/website/docs/r/api_management_api_diagnostic.html.markdown @@ -167,7 +167,7 @@ A `data_masking` block supports the following: --- -A `query_params`, `headers` block supports the following: +The `query_params` and `headers` blocks support the following: * `mode` - (Required) The data masking mode. Possible values are `Mask` and `Hide` for `query_params`. The only possible value is `Mask` for `headers`. From c58d0d94faf0d4fa7072fb1021c71e57ba4cd9d0 Mon Sep 17 00:00:00 2001 From: yupwei68 Date: Mon, 12 Jul 2021 09:44:22 +0800 Subject: [PATCH 9/9] fmt --- .../apimanagement/api_management_api_diagnostic_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/apimanagement/api_management_api_diagnostic_resource.go b/azurerm/internal/services/apimanagement/api_management_api_diagnostic_resource.go index 49a0212a1ac3..7899d689c7bc 100644 --- a/azurerm/internal/services/apimanagement/api_management_api_diagnostic_resource.go +++ b/azurerm/internal/services/apimanagement/api_management_api_diagnostic_resource.go @@ -142,7 +142,7 @@ func resourceApiManagementApiDiagnosticAdditionalContentSchema() *pluginsdk.Sche Elem: &pluginsdk.Resource{ Schema: map[string]*pluginsdk.Schema{ "query_params": schemaApiManagementDataMaskingEntityList(), - "headers": schemaApiManagementDataMaskingEntityList(), + "headers": schemaApiManagementDataMaskingEntityList(), }, }, },