-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
New Resource: azurerm_logic_app_workflow
#1266
Changes from all commits
fb1823c
4492194
c92d324
2153a55
2e01256
19f8f31
25e3028
0c03156
1496768
70762ae
60d3e06
706bb7a
9a5c117
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/logic/mgmt/2016-06-01/logic" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func dataSourceArmLogicAppWorkflow() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceArmLogicAppWorkflowRead, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
|
||
"resource_group_name": resourceGroupNameForDataSourceSchema(), | ||
|
||
"location": locationForDataSourceSchema(), | ||
|
||
// TODO: should Parameters be split out into their own object to allow validation on the different sub-types? | ||
"parameters": { | ||
Type: schema.TypeMap, | ||
Computed: true, | ||
}, | ||
|
||
"workflow_schema": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"workflow_version": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"tags": tagsForDataSourceSchema(), | ||
|
||
"access_endpoint": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
func dataSourceArmLogicAppWorkflowRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).logicWorkflowsClient | ||
ctx := meta.(*ArmClient).StopContext | ||
|
||
name := d.Get("name").(string) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
|
||
resp, err := client.Get(ctx, resourceGroup, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
return fmt.Errorf("Logic App Workflow %q was not found in Resource Group %q", name, resourceGroup) | ||
} | ||
|
||
return fmt.Errorf("[ERROR] Error making Read request on Logic App Workflow %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
d.SetId(*resp.ID) | ||
|
||
if location := resp.Location; location != nil { | ||
d.Set("location", azureRMNormalizeLocation(*location)) | ||
} | ||
|
||
if props := resp.WorkflowProperties; props != nil { | ||
parameters := flattenLogicAppDataSourceWorkflowParameters(props.Parameters) | ||
if err := d.Set("parameters", parameters); err != nil { | ||
return fmt.Errorf("Error flattening `parameters`: %+v", err) | ||
} | ||
|
||
d.Set("access_endpoint", props.AccessEndpoint) | ||
|
||
if definition := props.Definition; definition != nil { | ||
if v, ok := definition.(map[string]interface{}); ok { | ||
schema := v["$schema"].(string) | ||
version := v["contentVersion"].(string) | ||
d.Set("workflow_schema", schema) | ||
d.Set("workflow_version", version) | ||
} | ||
} | ||
} | ||
|
||
flattenAndSetTags(d, resp.Tags) | ||
|
||
return nil | ||
} | ||
|
||
func flattenLogicAppDataSourceWorkflowParameters(input map[string]*logic.WorkflowParameter) map[string]interface{} { | ||
output := make(map[string]interface{}, 0) | ||
|
||
for k, v := range input { | ||
if v != nil { | ||
output[k] = v.Value.(string) | ||
} | ||
} | ||
|
||
return output | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceAzureRMLogicAppWorkflow_basic(t *testing.T) { | ||
dataSourceName := "data.azurerm_logic_app_workflow.test" | ||
ri := acctest.RandInt() | ||
location := testLocation() | ||
config := testAccDataSourceAzureRMLogicAppWorkflow_basic(ri, location) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Check: resource.ComposeTestCheckFunc( | ||
testCheckAzureRMLogicAppWorkflowExists(dataSourceName), | ||
resource.TestCheckResourceAttr(dataSourceName, "parameters.%", "0"), | ||
resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccDataSourceAzureRMLogicAppWorkflow_tags(t *testing.T) { | ||
dataSourceName := "data.azurerm_logic_app_workflow.test" | ||
ri := acctest.RandInt() | ||
location := testLocation() | ||
config := testAccDataSourceAzureRMLogicAppWorkflow_tags(ri, location) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Check: resource.ComposeTestCheckFunc( | ||
testCheckAzureRMLogicAppWorkflowExists(dataSourceName), | ||
resource.TestCheckResourceAttr(dataSourceName, "parameters.%", "0"), | ||
resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "tags.Source", "AcceptanceTests"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceAzureRMLogicAppWorkflow_basic(rInt int, location string) string { | ||
resource := testAccAzureRMLogicAppWorkflow_empty(rInt, location) | ||
return fmt.Sprintf(` | ||
%s | ||
|
||
data "azurerm_logic_app_workflow" "test" { | ||
name = "${azurerm_logic_app_workflow.test.name}" | ||
resource_group_name = "${azurerm_logic_app_workflow.test.resource_group_name}" | ||
} | ||
`, resource) | ||
} | ||
|
||
func testAccDataSourceAzureRMLogicAppWorkflow_tags(rInt int, location string) string { | ||
resource := testAccAzureRMLogicAppWorkflow_tags(rInt, location) | ||
return fmt.Sprintf(` | ||
%s | ||
|
||
data "azurerm_logic_app_workflow" "test" { | ||
name = "${azurerm_logic_app_workflow.test.name}" | ||
resource_group_name = "${azurerm_logic_app_workflow.test.resource_group_name}" | ||
} | ||
`, resource) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package azurerm | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccAzureRMLogicAppActionCustom_importBasic(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Point for consideration: In AWS-land, we've been adding the import
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not opposed to that approach (we've started doing it for some resources) - but I think that's a larger project outside the scope of this PR - so I'm going to skip this for now. |
||
ri := acctest.RandInt() | ||
config := testAccAzureRMLogicAppActionCustom_basic(ri, testLocation()) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
}, | ||
{ | ||
ResourceName: "azurerm_logic_app_action_custom.test", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package azurerm | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccAzureRMLogicAppActionHttp_importBasic(t *testing.T) { | ||
ri := acctest.RandInt() | ||
config := testAccAzureRMLogicAppActionHttp_basic(ri, testLocation()) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
}, | ||
{ | ||
ResourceName: "azurerm_logic_app_action_http.test", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccAzureRMLogicAppActionHttp_importHeaders(t *testing.T) { | ||
ri := acctest.RandInt() | ||
config := testAccAzureRMLogicAppActionHttp_headers(ri, testLocation()) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
}, | ||
{ | ||
ResourceName: "azurerm_logic_app_action_http.test", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package azurerm | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccAzureRMLogicAppTriggerCustom_importBasic(t *testing.T) { | ||
ri := acctest.RandInt() | ||
config := testAccAzureRMLogicAppTriggerCustom_basic(ri, testLocation()) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
}, | ||
{ | ||
ResourceName: "azurerm_logic_app_trigger_custom.test", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nitpick: should we use
resource.TestCheckResourceAttrPair()
for these rather than hardcoding the expectations?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's an enhancement we should make, but across all resources (since a lot of tests follow this pattern); going to skip this for now.