Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_logic_app_workflow - support for enabled & access_control #13265

Merged
merged 9 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
226 changes: 226 additions & 0 deletions internal/services/logic/logic_app_workflow_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,99 @@ func resourceLogicAppWorkflow() *pluginsdk.Resource {
ValidateFunc: validate.IntegrationServiceEnvironmentID,
},

"access_control": {
Type: pluginsdk.TypeList,
Optional: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"action": {
Type: pluginsdk.TypeList,
Optional: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"allowed_caller_ip_address_range": {
Type: pluginsdk.TypeSet,
Required: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
ValidateFunc: validation.Any(
validation.IsCIDR,
validation.IsIPv4Range,
),
},
},
},
},
},

"content": {
Type: pluginsdk.TypeList,
Optional: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"allowed_caller_ip_address_range": {
Type: pluginsdk.TypeSet,
Required: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
ValidateFunc: validation.Any(
validation.IsCIDR,
validation.IsIPv4Range,
),
},
},
},
},
},

"trigger": {
Type: pluginsdk.TypeList,
Optional: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"allowed_caller_ip_address_range": {
Type: pluginsdk.TypeSet,
Required: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
ValidateFunc: validation.Any(
validation.IsCIDR,
validation.IsIPv4Range,
),
},
},
},
},
},

"workflow_management": {
Type: pluginsdk.TypeList,
Optional: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"allowed_caller_ip_address_range": {
Type: pluginsdk.TypeSet,
Required: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
ValidateFunc: validation.Any(
validation.IsCIDR,
validation.IsIPv4Range,
),
},
},
},
},
},
},
},
},

"logic_app_integration_account_id": {
Type: pluginsdk.TypeString,
Optional: true,
Expand All @@ -79,6 +172,12 @@ func resourceLogicAppWorkflow() *pluginsdk.Resource {
},
},

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

"workflow_schema": {
Type: pluginsdk.TypeString,
Optional: true,
Expand Down Expand Up @@ -170,6 +269,11 @@ func resourceLogicAppWorkflowCreate(d *pluginsdk.ResourceData, meta interface{})
}
t := d.Get("tags").(map[string]interface{})

isEnabled := logic.WorkflowStateEnabled
if v := d.Get("enabled").(bool); !v {
isEnabled = logic.WorkflowStateDisabled
}

properties := logic.Workflow{
Location: utils.String(location),
WorkflowProperties: &logic.WorkflowProperties{
Expand All @@ -181,10 +285,15 @@ func resourceLogicAppWorkflowCreate(d *pluginsdk.ResourceData, meta interface{})
"parameters": workflowParameters,
},
Parameters: parameters,
State: isEnabled,
},
Tags: tags.Expand(t),
}

if v, ok := d.GetOk("access_control"); ok {
properties.WorkflowProperties.AccessControl = expandLogicAppWorkflowAccessControl(v.([]interface{}))
}

