Skip to content

Commit

Permalink
Modify per PR comment
Browse files Browse the repository at this point in the history
[PR Link](#5862 (review))
  • Loading branch information
magodo committed Mar 17, 2020
1 parent 742f3c8 commit 95c2dad
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 107 deletions.
40 changes: 31 additions & 9 deletions azurerm/internal/services/logic/data_source_logic_app_workflow.go
Expand Up @@ -56,15 +56,25 @@ func dataSourceArmLogicAppWorkflow() *schema.Resource {
Computed: true,
},

"endpoint_configuration": {
"connector_endpoint_ip_addresses": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"workflow": buildFlowEndpointsSchema(),
"connector": buildFlowEndpointsSchema(),
},
},
Elem: &schema.Schema{Type: schema.TypeString},
},
"connector_outbound_ip_addresses": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"workflow_endpoint_ip_addresses": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"workflow_outbound_ip_addresses": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},

"tags": tags.SchemaDataSource(),
Expand Down Expand Up @@ -102,8 +112,20 @@ func dataSourceArmLogicAppWorkflowRead(d *schema.ResourceData, meta interface{})

d.Set("access_endpoint", props.AccessEndpoint)

if err := d.Set("endpoint_configuration", flattenFlowEndpointsConfiguration(props.EndpointsConfiguration)); err != nil {
return fmt.Errorf("Error setting `endpoint_configuration`: %+v", err)
if props.EndpointsConfiguration == nil || props.EndpointsConfiguration.Connector == nil {
d.Set("connector_endpoint_ip_addresses", []interface{}{})
d.Set("connector_outbound_ip_addresses", []interface{}{})
} else {
d.Set("connector_endpoint_ip_addresses", flattenIPAddresses(props.EndpointsConfiguration.Connector.AccessEndpointIPAddresses))
d.Set("connector_outbound_ip_addresses", flattenIPAddresses(props.EndpointsConfiguration.Connector.OutgoingIPAddresses))
}

if props.EndpointsConfiguration == nil || props.EndpointsConfiguration.Workflow == nil {
d.Set("workflow_endpoint_ip_addresses", []interface{}{})
d.Set("workflow_outbound_ip_addresses", []interface{}{})
} else {
d.Set("workflow_endpoint_ip_addresses", flattenIPAddresses(props.EndpointsConfiguration.Workflow.AccessEndpointIPAddresses))
d.Set("workflow_outbound_ip_addresses", flattenIPAddresses(props.EndpointsConfiguration.Workflow.OutgoingIPAddresses))
}

if definition := props.Definition; definition != nil {
Expand Down
96 changes: 35 additions & 61 deletions azurerm/internal/services/logic/resource_arm_logic_app_workflow.go
Expand Up @@ -19,27 +19,6 @@ import (

var logicAppResourceName = "azurerm_logic_app"

func buildFlowEndpointsSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"outgoing_ip_addresses": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"access_endpoint_ip_addresses": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
}
}

func resourceArmLogicAppWorkflow() *schema.Resource {
return &schema.Resource{
Create: resourceArmLogicAppWorkflowCreate,
Expand Down Expand Up @@ -96,15 +75,25 @@ func resourceArmLogicAppWorkflow() *schema.Resource {
Computed: true,
},

"endpoint_configuration": {
"connector_endpoint_ip_addresses": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"workflow": buildFlowEndpointsSchema(),
"connector": buildFlowEndpointsSchema(),
},
},
Elem: &schema.Schema{Type: schema.TypeString},
},
"connector_outbound_ip_addresses": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"workflow_endpoint_ip_addresses": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"workflow_outbound_ip_addresses": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},

"tags": tags.Schema(),
Expand Down Expand Up @@ -261,10 +250,21 @@ func resourceArmLogicAppWorkflowRead(d *schema.ResourceData, meta interface{}) e

d.Set("access_endpoint", props.AccessEndpoint)

