From fee3b4f6026b30600e9ed58cf984fe37c328384a Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Tue, 31 Aug 2021 14:46:13 +0800 Subject: [PATCH 1/2] New Resource: azurerm_logic_app_integration_account_map --- internal/services/logic/client/client.go | 5 + ...ic_app_integration_account_map_resource.go | 177 ++++++++++++++++ ...p_integration_account_map_resource_test.go | 189 ++++++++++++++++++ .../logic/parse/integration_account_map.go | 75 +++++++ .../parse/integration_account_map_test.go | 128 ++++++++++++ internal/services/logic/registration.go | 1 + internal/services/logic/resourceids.go | 1 + .../integration_account_map_content.xsd | 70 +++++++ .../integration_account_map_content2.xsd | 70 +++++++ .../validate/integration_account_map_id.go | 23 +++ .../integration_account_map_id_test.go | 88 ++++++++ .../validate/integration_account_map_name.go | 30 +++ .../integration_account_map_name_test.go | 54 +++++ ..._app_integration_account_map.html.markdown | 74 +++++++ 14 files changed, 985 insertions(+) create mode 100644 internal/services/logic/logic_app_integration_account_map_resource.go create mode 100644 internal/services/logic/logic_app_integration_account_map_resource_test.go create mode 100644 internal/services/logic/parse/integration_account_map.go create mode 100644 internal/services/logic/parse/integration_account_map_test.go create mode 100644 internal/services/logic/testdata/integration_account_map_content.xsd create mode 100644 internal/services/logic/testdata/integration_account_map_content2.xsd create mode 100644 internal/services/logic/validate/integration_account_map_id.go create mode 100644 internal/services/logic/validate/integration_account_map_id_test.go create mode 100644 internal/services/logic/validate/integration_account_map_name.go create mode 100644 internal/services/logic/validate/integration_account_map_name_test.go create mode 100644 website/docs/r/logic_app_integration_account_map.html.markdown diff --git a/internal/services/logic/client/client.go b/internal/services/logic/client/client.go index 78e69712e9cc..8b862f9f912e 100644 --- a/internal/services/logic/client/client.go +++ b/internal/services/logic/client/client.go @@ -8,6 +8,7 @@ import ( type Client struct { IntegrationAccountClient *logic.IntegrationAccountsClient IntegrationAccountCertificateClient *logic.IntegrationAccountCertificatesClient + IntegrationAccountMapClient *logic.IntegrationAccountMapsClient IntegrationAccountPartnerClient *logic.IntegrationAccountPartnersClient IntegrationAccountSchemaClient *logic.IntegrationAccountSchemasClient IntegrationAccountSessionClient *logic.IntegrationAccountSessionsClient @@ -23,6 +24,9 @@ func NewClient(o *common.ClientOptions) *Client { integrationAccountCertificateClient := logic.NewIntegrationAccountCertificatesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&integrationAccountCertificateClient.Client, o.ResourceManagerAuthorizer) + integrationAccountMapClient := logic.NewIntegrationAccountMapsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) + o.ConfigureClient(&integrationAccountMapClient.Client, o.ResourceManagerAuthorizer) + integrationAccountPartnerClient := logic.NewIntegrationAccountPartnersClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&integrationAccountPartnerClient.Client, o.ResourceManagerAuthorizer) @@ -44,6 +48,7 @@ func NewClient(o *common.ClientOptions) *Client { return &Client{ IntegrationAccountClient: &integrationAccountClient, IntegrationAccountCertificateClient: &integrationAccountCertificateClient, + IntegrationAccountMapClient: &integrationAccountMapClient, IntegrationAccountPartnerClient: &integrationAccountPartnerClient, IntegrationAccountSchemaClient: &integrationAccountSchemaClient, IntegrationAccountSessionClient: &integrationAccountSessionClient, diff --git a/internal/services/logic/logic_app_integration_account_map_resource.go b/internal/services/logic/logic_app_integration_account_map_resource.go new file mode 100644 index 000000000000..a6794eca04bb --- /dev/null +++ b/internal/services/logic/logic_app_integration_account_map_resource.go @@ -0,0 +1,177 @@ +package logic + +import ( + "fmt" + "log" + "time" + + "github.com/Azure/azure-sdk-for-go/services/logic/mgmt/2019-05-01/logic" + "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" + "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" + "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/logic/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/logic/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/internal/timeouts" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +func resourceLogicAppIntegrationAccountMap() *pluginsdk.Resource { + return &pluginsdk.Resource{ + Create: resourceLogicAppIntegrationAccountMapCreateUpdate, + Read: resourceLogicAppIntegrationAccountMapRead, + Update: resourceLogicAppIntegrationAccountMapCreateUpdate, + Delete: resourceLogicAppIntegrationAccountMapDelete, + + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(30 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(30 * time.Minute), + Delete: pluginsdk.DefaultTimeout(30 * time.Minute), + }, + + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { + _, err := parse.IntegrationAccountMapID(id) + return err + }), + + Schema: map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.IntegrationAccountMapName(), + }, + + "resource_group_name": azure.SchemaResourceGroupName(), + + "integration_account_name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.IntegrationAccountName(), + }, + + "content": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "map_type": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + string(logic.MapTypeXslt), + string(logic.MapTypeXslt20), + string(logic.MapTypeXslt30), + string(logic.MapTypeLiquid), + }, false), + }, + + "metadata": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsJSON, + DiffSuppressFunc: pluginsdk.SuppressJsonDiff, + }, + }, + } +} + +func resourceLogicAppIntegrationAccountMapCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { + subscriptionId := meta.(*clients.Client).Account.SubscriptionId + client := meta.(*clients.Client).Logic.IntegrationAccountMapClient + ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + id := parse.NewIntegrationAccountMapID(subscriptionId, d.Get("resource_group_name").(string), d.Get("integration_account_name").(string), d.Get("name").(string)) + + if d.IsNewResource() { + existing, err := client.Get(ctx, id.ResourceGroup, id.IntegrationAccountName, id.MapName) + if err != nil { + if !utils.ResponseWasNotFound(existing.Response) { + return fmt.Errorf("checking for presence of existing %s: %+v", id, err) + } + } + if !utils.ResponseWasNotFound(existing.Response) { + return tf.ImportAsExistsError("azurerm_logic_app_integration_account_map", id.ID()) + } + } + + parameters := logic.IntegrationAccountMap{ + IntegrationAccountMapProperties: &logic.IntegrationAccountMapProperties{ + MapType: logic.MapType(d.Get("map_type").(string)), + Content: utils.String(d.Get("content").(string)), + ContentType: utils.String("application/xml"), + }, + } + + if v, ok := d.GetOk("metadata"); ok { + metadata, _ := pluginsdk.ExpandJsonFromString(v.(string)) + parameters.IntegrationAccountMapProperties.Metadata = metadata + } + + if _, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.IntegrationAccountName, id.MapName, parameters); err != nil { + return fmt.Errorf("creating/updating %s: %+v", id, err) + } + + d.SetId(id.ID()) + return resourceLogicAppIntegrationAccountMapRead(d, meta) +} + +func resourceLogicAppIntegrationAccountMapRead(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Logic.IntegrationAccountMapClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := parse.IntegrationAccountMapID(d.Id()) + if err != nil { + return err + } + + resp, err := client.Get(ctx, id.ResourceGroup, id.IntegrationAccountName, id.MapName) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[DEBUG] %s was not found - removing from state", *id) + d.SetId("") + return nil + } + return fmt.Errorf("retrieving %s: %+v", *id, err) + } + + d.Set("name", id.MapName) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("integration_account_name", id.IntegrationAccountName) + + if props := resp.IntegrationAccountMapProperties; props != nil { + d.Set("map_type", props.MapType) + d.Set("content", d.Get("content").(string)) + + if props.Metadata != nil { + metadataValue := props.Metadata.(map[string]interface{}) + metadataStr, _ := pluginsdk.FlattenJsonToString(metadataValue) + d.Set("metadata", metadataStr) + } + } + + return nil +} + +func resourceLogicAppIntegrationAccountMapDelete(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Logic.IntegrationAccountMapClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := parse.IntegrationAccountMapID(d.Id()) + if err != nil { + return err + } + + if _, err := client.Delete(ctx, id.ResourceGroup, id.IntegrationAccountName, id.MapName); err != nil { + return fmt.Errorf("deleting %s: %+v", id, err) + } + + return nil +} diff --git a/internal/services/logic/logic_app_integration_account_map_resource_test.go b/internal/services/logic/logic_app_integration_account_map_resource_test.go new file mode 100644 index 000000000000..70fe77a26b4e --- /dev/null +++ b/internal/services/logic/logic_app_integration_account_map_resource_test.go @@ -0,0 +1,189 @@ +package logic_test + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" + "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/logic/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +type LogicAppIntegrationAccountMapResource struct{} + +func TestAccLogicAppIntegrationAccountMap_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_logic_app_integration_account_map", "test") + r := LogicAppIntegrationAccountMapResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep("content"), // not returned from the API + }) +} + +func TestAccLogicAppIntegrationAccountMap_requiresImport(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_logic_app_integration_account_map", "test") + r := LogicAppIntegrationAccountMapResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.RequiresImportErrorStep(r.requiresImport), + }) +} + +func TestAccLogicAppIntegrationAccountMap_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_logic_app_integration_account_map", "test") + r := LogicAppIntegrationAccountMapResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.complete(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep("content"), // not returned from the API + }) +} + +func TestAccLogicAppIntegrationAccountMap_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_logic_app_integration_account_map", "test") + r := LogicAppIntegrationAccountMapResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.complete(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep("content"), // not returned from the API + { + Config: r.update(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep("content"), // not returned from the API + }) +} + +func (r LogicAppIntegrationAccountMapResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + id, err := parse.IntegrationAccountMapID(state.ID) + if err != nil { + return nil, err + } + + resp, err := client.Logic.IntegrationAccountMapClient.Get(ctx, id.ResourceGroup, id.IntegrationAccountName, id.MapName) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return utils.Bool(false), nil + } + return nil, fmt.Errorf("retrieving %q %+v", id, err) + } + + return utils.Bool(resp.IntegrationAccountMapProperties != nil), nil +} + +func (r LogicAppIntegrationAccountMapResource) template(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-logic-%d" + location = "%s" +} + +resource "azurerm_logic_app_integration_account" "test" { + name = "acctest-ia-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku_name = "Basic" +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +} + +func (r LogicAppIntegrationAccountMapResource) basic(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_logic_app_integration_account_map" "test" { + name = "acctest-iamap-%d" + resource_group_name = azurerm_resource_group.test.name + integration_account_name = azurerm_logic_app_integration_account.test.name + map_type = "Xslt" + content = file("testdata/integration_account_map_content.xsd") +} +`, r.template(data), data.RandomInteger) +} + +func (r LogicAppIntegrationAccountMapResource) requiresImport(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_logic_app_integration_account_map" "import" { + name = azurerm_logic_app_integration_account_map.test.name + resource_group_name = azurerm_logic_app_integration_account_map.test.resource_group_name + integration_account_name = azurerm_logic_app_integration_account_map.test.integration_account_name + map_type = azurerm_logic_app_integration_account_map.test.map_type + content = azurerm_logic_app_integration_account_map.test.content +} +`, r.basic(data)) +} + +func (r LogicAppIntegrationAccountMapResource) complete(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_logic_app_integration_account_map" "test" { + name = "acctest-iamap-%d" + resource_group_name = azurerm_resource_group.test.name + integration_account_name = azurerm_logic_app_integration_account.test.name + map_type = "Xslt" + content = file("testdata/integration_account_map_content.xsd") + + metadata = < + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/internal/services/logic/testdata/integration_account_map_content2.xsd b/internal/services/logic/testdata/integration_account_map_content2.xsd new file mode 100644 index 000000000000..f38ee6f44fc1 --- /dev/null +++ b/internal/services/logic/testdata/integration_account_map_content2.xsd @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/internal/services/logic/validate/integration_account_map_id.go b/internal/services/logic/validate/integration_account_map_id.go new file mode 100644 index 000000000000..85c457f37e4a --- /dev/null +++ b/internal/services/logic/validate/integration_account_map_id.go @@ -0,0 +1,23 @@ +package validate + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import ( + "fmt" + + "github.com/hashicorp/terraform-provider-azurerm/internal/services/logic/parse" +) + +func IntegrationAccountMapID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := parse.IntegrationAccountMapID(v); err != nil { + errors = append(errors, err) + } + + return +} diff --git a/internal/services/logic/validate/integration_account_map_id_test.go b/internal/services/logic/validate/integration_account_map_id_test.go new file mode 100644 index 000000000000..27f8292620c1 --- /dev/null +++ b/internal/services/logic/validate/integration_account_map_id_test.go @@ -0,0 +1,88 @@ +package validate + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import "testing" + +func TestIntegrationAccountMapID(t *testing.T) { + cases := []struct { + Input string + Valid bool + }{ + + { + // empty + Input: "", + Valid: false, + }, + + { + // missing SubscriptionId + Input: "/", + Valid: false, + }, + + { + // missing value for SubscriptionId + Input: "/subscriptions/", + Valid: false, + }, + + { + // missing ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", + Valid: false, + }, + + { + // missing value for ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", + Valid: false, + }, + + { + // missing IntegrationAccountName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Logic/", + Valid: false, + }, + + { + // missing value for IntegrationAccountName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Logic/integrationAccounts/", + Valid: false, + }, + + { + // missing MapName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Logic/integrationAccounts/account1/", + Valid: false, + }, + + { + // missing value for MapName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Logic/integrationAccounts/account1/maps/", + Valid: false, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Logic/integrationAccounts/account1/maps/map1", + Valid: true, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/GROUP1/PROVIDERS/MICROSOFT.LOGIC/INTEGRATIONACCOUNTS/ACCOUNT1/MAPS/MAP1", + Valid: false, + }, + } + for _, tc := range cases { + t.Logf("[DEBUG] Testing Value %s", tc.Input) + _, errors := IntegrationAccountMapID(tc.Input, "test") + valid := len(errors) == 0 + + if tc.Valid != valid { + t.Fatalf("Expected %t but got %t", tc.Valid, valid) + } + } +} diff --git a/internal/services/logic/validate/integration_account_map_name.go b/internal/services/logic/validate/integration_account_map_name.go new file mode 100644 index 000000000000..e0dd07d62f65 --- /dev/null +++ b/internal/services/logic/validate/integration_account_map_name.go @@ -0,0 +1,30 @@ +package validate + +import ( + "fmt" + "regexp" + + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +func IntegrationAccountMapName() pluginsdk.SchemaValidateFunc { + return func(i interface{}, k string) (warnings []string, errors []error) { + v, ok := i.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", k)) + return + } + + if len(v) > 80 { + errors = append(errors, fmt.Errorf("length should be equal to or less than %d, got %q", 80, v)) + return + } + + if !regexp.MustCompile(`^[A-Za-z0-9-().]+$`).MatchString(v) { + errors = append(errors, fmt.Errorf("%q contains only letters, numbers, dots, parentheses and hyphens", k)) + return + } + + return + } +} diff --git a/internal/services/logic/validate/integration_account_map_name_test.go b/internal/services/logic/validate/integration_account_map_name_test.go new file mode 100644 index 000000000000..d609082a8c16 --- /dev/null +++ b/internal/services/logic/validate/integration_account_map_name_test.go @@ -0,0 +1,54 @@ +package validate + +import ( + "strings" + "testing" +) + +func TestIntegrationAccountMapName(t *testing.T) { + tests := []struct { + name string + input string + valid bool + }{ + { + input: "", + valid: false, + }, + { + input: "test1", + valid: true, + }, + { + input: "a2-.()b", + valid: true, + }, + { + input: "a2&b", + valid: false, + }, + { + input: strings.Repeat("s", 79), + valid: true, + }, + { + input: strings.Repeat("s", 80), + valid: true, + }, + { + input: strings.Repeat("s", 81), + valid: false, + }, + } + + validationFunction := IntegrationAccountMapName() + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + _, err := validationFunction(tt.input, "name") + valid := err == nil + if valid != tt.valid { + t.Errorf("Expected valid status %t but got %t for input %s", tt.valid, valid, tt.input) + } + }) + } +} diff --git a/website/docs/r/logic_app_integration_account_map.html.markdown b/website/docs/r/logic_app_integration_account_map.html.markdown new file mode 100644 index 000000000000..537429fff7b6 --- /dev/null +++ b/website/docs/r/logic_app_integration_account_map.html.markdown @@ -0,0 +1,74 @@ +--- +subcategory: "Logic App" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_logic_app_integration_account_map" +description: |- + Manages a Logic App Integration Account Map. +--- + +# azurerm_logic_app_integration_account_map + +Manages a Logic App Integration Account Map. + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "example-resources" + location = "West Europe" +} + +resource "azurerm_logic_app_integration_account" "example" { + name = "example-ia" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + sku_name = "Standard" +} + +resource "azurerm_logic_app_integration_account_map" "example" { + name = "example-iamap" + resource_group_name = azurerm_resource_group.example.name + integration_account_name = azurerm_logic_app_integration_account.example.name + map_type = "Xslt" + content = file("testdata/integration_account_map_content.xsd") +} +``` + +## Arguments Reference + +The following arguments are supported: + +* `name` - (Required) The name which should be used for this Logic App Integration Account Map. Changing this forces a new Logic App Integration Account Map to be created. + +* `resource_group_name` - (Required) The name of the Resource Group where the Logic App Integration Account Map should exist. Changing this forces a new Logic App Integration Account Map to be created. + +* `integration_account_name` - (Required) The name of the Logic App Integration Account. Changing this forces a new Logic App Integration Account Map to be created. + +* `content` - (Required) The content of the Logic App Integration Account Map. + +* `map_type` - (Required) The type of the Logic App Integration Account Map. + +* `metadata` - (Optional) The metadata of the Logic App Integration Account Map. + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `id` - The ID of the Logic App Integration Account Map. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: + +* `create` - (Defaults to 30 minutes) Used when creating the Logic App Integration Account Map. +* `read` - (Defaults to 5 minutes) Used when retrieving the Logic App Integration Account Map. +* `update` - (Defaults to 30 minutes) Used when updating the Logic App Integration Account Map. +* `delete` - (Defaults to 30 minutes) Used when deleting the Logic App Integration Account Map. + +## Import + +Logic App Integration Account Maps can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_logic_app_integration_account_map.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Logic/integrationAccounts/account1/maps/map1 +``` From fa0f73d39bedfc9b58c4b1836265ae9aef461aa5 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Thu, 2 Sep 2021 14:39:45 +0800 Subject: [PATCH 2/2] update code --- ...ic_app_integration_account_map_resource.go | 19 ++++++++++--------- ...p_integration_account_map_resource_test.go | 16 ++++++---------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/internal/services/logic/logic_app_integration_account_map_resource.go b/internal/services/logic/logic_app_integration_account_map_resource.go index a6794eca04bb..874681ac20da 100644 --- a/internal/services/logic/logic_app_integration_account_map_resource.go +++ b/internal/services/logic/logic_app_integration_account_map_resource.go @@ -71,10 +71,12 @@ func resourceLogicAppIntegrationAccountMap() *pluginsdk.Resource { }, "metadata": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: validation.StringIsJSON, - DiffSuppressFunc: pluginsdk.SuppressJsonDiff, + Type: pluginsdk.TypeMap, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateFunc: validation.StringIsNotEmpty, + }, }, }, } @@ -109,8 +111,8 @@ func resourceLogicAppIntegrationAccountMapCreateUpdate(d *pluginsdk.ResourceData } if v, ok := d.GetOk("metadata"); ok { - metadata, _ := pluginsdk.ExpandJsonFromString(v.(string)) - parameters.IntegrationAccountMapProperties.Metadata = metadata + metadata := v.(map[string]interface{}) + parameters.IntegrationAccountMapProperties.Metadata = &metadata } if _, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.IntegrationAccountName, id.MapName, parameters); err != nil { @@ -150,9 +152,8 @@ func resourceLogicAppIntegrationAccountMapRead(d *pluginsdk.ResourceData, meta i d.Set("content", d.Get("content").(string)) if props.Metadata != nil { - metadataValue := props.Metadata.(map[string]interface{}) - metadataStr, _ := pluginsdk.FlattenJsonToString(metadataValue) - d.Set("metadata", metadataStr) + metadata := props.Metadata.(map[string]interface{}) + d.Set("metadata", metadata) } } diff --git a/internal/services/logic/logic_app_integration_account_map_resource_test.go b/internal/services/logic/logic_app_integration_account_map_resource_test.go index 70fe77a26b4e..893bdd66165a 100644 --- a/internal/services/logic/logic_app_integration_account_map_resource_test.go +++ b/internal/services/logic/logic_app_integration_account_map_resource_test.go @@ -159,11 +159,9 @@ resource "azurerm_logic_app_integration_account_map" "test" { map_type = "Xslt" content = file("testdata/integration_account_map_content.xsd") - metadata = <