if iseID, ok := d.GetOk("integration_service_environment_id"); ok {
properties.WorkflowProperties.IntegrationServiceEnvironment = &logic.ResourceReference{
ID: utils.String(iseID.(string)),
Expand Down Expand Up @@ -260,15 +369,25 @@ func resourceLogicAppWorkflowUpdate(d *pluginsdk.ResourceData, meta interface{})
definition := read.WorkflowProperties.Definition.(map[string]interface{})
definition["parameters"] = workflowParameters

isEnabled := logic.WorkflowStateEnabled
if v := d.Get("enabled").(bool); !v {
isEnabled = logic.WorkflowStateDisabled
}

properties := logic.Workflow{
Location: utils.String(location),
WorkflowProperties: &logic.WorkflowProperties{
Definition: definition,
Parameters: parameters,
State: isEnabled,
},
Tags: tags.Expand(t),
}

if v, ok := d.GetOk("access_control"); ok {
properties.WorkflowProperties.AccessControl = expandLogicAppWorkflowAccessControl(v.([]interface{}))
}

if v, ok := d.GetOk("logic_app_integration_account_id"); ok {
properties.WorkflowProperties.IntegrationAccount = &logic.ResourceReference{
ID: utils.String(v.(string)),
Expand Down Expand Up @@ -314,6 +433,14 @@ func resourceLogicAppWorkflowRead(d *pluginsdk.ResourceData, meta interface{}) e
if props := resp.WorkflowProperties; props != nil {
d.Set("access_endpoint", props.AccessEndpoint)

if err := d.Set("access_control", flattenLogicAppWorkflowFlowAccessControl(props.AccessControl)); err != nil {
return fmt.Errorf("setting `access_control`: %+v", err)
}

if props.State != "" {
d.Set("enabled", props.State == logic.WorkflowStateEnabled)
}

if props.EndpointsConfiguration == nil || props.EndpointsConfiguration.Connector == nil {
d.Set("connector_endpoint_ip_addresses", []interface{}{})
d.Set("connector_outbound_ip_addresses", []interface{}{})
Expand Down Expand Up @@ -578,6 +705,58 @@ func expandLogicAppWorkflowWorkflowParameters(input map[string]interface{}) (map
return output, nil
}

func expandLogicAppWorkflowAccessControl(input []interface{}) *logic.FlowAccessControlConfiguration {
if len(input) == 0 {
return nil
}
v := input[0].(map[string]interface{})

result := logic.FlowAccessControlConfiguration{}

if contents := v["content"].([]interface{}); len(contents) != 0 {
result.Contents = expandLogicAppWorkflowAccessControlConfigurationPolicy(contents)
}

if actions := v["action"].([]interface{}); len(actions) != 0 {
result.Actions = expandLogicAppWorkflowAccessControlConfigurationPolicy(actions)
}

if triggers := v["trigger"].([]interface{}); len(triggers) != 0 {
result.Triggers = expandLogicAppWorkflowAccessControlConfigurationPolicy(triggers)
}

if workflowManagement := v["workflow_management"].([]interface{}); len(workflowManagement) != 0 {
result.WorkflowManagement = expandLogicAppWorkflowAccessControlConfigurationPolicy(workflowManagement)
}

return &result
}

func expandLogicAppWorkflowAccessControlConfigurationPolicy(input []interface{}) *logic.FlowAccessControlConfigurationPolicy {
if len(input) == 0 {
return nil
}
v := input[0].(map[string]interface{})

result := logic.FlowAccessControlConfigurationPolicy{
AllowedCallerIPAddresses: expandLogicAppWorkflowIPAddressRanges(v["allowed_caller_ip_address_range"].(*pluginsdk.Set).List()),
}

return &result
}

func expandLogicAppWorkflowIPAddressRanges(input []interface{}) *[]logic.IPAddressRange {
results := make([]logic.IPAddressRange, 0)

for _, item := range input {
results = append(results, logic.IPAddressRange{
AddressRange: utils.String(item.(string)),
})
}

return &results
}

func flattenLogicAppWorkflowWorkflowParameters(input map[string]interface{}) (map[string]interface{}, error) {
if input == nil {
return nil, nil
Expand All @@ -604,3 +783,50 @@ func flattenIPAddresses(input *[]logic.IPAddress) []interface{} {
}
return addresses
}

func flattenLogicAppWorkflowFlowAccessControl(input *logic.FlowAccessControlConfiguration) []interface{} {
if input == nil {
return make([]interface{}, 0)
}

return []interface{}{
map[string]interface{}{
"action": flattenLogicAppWorkflowAccessControlConfigurationPolicy(input.Actions),
"content": flattenLogicAppWorkflowAccessControlConfigurationPolicy(input.Contents),
"trigger": flattenLogicAppWorkflowAccessControlConfigurationPolicy(input.Triggers),
"workflow_management": flattenLogicAppWorkflowAccessControlConfigurationPolicy(input.WorkflowManagement),
},
}
}

func flattenLogicAppWorkflowAccessControlConfigurationPolicy(input *logic.FlowAccessControlConfigurationPolicy) []interface{} {
results := make([]interface{}, 0)
if input == nil {
return results
}

result := make(map[string]interface{})

if input.AllowedCallerIPAddresses != nil {
result["allowed_caller_ip_address_range"] = flattenLogicAppWorkflowIPAddressRanges(input.AllowedCallerIPAddresses)
}

return append(results, result)
}

func flattenLogicAppWorkflowIPAddressRanges(input *[]logic.IPAddressRange) []interface{} {
results := make([]interface{}, 0)
if input == nil {
return results
}

for _, item := range *input {
var addressRange string
if item.AddressRange != nil {
addressRange = *item.AddressRange
}
results = append(results, addressRange)
}

return results
}
97 changes: 97 additions & 0 deletions internal/services/logic/logic_app_workflow_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,28 @@ func TestAccLogicAppWorkflow_parameters(t *testing.T) {
})
}

func TestAccLogicAppWorkflow_accessControl(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_logic_app_workflow", "test")
r := LogicAppWorkflowResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.accessControl(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.updateAccessControl(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (LogicAppWorkflowResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := azure.ParseAzureResourceID(state.ID)
if err != nil {
Expand Down Expand Up @@ -364,3 +386,78 @@ resource "azurerm_logic_app_workflow" "test" {
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func (LogicAppWorkflowResource) accessControl(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-logic-%[1]d"
location = "%[2]s"
}

resource "azurerm_logic_app_workflow" "test" {
name = "acctestlaw-%[1]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name

access_control {
content {
allowed_caller_ip_address_range = ["10.0.5.0-10.0.5.10"]
}

action {
allowed_caller_ip_address_range = ["10.0.6.0-10.0.6.10"]
}

trigger {
allowed_caller_ip_address_range = ["10.0.7.0-10.0.7.10"]
}

workflow_management {
allowed_caller_ip_address_range = ["10.0.8.0-10.0.8.10"]
}
}
}
`, data.RandomInteger, data.Locations.Primary)
}

func (LogicAppWorkflowResource) updateAccessControl(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-logic-%[1]d"
location = "%[2]s"
}

resource "azurerm_logic_app_workflow" "test" {
name = "acctestlaw-%[1]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
enabled = false

access_control {
content {
allowed_caller_ip_address_range = ["10.10.3.0/24"]
}

action {
allowed_caller_ip_address_range = ["10.10.4.0/24"]
}

trigger {
allowed_caller_ip_address_range = ["10.10.5.0/24"]
}

workflow_management {
allowed_caller_ip_address_range = ["10.10.6.0/24"]
}
}
}
`, data.RandomInteger, data.Locations.Primary)
}
Loading