if err := d.Set("endpoint_configuration", flattenFlowEndpointsConfiguration(props.EndpointsConfiguration)); err != nil {
return fmt.Errorf("Error setting `endpoint_configuration`: %+v", err)
if props.EndpointsConfiguration == nil || props.EndpointsConfiguration.Connector == nil {
d.Set("connector_endpoint_ip_addresses", []interface{}{})
d.Set("connector_outbound_ip_addresses", []interface{}{})
} else {
d.Set("connector_endpoint_ip_addresses", flattenIPAddresses(props.EndpointsConfiguration.Connector.AccessEndpointIPAddresses))
d.Set("connector_outbound_ip_addresses", flattenIPAddresses(props.EndpointsConfiguration.Connector.OutgoingIPAddresses))
}

if props.EndpointsConfiguration == nil || props.EndpointsConfiguration.Workflow == nil {
d.Set("workflow_endpoint_ip_addresses", []interface{}{})
d.Set("workflow_outbound_ip_addresses", []interface{}{})
} else {
d.Set("workflow_endpoint_ip_addresses", flattenIPAddresses(props.EndpointsConfiguration.Workflow.AccessEndpointIPAddresses))
d.Set("workflow_outbound_ip_addresses", flattenIPAddresses(props.EndpointsConfiguration.Workflow.OutgoingIPAddresses))
}
if definition := props.Definition; definition != nil {
if v, ok := definition.(map[string]interface{}); ok {
d.Set("workflow_schema", v["$schema"].(string))
Expand Down Expand Up @@ -335,40 +335,14 @@ func flattenLogicAppWorkflowParameters(input map[string]*logic.WorkflowParameter
return output
}

func flattenFlowEndpointsConfiguration(input *logic.FlowEndpointsConfiguration) []interface{} {
func flattenIPAddresses(input *[]logic.IPAddress) []interface{} {
if input == nil {
return []interface{}{}
}

return []interface{}{
map[string]interface{}{
"workflow": flattenFlowEndpoint(input.Workflow),
"connector": flattenFlowEndpoint(input.Connector),
},
}
}
func flattenFlowEndpoint(input *logic.FlowEndpoints) []interface{} {
if input == nil {
return []interface{}{}
}

outgoingIpAddresses := []string{}
if input.OutgoingIPAddresses != nil {
for _, addr := range *input.OutgoingIPAddresses {
outgoingIpAddresses = append(outgoingIpAddresses, *addr.Address)
}
}
accessEndpointIpAddresses := []string{}
if input.AccessEndpointIPAddresses != nil {
for _, addr := range *input.AccessEndpointIPAddresses {
accessEndpointIpAddresses = append(accessEndpointIpAddresses, *addr.Address)
}
}

return []interface{}{
map[string]interface{}{
"outgoing_ip_addresses": outgoingIpAddresses,
"access_endpoint_ip_addresses": accessEndpointIpAddresses,
},
var addresses []interface{}
for _, addr := range *input {
addresses = append(addresses, *addr.Address)
}
return addresses
}
Expand Up @@ -21,10 +21,10 @@ func TestAccDataSourceAzureRMLogicAppWorkflow_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMLogicAppWorkflowExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "parameters.%", "0"),
resource.TestCheckResourceAttrSet(data.ResourceName, "endpoint_configuration.0.workflow.0.access_endpoint_ip_addresses.#"),
resource.TestCheckResourceAttrSet(data.ResourceName, "endpoint_configuration.0.workflow.0.outgoing_ip_addresses.#"),
resource.TestCheckResourceAttrSet(data.ResourceName, "endpoint_configuration.0.connector.0.access_endpoint_ip_addresses.#"),
resource.TestCheckResourceAttrSet(data.ResourceName, "endpoint_configuration.0.connector.0.outgoing_ip_addresses.#"),
resource.TestCheckResourceAttrSet(data.ResourceName, "connector_endpoint_ip_addresses.#"),
resource.TestCheckResourceAttrSet(data.ResourceName, "connector_outbound_ip_addresses.#"),
resource.TestCheckResourceAttrSet(data.ResourceName, "workflow_endpoint_ip_addresses.#"),
resource.TestCheckResourceAttrSet(data.ResourceName, "workflow_outbound_ip_addresses.#"),
resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"),
),
},
Expand Down
Expand Up @@ -26,10 +26,10 @@ func TestAccAzureRMLogicAppWorkflow_empty(t *testing.T) {
testCheckAzureRMLogicAppWorkflowExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "parameters.%", "0"),
resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"),
resource.TestCheckResourceAttrSet(data.ResourceName, "endpoint_configuration.0.workflow.0.access_endpoint_ip_addresses.#"),
resource.TestCheckResourceAttrSet(data.ResourceName, "endpoint_configuration.0.workflow.0.outgoing_ip_addresses.#"),
resource.TestCheckResourceAttrSet(data.ResourceName, "endpoint_configuration.0.connector.0.access_endpoint_ip_addresses.#"),
resource.TestCheckResourceAttrSet(data.ResourceName, "endpoint_configuration.0.connector.0.outgoing_ip_addresses.#"),
resource.TestCheckResourceAttrSet(data.ResourceName, "connector_endpoint_ip_addresses.#"),
resource.TestCheckResourceAttrSet(data.ResourceName, "connector_outbound_ip_addresses.#"),
resource.TestCheckResourceAttrSet(data.ResourceName, "workflow_endpoint_ip_addresses.#"),
resource.TestCheckResourceAttrSet(data.ResourceName, "workflow_outbound_ip_addresses.#"),
),
},
data.ImportStep(),
Expand Down
18 changes: 4 additions & 14 deletions website/docs/d/logic_app_workflow.html.markdown
Expand Up @@ -49,23 +49,13 @@ The following attributes are exported:

