From e466e03c0346ba582dfc5811520b9cd5252bb10b Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Thu, 2 Sep 2021 12:59:23 +0800 Subject: [PATCH 1/4] New Resource: azurerm_logic_app_integration_account_batch_configuration --- internal/services/logic/client/client.go | 37 +- ...on_account_batch_configuration_resource.go | 579 ++++++++++++++++++ ...count_batch_configuration_resource_test.go | 233 +++++++ ...integration_account_batch_configuration.go | 75 +++ ...ration_account_batch_configuration_test.go | 128 ++++ internal/services/logic/registration.go | 25 +- internal/services/logic/resourceids.go | 1 + ...batch_configuration_recurrence_timezone.go | 107 ++++ ...nt_batch_configuration_batch_group_name.go | 30 + ...tch_configuration_batch_group_name_test.go | 58 ++ ...egration_account_batch_configuration_id.go | 23 + ...ion_account_batch_configuration_id_test.go | 88 +++ ...ration_account_batch_configuration_name.go | 30 + ...n_account_batch_configuration_name_test.go | 54 ++ ..._account_batch_configuration.html.markdown | 125 ++++ 15 files changed, 1565 insertions(+), 28 deletions(-) create mode 100644 internal/services/logic/logic_app_integration_account_batch_configuration_resource.go create mode 100644 internal/services/logic/logic_app_integration_account_batch_configuration_resource_test.go create mode 100644 internal/services/logic/parse/integration_account_batch_configuration.go create mode 100644 internal/services/logic/parse/integration_account_batch_configuration_test.go create mode 100644 internal/services/logic/validate/batch_configuration_recurrence_timezone.go create mode 100644 internal/services/logic/validate/integration_account_batch_configuration_batch_group_name.go create mode 100644 internal/services/logic/validate/integration_account_batch_configuration_batch_group_name_test.go create mode 100644 internal/services/logic/validate/integration_account_batch_configuration_id.go create mode 100644 internal/services/logic/validate/integration_account_batch_configuration_id_test.go create mode 100644 internal/services/logic/validate/integration_account_batch_configuration_name.go create mode 100644 internal/services/logic/validate/integration_account_batch_configuration_name_test.go create mode 100644 website/docs/r/logic_app_integration_account_batch_configuration.html.markdown diff --git a/internal/services/logic/client/client.go b/internal/services/logic/client/client.go index 78e69712e9cc..f13a0d077859 100644 --- a/internal/services/logic/client/client.go +++ b/internal/services/logic/client/client.go @@ -6,20 +6,24 @@ import ( ) type Client struct { - IntegrationAccountClient *logic.IntegrationAccountsClient - IntegrationAccountCertificateClient *logic.IntegrationAccountCertificatesClient - IntegrationAccountPartnerClient *logic.IntegrationAccountPartnersClient - IntegrationAccountSchemaClient *logic.IntegrationAccountSchemasClient - IntegrationAccountSessionClient *logic.IntegrationAccountSessionsClient - IntegrationServiceEnvironmentClient *logic.IntegrationServiceEnvironmentsClient - WorkflowClient *logic.WorkflowsClient - TriggersClient *logic.WorkflowTriggersClient + IntegrationAccountClient *logic.IntegrationAccountsClient + IntegrationAccountBatchConfigurationClient *logic.IntegrationAccountBatchConfigurationsClient + IntegrationAccountCertificateClient *logic.IntegrationAccountCertificatesClient + IntegrationAccountPartnerClient *logic.IntegrationAccountPartnersClient + IntegrationAccountSchemaClient *logic.IntegrationAccountSchemasClient + IntegrationAccountSessionClient *logic.IntegrationAccountSessionsClient + IntegrationServiceEnvironmentClient *logic.IntegrationServiceEnvironmentsClient + WorkflowClient *logic.WorkflowsClient + TriggersClient *logic.WorkflowTriggersClient } func NewClient(o *common.ClientOptions) *Client { integrationAccountClient := logic.NewIntegrationAccountsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&integrationAccountClient.Client, o.ResourceManagerAuthorizer) + integrationAccountBatchConfigurationClient := logic.NewIntegrationAccountBatchConfigurationsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) + o.ConfigureClient(&integrationAccountBatchConfigurationClient.Client, o.ResourceManagerAuthorizer) + integrationAccountCertificateClient := logic.NewIntegrationAccountCertificatesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&integrationAccountCertificateClient.Client, o.ResourceManagerAuthorizer) @@ -42,13 +46,14 @@ func NewClient(o *common.ClientOptions) *Client { o.ConfigureClient(&triggersClient.Client, o.ResourceManagerAuthorizer) return &Client{ - IntegrationAccountClient: &integrationAccountClient, - IntegrationAccountCertificateClient: &integrationAccountCertificateClient, - IntegrationAccountPartnerClient: &integrationAccountPartnerClient, - IntegrationAccountSchemaClient: &integrationAccountSchemaClient, - IntegrationAccountSessionClient: &integrationAccountSessionClient, - IntegrationServiceEnvironmentClient: &integrationServiceEnvironmentClient, - WorkflowClient: &workflowClient, - TriggersClient: &triggersClient, + IntegrationAccountClient: &integrationAccountClient, + IntegrationAccountBatchConfigurationClient: &integrationAccountBatchConfigurationClient, + IntegrationAccountCertificateClient: &integrationAccountCertificateClient, + IntegrationAccountPartnerClient: &integrationAccountPartnerClient, + IntegrationAccountSchemaClient: &integrationAccountSchemaClient, + IntegrationAccountSessionClient: &integrationAccountSessionClient, + IntegrationServiceEnvironmentClient: &integrationServiceEnvironmentClient, + WorkflowClient: &workflowClient, + TriggersClient: &triggersClient, } } diff --git a/internal/services/logic/logic_app_integration_account_batch_configuration_resource.go b/internal/services/logic/logic_app_integration_account_batch_configuration_resource.go new file mode 100644 index 000000000000..1b0f7a8d7190 --- /dev/null +++ b/internal/services/logic/logic_app_integration_account_batch_configuration_resource.go @@ -0,0 +1,579 @@ +package logic + +import ( + "context" + "fmt" + "log" + "strings" + "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/suppress" + "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 resourceLogicAppIntegrationAccountBatchConfiguration() *pluginsdk.Resource { + return &pluginsdk.Resource{ + Create: resourceLogicAppIntegrationAccountBatchConfigurationCreateUpdate, + Read: resourceLogicAppIntegrationAccountBatchConfigurationRead, + Update: resourceLogicAppIntegrationAccountBatchConfigurationCreateUpdate, + Delete: resourceLogicAppIntegrationAccountBatchConfigurationDelete, + + 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.IntegrationAccountBatchConfigurationID(id) + return err + }), + + Schema: map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.IntegrationAccountBatchConfigurationName(), + }, + + "resource_group_name": azure.SchemaResourceGroupName(), + + "integration_account_name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.IntegrationAccountName(), + }, + + "batch_group_name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.IntegrationAccountBatchConfigurationBatchGroupName(), + }, + + "release_criteria": { + Type: pluginsdk.TypeList, + Required: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "batch_size": { + Type: pluginsdk.TypeInt, + Optional: true, + ValidateFunc: validation.IntBetween(1, 83886080), + AtLeastOneOf: []string{"release_criteria.0.batch_size", "release_criteria.0.message_count", "release_criteria.0.recurrence"}, + }, + + "message_count": { + Type: pluginsdk.TypeInt, + Optional: true, + ValidateFunc: validation.IntBetween(1, 8000), + AtLeastOneOf: []string{"release_criteria.0.batch_size", "release_criteria.0.message_count", "release_criteria.0.recurrence"}, + }, + + "recurrence": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + AtLeastOneOf: []string{"release_criteria.0.batch_size", "release_criteria.0.message_count", "release_criteria.0.recurrence"}, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "frequency": { + Type: pluginsdk.TypeString, + Required: true, + DiffSuppressFunc: suppress.CaseDifference, + ValidateFunc: validation.StringInSlice([]string{ + string(logic.RecurrenceFrequencySecond), + string(logic.RecurrenceFrequencyMinute), + string(logic.RecurrenceFrequencyHour), + string(logic.RecurrenceFrequencyDay), + string(logic.RecurrenceFrequencyWeek), + string(logic.RecurrenceFrequencyMonth), + string(logic.RecurrenceFrequencyYear), + }, true), + }, + + "interval": { + Type: pluginsdk.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween(1, 100), + }, + + "end_time": { + Type: pluginsdk.TypeString, + Optional: true, + DiffSuppressFunc: suppress.RFC3339Time, + ValidateFunc: validation.IsRFC3339Time, + }, + + "schedule": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "hours": { + Type: pluginsdk.TypeSet, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeInt, + ValidateFunc: validation.IntBetween(0, 23), + }, + }, + + "minutes": { + Type: pluginsdk.TypeSet, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeInt, + ValidateFunc: validation.IntBetween(0, 59), + }, + }, + + "month_days": { + Type: pluginsdk.TypeSet, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeInt, + ValidateFunc: validation.All( + validation.IntBetween(-31, 31), + validation.IntNotInSlice([]int{0}), + ), + }, + ConflictsWith: []string{"release_criteria.0.recurrence.0.schedule.0.week_days"}, + }, + + "monthly_occurrence": { + Type: pluginsdk.TypeSet, + Optional: true, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "day": { + Type: pluginsdk.TypeString, + Required: true, + DiffSuppressFunc: suppress.CaseDifference, + ValidateFunc: validation.StringInSlice([]string{ + string(logic.Monday), + string(logic.Tuesday), + string(logic.Wednesday), + string(logic.Thursday), + string(logic.Friday), + string(logic.Saturday), + string(logic.Sunday), + }, true), + }, + + "occurrence": { + Type: pluginsdk.TypeInt, + Required: true, + ValidateFunc: validation.All( + validation.IntBetween(-5, 5), + validation.IntNotInSlice([]int{0}), + ), + }, + }, + }, + ConflictsWith: []string{"release_criteria.0.recurrence.0.schedule.0.week_days"}, + }, + + "week_days": { + Type: pluginsdk.TypeSet, + Optional: true, + DiffSuppressFunc: suppress.CaseDifference, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateFunc: validation.StringInSlice([]string{ + string(logic.Monday), + string(logic.Tuesday), + string(logic.Wednesday), + string(logic.Thursday), + string(logic.Friday), + string(logic.Saturday), + string(logic.Sunday), + }, true), + }, + ConflictsWith: []string{"release_criteria.0.recurrence.0.schedule.0.month_days", "release_criteria.0.recurrence.0.schedule.0.monthly_occurrence"}, + }, + }, + }, + }, + + "start_time": { + Type: pluginsdk.TypeString, + Optional: true, + DiffSuppressFunc: suppress.RFC3339Time, + ValidateFunc: validation.IsRFC3339Time, + }, + + "time_zone": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validate.BatchConfigurationRecurrenceTimeZone(), + }, + }, + }, + }, + }, + }, + }, + + "metadata": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsJSON, + DiffSuppressFunc: pluginsdk.SuppressJsonDiff, + }, + }, + + CustomizeDiff: pluginsdk.CustomizeDiffShim(func(ctx context.Context, diff *pluginsdk.ResourceDiff, v interface{}) error { + frequency := strings.ToLower(diff.Get("release_criteria.0.recurrence.0.frequency").(string)) + + _, hasWeekDays := diff.GetOk("release_criteria.0.recurrence.0.schedule.0.week_days") + if hasWeekDays && frequency != "week" { + return fmt.Errorf("`week_days` can only be set when frequency is `Week`") + } + + _, hasMonthDays := diff.GetOk("release_criteria.0.recurrence.0.schedule.0.month_days") + if hasMonthDays && frequency != "month" { + return fmt.Errorf("`month_days` can only be set when frequency is `Month`") + } + + _, hasMonthlyOccurrences := diff.GetOk("release_criteria.0.recurrence.0.schedule.0.monthly_occurrence") + if hasMonthlyOccurrences && frequency != "month" { + return fmt.Errorf("`monthly_occurrence` can only be set when frequency is `Month`") + } + + return nil + }), + } +} + +func resourceLogicAppIntegrationAccountBatchConfigurationCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { + subscriptionId := meta.(*clients.Client).Account.SubscriptionId + client := meta.(*clients.Client).Logic.IntegrationAccountBatchConfigurationClient + ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + id := parse.NewIntegrationAccountBatchConfigurationID(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.BatchConfigurationName) + 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_batch_configuration", id.ID()) + } + } + + parameters := logic.BatchConfiguration{ + Properties: &logic.BatchConfigurationProperties{ + BatchGroupName: utils.String(d.Get("batch_group_name").(string)), + ReleaseCriteria: expandIntegrationAccountBatchConfigurationBatchReleaseCriteria(d.Get("release_criteria").([]interface{})), + }, + } + + if v, ok := d.GetOk("metadata"); ok { + metadata, _ := pluginsdk.ExpandJsonFromString(v.(string)) + parameters.Properties.Metadata = metadata + } + + if _, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.IntegrationAccountName, id.BatchConfigurationName, parameters); err != nil { + return fmt.Errorf("creating/updating %s: %+v", id, err) + } + + d.SetId(id.ID()) + return resourceLogicAppIntegrationAccountBatchConfigurationRead(d, meta) +} + +func resourceLogicAppIntegrationAccountBatchConfigurationRead(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Logic.IntegrationAccountBatchConfigurationClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := parse.IntegrationAccountBatchConfigurationID(d.Id()) + if err != nil { + return err + } + + resp, err := client.Get(ctx, id.ResourceGroup, id.IntegrationAccountName, id.BatchConfigurationName) + 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.BatchConfigurationName) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("integration_account_name", id.IntegrationAccountName) + + if props := resp.Properties; props != nil { + d.Set("batch_group_name", props.BatchGroupName) + + if err := d.Set("release_criteria", flattenIntegrationAccountBatchConfigurationBatchReleaseCriteria(props.ReleaseCriteria)); err != nil { + return fmt.Errorf("setting `release_criteria`: %+v", err) + } + + if props.Metadata != nil { + metadataValue := props.Metadata.(map[string]interface{}) + metadataStr, _ := pluginsdk.FlattenJsonToString(metadataValue) + d.Set("metadata", metadataStr) + } + } + + return nil +} + +func resourceLogicAppIntegrationAccountBatchConfigurationDelete(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Logic.IntegrationAccountBatchConfigurationClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := parse.IntegrationAccountBatchConfigurationID(d.Id()) + if err != nil { + return err + } + + if _, err := client.Delete(ctx, id.ResourceGroup, id.IntegrationAccountName, id.BatchConfigurationName); err != nil { + return fmt.Errorf("deleting %s: %+v", id, err) + } + + return nil +} + +func expandIntegrationAccountBatchConfigurationBatchReleaseCriteria(input []interface{}) *logic.BatchReleaseCriteria { + if len(input) == 0 { + return nil + } + v := input[0].(map[string]interface{}) + + result := logic.BatchReleaseCriteria{} + + if batchSize := v["batch_size"].(int); batchSize != 0 { + result.BatchSize = utils.Int32(int32(batchSize)) + } + + if messageCount := v["message_count"].(int); messageCount != 0 { + result.MessageCount = utils.Int32(int32(messageCount)) + } + + if recurrence := v["recurrence"].([]interface{}); len(recurrence) != 0 { + result.Recurrence = expandIntegrationAccountBatchConfigurationWorkflowTriggerRecurrence(recurrence) + } + + return &result +} + +func expandIntegrationAccountBatchConfigurationWorkflowTriggerRecurrence(input []interface{}) *logic.WorkflowTriggerRecurrence { + if len(input) == 0 { + return nil + } + v := input[0].(map[string]interface{}) + + result := logic.WorkflowTriggerRecurrence{ + Frequency: logic.RecurrenceFrequency(v["frequency"].(string)), + Interval: utils.Int32(int32(v["interval"].(int))), + } + + if startTime := v["start_time"].(string); startTime != "" { + result.StartTime = utils.String(startTime) + } + + if endTime := v["end_time"].(string); endTime != "" { + result.EndTime = utils.String(endTime) + } + + if timeZone := v["time_zone"].(string); timeZone != "" { + result.TimeZone = utils.String(timeZone) + } + + if schedule := v["schedule"].([]interface{}); len(schedule) != 0 { + result.Schedule = expandIntegrationAccountBatchConfigurationRecurrenceSchedule(schedule) + } + + return &result +} + +func expandIntegrationAccountBatchConfigurationRecurrenceSchedule(input []interface{}) *logic.RecurrenceSchedule { + if len(input) == 0 { + return nil + } + v := input[0].(map[string]interface{}) + + result := logic.RecurrenceSchedule{} + + if hours := v["hours"].(*pluginsdk.Set).List(); len(hours) != 0 { + result.Hours = utils.ExpandInt32Slice(hours) + } + + if minutes := v["minutes"].(*pluginsdk.Set).List(); len(minutes) != 0 { + result.Minutes = utils.ExpandInt32Slice(minutes) + } + + if rawWeekDays := v["week_days"].(*pluginsdk.Set).List(); len(rawWeekDays) != 0 { + weekDays := make([]logic.DaysOfWeek, 0) + for _, item := range *(utils.ExpandStringSlice(rawWeekDays)) { + weekDays = append(weekDays, (logic.DaysOfWeek)(item)) + } + result.WeekDays = &weekDays + } + + if monthDays := v["month_days"].(*pluginsdk.Set).List(); len(monthDays) != 0 { + result.MonthDays = utils.ExpandInt32Slice(monthDays) + } + + if monthlyOccurrence := v["monthly_occurrence"].(*pluginsdk.Set).List(); len(monthlyOccurrence) != 0 { + result.MonthlyOccurrences = expandIntegrationAccountBatchConfigurationRecurrenceScheduleOccurrences(monthlyOccurrence) + } + + return &result +} + +func expandIntegrationAccountBatchConfigurationRecurrenceScheduleOccurrences(input []interface{}) *[]logic.RecurrenceScheduleOccurrence { + results := make([]logic.RecurrenceScheduleOccurrence, 0) + + for _, item := range input { + v := item.(map[string]interface{}) + + results = append(results, logic.RecurrenceScheduleOccurrence{ + Day: logic.DayOfWeek(v["day"].(string)), + Occurrence: utils.Int32(int32(v["occurrence"].(int))), + }) + } + + return &results +} + +func flattenIntegrationAccountBatchConfigurationBatchReleaseCriteria(input *logic.BatchReleaseCriteria) []interface{} { + if input == nil { + return make([]interface{}, 0) + } + + var batchSize int32 + if input.BatchSize != nil { + batchSize = *input.BatchSize + } + + var messageCount int32 + if input.MessageCount != nil { + messageCount = *input.MessageCount + } + + return []interface{}{ + map[string]interface{}{ + "batch_size": batchSize, + "message_count": messageCount, + "recurrence": flattenIntegrationAccountBatchConfigurationWorkflowTriggerRecurrence(input.Recurrence), + }, + } +} + +func flattenIntegrationAccountBatchConfigurationWorkflowTriggerRecurrence(input *logic.WorkflowTriggerRecurrence) []interface{} { + if input == nil { + return make([]interface{}, 0) + } + + var endTime string + if input.EndTime != nil { + endTime = *input.EndTime + } + + var frequency logic.RecurrenceFrequency + if input.Frequency != "" { + frequency = input.Frequency + } + + var interval int32 + if input.Interval != nil { + interval = *input.Interval + } + + var startTime string + if input.StartTime != nil { + startTime = *input.StartTime + } + + var timeZone string + if input.TimeZone != nil { + timeZone = *input.TimeZone + } + + return []interface{}{ + map[string]interface{}{ + "end_time": endTime, + "frequency": frequency, + "interval": interval, + "schedule": flattenIntegrationAccountBatchConfigurationRecurrenceSchedule(input.Schedule), + "start_time": startTime, + "time_zone": timeZone, + }, + } +} + +func flattenIntegrationAccountBatchConfigurationRecurrenceSchedule(input *logic.RecurrenceSchedule) []interface{} { + if input == nil { + return make([]interface{}, 0) + } + + var weekDays []interface{} + if input.WeekDays != nil { + weekDaysCast := make([]string, 0) + for _, item := range *input.WeekDays { + weekDaysCast = append(weekDaysCast, (string)(item)) + } + weekDays = utils.FlattenStringSlice(&weekDaysCast) + } + + return []interface{}{ + map[string]interface{}{ + "hours": utils.FlattenInt32Slice(input.Hours), + "minutes": utils.FlattenInt32Slice(input.Minutes), + "month_days": utils.FlattenInt32Slice(input.MonthDays), + "monthly_occurrence": flattenIntegrationAccountBatchConfigurationRecurrenceScheduleOccurrence(input.MonthlyOccurrences), + "week_days": weekDays, + }, + } +} + +func flattenIntegrationAccountBatchConfigurationRecurrenceScheduleOccurrence(input *[]logic.RecurrenceScheduleOccurrence) []interface{} { + results := make([]interface{}, 0) + if input == nil { + return results + } + + for _, item := range *input { + var day logic.DayOfWeek + if item.Day != "" { + day = item.Day + } + + var occurrence int32 + if item.Occurrence != nil { + occurrence = *item.Occurrence + } + + results = append(results, map[string]interface{}{ + "day": day, + "occurrence": occurrence, + }) + } + + return results +} diff --git a/internal/services/logic/logic_app_integration_account_batch_configuration_resource_test.go b/internal/services/logic/logic_app_integration_account_batch_configuration_resource_test.go new file mode 100644 index 000000000000..6be06a3f21e7 --- /dev/null +++ b/internal/services/logic/logic_app_integration_account_batch_configuration_resource_test.go @@ -0,0 +1,233 @@ +package logic_test + +import ( + "context" + "fmt" + "testing" + + "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 LogicAppIntegrationAccountBatchConfigurationResource struct{} + +func TestAccLogicAppIntegrationAccountBatchConfiguration_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_logic_app_integration_account_batch_configuration", "test") + r := LogicAppIntegrationAccountBatchConfigurationResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccLogicAppIntegrationAccountBatchConfiguration_requiresImport(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_logic_app_integration_account_batch_configuration", "test") + r := LogicAppIntegrationAccountBatchConfigurationResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.RequiresImportErrorStep(r.requiresImport), + }) +} + +func TestAccLogicAppIntegrationAccountBatchConfiguration_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_logic_app_integration_account_batch_configuration", "test") + r := LogicAppIntegrationAccountBatchConfigurationResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccLogicAppIntegrationAccountBatchConfiguration_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_logic_app_integration_account_batch_configuration", "test") + r := LogicAppIntegrationAccountBatchConfigurationResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.update(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func (r LogicAppIntegrationAccountBatchConfigurationResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + id, err := parse.IntegrationAccountBatchConfigurationID(state.ID) + if err != nil { + return nil, err + } + resp, err := client.Logic.IntegrationAccountBatchConfigurationClient.Get(ctx, id.ResourceGroup, id.IntegrationAccountName, id.BatchConfigurationName) + 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.Properties != nil), nil +} + +func (r LogicAppIntegrationAccountBatchConfigurationResource) 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 = "Standard" +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +} + +func (r LogicAppIntegrationAccountBatchConfigurationResource) basic(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_logic_app_integration_account_batch_configuration" "test" { + name = "acctestiabc%s" + resource_group_name = azurerm_resource_group.test.name + integration_account_name = azurerm_logic_app_integration_account.test.name + batch_group_name = "TestBatchGroup" + + release_criteria { + message_count = 80 + } +} +`, r.template(data), data.RandomString) +} + +func (r LogicAppIntegrationAccountBatchConfigurationResource) requiresImport(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_logic_app_integration_account_batch_configuration" "import" { + name = azurerm_logic_app_integration_account_batch_configuration.test.name + resource_group_name = azurerm_logic_app_integration_account_batch_configuration.test.resource_group_name + integration_account_name = azurerm_logic_app_integration_account_batch_configuration.test.integration_account_name + batch_group_name = azurerm_logic_app_integration_account_batch_configuration.test.batch_group_name + + release_criteria { + message_count = azurerm_logic_app_integration_account_batch_configuration.test.release_criteria.0.message_count + } +} +`, r.basic(data)) +} + +func (r LogicAppIntegrationAccountBatchConfigurationResource) complete(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_logic_app_integration_account_batch_configuration" "test" { + name = "acctestiabc%s" + resource_group_name = azurerm_resource_group.test.name + integration_account_name = azurerm_logic_app_integration_account.test.name + batch_group_name = "TestBatchGroup" + + release_criteria { + batch_size = 100 + message_count = 100 + + recurrence { + frequency = "Month" + interval = 1 + start_time = "2021-09-01T01:00:00Z" + end_time = "2021-09-02T01:00:00Z" + time_zone = "Pacific Standard Time" + + schedule { + hours = [2, 3] + minutes = [4, 5] + month_days = [6, 7] + + monthly_occurrence { + day = "Monday" + occurrence = 1 + } + } + } + } + + metadata = < 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, underlines, dots, parentheses and hyphens", k)) + return + } + + return + } +} diff --git a/internal/services/logic/validate/integration_account_batch_configuration_batch_group_name_test.go b/internal/services/logic/validate/integration_account_batch_configuration_batch_group_name_test.go new file mode 100644 index 000000000000..eba54450ff10 --- /dev/null +++ b/internal/services/logic/validate/integration_account_batch_configuration_batch_group_name_test.go @@ -0,0 +1,58 @@ +package validate + +import ( + "strings" + "testing" +) + +func TestIntegrationAccountBatchConfigurationBatchGroupName(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: "a_b", + valid: true, + }, + { + input: strings.Repeat("s", 79), + valid: true, + }, + { + input: strings.Repeat("s", 80), + valid: true, + }, + { + input: strings.Repeat("s", 81), + valid: false, + }, + } + + validationFunction := IntegrationAccountBatchConfigurationBatchGroupName() + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + _, err := validationFunction(tt.input, "") + 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/internal/services/logic/validate/integration_account_batch_configuration_id.go b/internal/services/logic/validate/integration_account_batch_configuration_id.go new file mode 100644 index 000000000000..a3021852b348 --- /dev/null +++ b/internal/services/logic/validate/integration_account_batch_configuration_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 IntegrationAccountBatchConfigurationID(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.IntegrationAccountBatchConfigurationID(v); err != nil { + errors = append(errors, err) + } + + return +} diff --git a/internal/services/logic/validate/integration_account_batch_configuration_id_test.go b/internal/services/logic/validate/integration_account_batch_configuration_id_test.go new file mode 100644 index 000000000000..2ca088b9c2ae --- /dev/null +++ b/internal/services/logic/validate/integration_account_batch_configuration_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 TestIntegrationAccountBatchConfigurationID(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 BatchConfigurationName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Logic/integrationAccounts/account1/", + Valid: false, + }, + + { + // missing value for BatchConfigurationName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Logic/integrationAccounts/account1/batchConfigurations/", + Valid: false, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Logic/integrationAccounts/account1/batchConfigurations/batchConfiguration1", + Valid: true, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/GROUP1/PROVIDERS/MICROSOFT.LOGIC/INTEGRATIONACCOUNTS/ACCOUNT1/BATCHCONFIGURATIONS/BATCHCONFIGURATION1", + Valid: false, + }, + } + for _, tc := range cases { + t.Logf("[DEBUG] Testing Value %s", tc.Input) + _, errors := IntegrationAccountBatchConfigurationID(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_batch_configuration_name.go b/internal/services/logic/validate/integration_account_batch_configuration_name.go new file mode 100644 index 000000000000..f0f8136a5ec9 --- /dev/null +++ b/internal/services/logic/validate/integration_account_batch_configuration_name.go @@ -0,0 +1,30 @@ +package validate + +import ( + "fmt" + "regexp" + + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +func IntegrationAccountBatchConfigurationName() 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) > 20 { + errors = append(errors, fmt.Errorf("length should be equal to or less than %d, got %q", 20, v)) + return + } + + if !regexp.MustCompile(`^[A-Za-z0-9]+$`).MatchString(v) { + errors = append(errors, fmt.Errorf("%q contains only letters and numbers", k)) + return + } + + return + } +} diff --git a/internal/services/logic/validate/integration_account_batch_configuration_name_test.go b/internal/services/logic/validate/integration_account_batch_configuration_name_test.go new file mode 100644 index 000000000000..e2bf66d29510 --- /dev/null +++ b/internal/services/logic/validate/integration_account_batch_configuration_name_test.go @@ -0,0 +1,54 @@ +package validate + +import ( + "strings" + "testing" +) + +func TestIntegrationAccountBatchConfigurationName(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 := IntegrationAccountBatchConfigurationName() + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + _, err := validationFunction(tt.input, "") + 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_batch_configuration.html.markdown b/website/docs/r/logic_app_integration_account_batch_configuration.html.markdown new file mode 100644 index 000000000000..68424fd17a3d --- /dev/null +++ b/website/docs/r/logic_app_integration_account_batch_configuration.html.markdown @@ -0,0 +1,125 @@ +--- +subcategory: "Logic App" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_logic_app_integration_account_batch_configuration" +description: |- + Manages a Logic App Integration Account Batch Configuration. +--- + +# azurerm_logic_app_integration_account_batch_configuration + +Manages a Logic App Integration Account Batch Configuration. + +## 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_batch_configuration" "example" { + name = "example-iabc" + resource_group_name = azurerm_resource_group.example.name + integration_account_name = azurerm_logic_app_integration_account.example.name + batch_group_name = "TestBatchGroup" + + release_criteria { + message_count = 80 + } +} +``` + +## Arguments Reference + +The following arguments are supported: + +* `name` - (Required) The name which should be used for this Logic App Integration Account Batch Configuration. Changing this forces a new resource to be created. + +* `resource_group_name` - (Required) The name of the Resource Group where the Logic App Integration Account Batch Configuration should exist. Changing this forces a new resource to be created. + +* `integration_account_name` - (Required) The name of the Logic App Integration Account. Changing this forces a new resource to be created. + +* `batch_group_name` - (Required) The batch group name of the Logic App Integration Batch Configuration. Changing this forces a new resource to be created. + +* `release_criteria` - (Required) A `release_criteria` block as documented below. + +* `metadata` - (Optional) A JSON mapping of any Metadata for this Logic App Integration Account Batch Configuration. + +--- + +A `release_criteria` block exports the following: + +* `batch_size` - (Optional) The batch size in bytes for the Logic App Integration Batch Configuration. + +* `message_count` - (Optional) The message count for the Logic App Integration Batch Configuration. + +* `recurrence` - (Optional) A `recurrence` block as documented below. + +--- + +A `recurrence` block exports the following: + +* `frequency` - (Required) The frequency of the schedule. Possible values are `Day`, `Hour`, `Minute`, `Month`, `Second`, `Week` and `Year`. + +* `interval` - (Required) The number of `frequency`s between runs. + +* `end_time` - (Optional) The end time of the schedule. + +* `schedule` - (Optional) A `schedule` block as documented below. + +* `start_time` - (Optional) The start time of the schedule. + +* `time_zone` - (Optional) The timezone of the start/end time. + +--- + +A `schedule` block exports the following: + +* `hours` - (Optional) A list containing a single item, which specifies the Hour interval at which this recurrence should be triggered. + +* `minutes` - (Optional) A list containing a single item which specifies the Minute interval at which this recurrence should be triggered. + +* `month_days` - (Optional) A list of days of the month that the job should execute on. + +* `monthly_occurrence` - (Optional) A `monthly_occurrence` block as documented below. + +* `week_days` - (Optional) A list of days of the week that the job should execute on. Possible values are `Sunday`, `Monday`, `Tuesday`, `Wednesday`, `Thursday`, `Friday` and `Saturday`. + +--- + +A `monthly_occurrence` block exports the following: + +* `day` - (Required) The day of the occurrence. Possible values are `Sunday`, `Monday`, `Tuesday`, `Wednesday`, `Thursday`, `Friday` and `Saturday`. + +* `occurrence` - (Required) The occurrence of the week within the month. + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `id` - The ID of the Logic App Integration Account Batch Configuration. + +## 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 Batch Configuration. +* `read` - (Defaults to 5 minutes) Used when retrieving the Logic App Integration Account Batch Configuration. +* `update` - (Defaults to 30 minutes) Used when updating the Logic App Integration Account Batch Configuration. +* `delete` - (Defaults to 30 minutes) Used when deleting the Logic App Integration Account Batch Configuration. + +## Import + +Logic App Integration Account Batch Configurations can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_logic_app_integration_account_batch_configuration.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Logic/integrationAccounts/account1/batchConfigurations/batchConfiguration1 +``` From 46d530d289a3f5de123a6f9bcb831713be3716db Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Thu, 2 Sep 2021 13:43:11 +0800 Subject: [PATCH 2/4] update code --- ...on_account_batch_configuration_resource.go | 19 ++++++++++--------- ...count_batch_configuration_resource_test.go | 16 ++++++---------- ...n_account_batch_configuration_name_test.go | 8 ++++---- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/internal/services/logic/logic_app_integration_account_batch_configuration_resource.go b/internal/services/logic/logic_app_integration_account_batch_configuration_resource.go index 1b0f7a8d7190..2a5ffbb3b308 100644 --- a/internal/services/logic/logic_app_integration_account_batch_configuration_resource.go +++ b/internal/services/logic/logic_app_integration_account_batch_configuration_resource.go @@ -230,10 +230,12 @@ func resourceLogicAppIntegrationAccountBatchConfiguration() *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, + }, }, }, @@ -288,8 +290,8 @@ func resourceLogicAppIntegrationAccountBatchConfigurationCreateUpdate(d *plugins } if v, ok := d.GetOk("metadata"); ok { - metadata, _ := pluginsdk.ExpandJsonFromString(v.(string)) - parameters.Properties.Metadata = metadata + metadata := v.(map[string]interface{}) + parameters.Properties.Metadata = &metadata } if _, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.IntegrationAccountName, id.BatchConfigurationName, parameters); err != nil { @@ -332,9 +334,8 @@ func resourceLogicAppIntegrationAccountBatchConfigurationRead(d *pluginsdk.Resou } 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_batch_configuration_resource_test.go b/internal/services/logic/logic_app_integration_account_batch_configuration_resource_test.go index 6be06a3f21e7..8766e212e19f 100644 --- a/internal/services/logic/logic_app_integration_account_batch_configuration_resource_test.go +++ b/internal/services/logic/logic_app_integration_account_batch_configuration_resource_test.go @@ -185,11 +185,9 @@ resource "azurerm_logic_app_integration_account_batch_configuration" "test" { } } - metadata = < Date: Wed, 8 Sep 2021 15:43:44 +0800 Subject: [PATCH 3/4] update code --- ...on_account_batch_configuration_resource.go | 32 +++++++++---------- ...count_batch_configuration_resource_test.go | 6 ++-- ..._account_batch_configuration.html.markdown | 14 ++++---- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/internal/services/logic/logic_app_integration_account_batch_configuration_resource.go b/internal/services/logic/logic_app_integration_account_batch_configuration_resource.go index 2a5ffbb3b308..1d68bd289ed2 100644 --- a/internal/services/logic/logic_app_integration_account_batch_configuration_resource.go +++ b/internal/services/logic/logic_app_integration_account_batch_configuration_resource.go @@ -155,12 +155,12 @@ func resourceLogicAppIntegrationAccountBatchConfiguration() *pluginsdk.Resource ConflictsWith: []string{"release_criteria.0.recurrence.0.schedule.0.week_days"}, }, - "monthly_occurrence": { + "monthly": { Type: pluginsdk.TypeSet, Optional: true, Elem: &pluginsdk.Resource{ Schema: map[string]*pluginsdk.Schema{ - "day": { + "weekday": { Type: pluginsdk.TypeString, Required: true, DiffSuppressFunc: suppress.CaseDifference, @@ -175,7 +175,7 @@ func resourceLogicAppIntegrationAccountBatchConfiguration() *pluginsdk.Resource }, true), }, - "occurrence": { + "week": { Type: pluginsdk.TypeInt, Required: true, ValidateFunc: validation.All( @@ -204,7 +204,7 @@ func resourceLogicAppIntegrationAccountBatchConfiguration() *pluginsdk.Resource string(logic.Sunday), }, true), }, - ConflictsWith: []string{"release_criteria.0.recurrence.0.schedule.0.month_days", "release_criteria.0.recurrence.0.schedule.0.monthly_occurrence"}, + ConflictsWith: []string{"release_criteria.0.recurrence.0.schedule.0.month_days", "release_criteria.0.recurrence.0.schedule.0.monthly"}, }, }, }, @@ -252,9 +252,9 @@ func resourceLogicAppIntegrationAccountBatchConfiguration() *pluginsdk.Resource return fmt.Errorf("`month_days` can only be set when frequency is `Month`") } - _, hasMonthlyOccurrences := diff.GetOk("release_criteria.0.recurrence.0.schedule.0.monthly_occurrence") + _, hasMonthlyOccurrences := diff.GetOk("release_criteria.0.recurrence.0.schedule.0.monthly") if hasMonthlyOccurrences && frequency != "month" { - return fmt.Errorf("`monthly_occurrence` can only be set when frequency is `Month`") + return fmt.Errorf("`monthly` can only be set when frequency is `Month`") } return nil @@ -440,7 +440,7 @@ func expandIntegrationAccountBatchConfigurationRecurrenceSchedule(input []interf result.MonthDays = utils.ExpandInt32Slice(monthDays) } - if monthlyOccurrence := v["monthly_occurrence"].(*pluginsdk.Set).List(); len(monthlyOccurrence) != 0 { + if monthlyOccurrence := v["monthly"].(*pluginsdk.Set).List(); len(monthlyOccurrence) != 0 { result.MonthlyOccurrences = expandIntegrationAccountBatchConfigurationRecurrenceScheduleOccurrences(monthlyOccurrence) } @@ -454,8 +454,8 @@ func expandIntegrationAccountBatchConfigurationRecurrenceScheduleOccurrences(inp v := item.(map[string]interface{}) results = append(results, logic.RecurrenceScheduleOccurrence{ - Day: logic.DayOfWeek(v["day"].(string)), - Occurrence: utils.Int32(int32(v["occurrence"].(int))), + Day: logic.DayOfWeek(v["weekday"].(string)), + Occurrence: utils.Int32(int32(v["week"].(int))), }) } @@ -544,11 +544,11 @@ func flattenIntegrationAccountBatchConfigurationRecurrenceSchedule(input *logic. return []interface{}{ map[string]interface{}{ - "hours": utils.FlattenInt32Slice(input.Hours), - "minutes": utils.FlattenInt32Slice(input.Minutes), - "month_days": utils.FlattenInt32Slice(input.MonthDays), - "monthly_occurrence": flattenIntegrationAccountBatchConfigurationRecurrenceScheduleOccurrence(input.MonthlyOccurrences), - "week_days": weekDays, + "hours": utils.FlattenInt32Slice(input.Hours), + "minutes": utils.FlattenInt32Slice(input.Minutes), + "month_days": utils.FlattenInt32Slice(input.MonthDays), + "monthly": flattenIntegrationAccountBatchConfigurationRecurrenceScheduleOccurrence(input.MonthlyOccurrences), + "week_days": weekDays, }, } } @@ -571,8 +571,8 @@ func flattenIntegrationAccountBatchConfigurationRecurrenceScheduleOccurrence(inp } results = append(results, map[string]interface{}{ - "day": day, - "occurrence": occurrence, + "weekday": day, + "week": occurrence, }) } diff --git a/internal/services/logic/logic_app_integration_account_batch_configuration_resource_test.go b/internal/services/logic/logic_app_integration_account_batch_configuration_resource_test.go index 8766e212e19f..ffacb73d375d 100644 --- a/internal/services/logic/logic_app_integration_account_batch_configuration_resource_test.go +++ b/internal/services/logic/logic_app_integration_account_batch_configuration_resource_test.go @@ -177,9 +177,9 @@ resource "azurerm_logic_app_integration_account_batch_configuration" "test" { minutes = [4, 5] month_days = [6, 7] - monthly_occurrence { - day = "Monday" - occurrence = 1 + monthly { + weekday = "Monday" + week = 1 } } } diff --git a/website/docs/r/logic_app_integration_account_batch_configuration.html.markdown b/website/docs/r/logic_app_integration_account_batch_configuration.html.markdown index 68424fd17a3d..96dad85f9861 100644 --- a/website/docs/r/logic_app_integration_account_batch_configuration.html.markdown +++ b/website/docs/r/logic_app_integration_account_batch_configuration.html.markdown @@ -49,7 +49,7 @@ The following arguments are supported: * `batch_group_name` - (Required) The batch group name of the Logic App Integration Batch Configuration. Changing this forces a new resource to be created. -* `release_criteria` - (Required) A `release_criteria` block as documented below. +* `release_criteria` - (Required) A `release_criteria` block as documented below, which is used to select the criteria to meet before processing each batch. * `metadata` - (Optional) A JSON mapping of any Metadata for this Logic App Integration Account Batch Configuration. @@ -71,11 +71,11 @@ A `recurrence` block exports the following: * `interval` - (Required) The number of `frequency`s between runs. -* `end_time` - (Optional) The end time of the schedule. +* `end_time` - (Optional) The end time of the schedule, formatted as an RFC3339 string. * `schedule` - (Optional) A `schedule` block as documented below. -* `start_time` - (Optional) The start time of the schedule. +* `start_time` - (Optional) The start time of the schedule, formatted as an RFC3339 string. * `time_zone` - (Optional) The timezone of the start/end time. @@ -89,17 +89,17 @@ A `schedule` block exports the following: * `month_days` - (Optional) A list of days of the month that the job should execute on. -* `monthly_occurrence` - (Optional) A `monthly_occurrence` block as documented below. +* `monthly` - (Optional) A `monthly` block as documented below. * `week_days` - (Optional) A list of days of the week that the job should execute on. Possible values are `Sunday`, `Monday`, `Tuesday`, `Wednesday`, `Thursday`, `Friday` and `Saturday`. --- -A `monthly_occurrence` block exports the following: +A `monthly` block exports the following: -* `day` - (Required) The day of the occurrence. Possible values are `Sunday`, `Monday`, `Tuesday`, `Wednesday`, `Thursday`, `Friday` and `Saturday`. +* `weekday` - (Required) The day of the occurrence. Possible values are `Sunday`, `Monday`, `Tuesday`, `Wednesday`, `Thursday`, `Friday` and `Saturday`. -* `occurrence` - (Required) The occurrence of the week within the month. +* `week` - (Required) The occurrence of the week within the month. ## Attributes Reference From 5b6c81eaa8a22c27370cfebbb67d69c4e5920a18 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Wed, 8 Sep 2021 15:45:27 +0800 Subject: [PATCH 4/4] update code --- ...p_integration_account_batch_configuration_resource_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/services/logic/logic_app_integration_account_batch_configuration_resource_test.go b/internal/services/logic/logic_app_integration_account_batch_configuration_resource_test.go index ffacb73d375d..ce782b713a6a 100644 --- a/internal/services/logic/logic_app_integration_account_batch_configuration_resource_test.go +++ b/internal/services/logic/logic_app_integration_account_batch_configuration_resource_test.go @@ -178,8 +178,8 @@ resource "azurerm_logic_app_integration_account_batch_configuration" "test" { month_days = [6, 7] monthly { - weekday = "Monday" - week = 1 + weekday = "Monday" + week = 1 } } }