* `access_endpoint` - The Access Endpoint for the Logic App Workflow

* `endpoint_configuration` - The Endpoint Configuration for the Logic App Workflow as defined below.
* `connector_endpoint_ip_addresses` - The list of access endpoint ip addresses of connector.

---

A `endpoint_configuration` block supports the following:

* `workflow` - The Flow Endpoints Configuration applied to workflow as defined below.

* `connector` - The Flow Endpoints Configuration applied to connector as defined below.

---

A `workflow`/`connector` block supports the following:
* `connector_outbound_ip_addresses` - The list of outgoing ip addresses of connector.

* `outgoing_ip_addresses` - A set of the outgoing ip addresses.
* `workflow_endpoint_ip_addresses` - The list of access endpoint ip addresses of workflow.

* `access_endpoint_ip_addresses` - A set of the access endpoint ip addresses.
* `workflow_outbound_ip_addresses` - The list of outgoing ip addresses of workflow.

## Timeouts

Expand Down
19 changes: 4 additions & 15 deletions website/docs/r/logic_app_workflow.html.markdown
Expand Up @@ -53,24 +53,13 @@ The following attributes are exported:

* `access_endpoint` - The Access Endpoint for the Logic App Workflow.

* `endpoint_configuration` - The Endpoint Configuration for the Logic App Workflow as defined below.
* `connector_endpoint_ip_addresses` - The list of access endpoint ip addresses of connector.

---

A `endpoint_configuration` block supports the following:

* `workflow` - The Flow Endpoints Configuration applied to workflow as defined below.

* `connector` - The Flow Endpoints Configuration applied to connector as defined below.

---

A `workflow`/`connector` block supports the following:

* `outgoing_ip_addresses` - A set of the outgoing ip addresses.
* `connector_outbound_ip_addresses` - The list of outgoing ip addresses of connector.

* `access_endpoint_ip_addresses` - A set of the access endpoint ip addresses.
* `workflow_endpoint_ip_addresses` - The list of access endpoint ip addresses of workflow.

* `workflow_outbound_ip_addresses` - The list of outgoing ip addresses of workflow.

## Timeouts

Expand Down

0 comments on commit 95c2dad

Please sign in to comment.