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

Added new data source azurerm_data_factory #4517

Merged
merged 9 commits into from
Oct 4, 2019
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
166 changes: 166 additions & 0 deletions azurerm/data_source_arm_data_factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
package azurerm

import (
"fmt"
"regexp"

"github.com/Azure/azure-sdk-for-go/services/datafactory/mgmt/2018-06-01/datafactory"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func dataSourceArmDataFactory() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmDataFactoryRead,

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringMatch(
regexp.MustCompile(`^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`),
`Invalid name for Data Factory, see https://docs.microsoft.com/en-us/azure/data-factory/naming-rules`,
),
},
tracypholmes marked this conversation as resolved.
Show resolved Hide resolved

"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),
tracypholmes marked this conversation as resolved.
Show resolved Hide resolved

"location": azure.SchemaLocationForDataSource(),

"identity": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Computed: true,
},
"principal_id": {
Type: schema.TypeString,
Computed: true,
},
"tenant_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},

"github_configuration": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"account_name": {
Type: schema.TypeString,
Computed: true,
},
"branch_name": {
Type: schema.TypeString,
Computed: true,
},
"git_url": {
Type: schema.TypeString,
Computed: true,
},
"repository_name": {
Type: schema.TypeString,
Computed: true,
},
"root_folder": {
Type: schema.TypeString,
Computed: true,
},
},
},
},

"vsts_configuration": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"account_name": {
Type: schema.TypeString,
Computed: true,
},
"branch_name": {
Type: schema.TypeString,
Computed: true,
},
"project_name": {
Type: schema.TypeString,
Computed: true,
},
"repository_name": {
Type: schema.TypeString,
Computed: true,
},
"root_folder": {
Type: schema.TypeString,
Computed: true,
},
"tenant_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},

"tags": tags.SchemaDataSource(),
},
}
}

func dataSourceArmDataFactoryRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).dataFactory.FactoriesClient
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("Error Data Factory %q (Resource Group %q) was not found", name, resourceGroup)
}

return fmt.Errorf("Error retrieving Data Factory %q (Resource Group %q): %+v", name, resourceGroup, err)
}

d.Set("name", resp.Name)
d.Set("resource_group_name", resourceGroup)
if location := resp.Location; location != nil {
d.Set("location", azure.NormalizeLocation(*location))
}

d.Set("vsts_configuration", []interface{}{})
d.Set("github_configuration", []interface{}{})
repoType, repo := flattenArmDataFactoryRepoConfiguration(&resp)
if repoType == datafactory.TypeFactoryVSTSConfiguration {
if err := d.Set("vsts_configuration", repo); err != nil {
return fmt.Errorf("Error setting `vsts_configuration`: %+v", err)
}
}
if repoType == datafactory.TypeFactoryGitHubConfiguration {
if err := d.Set("github_configuration", repo); err != nil {
return fmt.Errorf("Error setting `github_configuration`: %+v", err)
}
}
if repoType == datafactory.TypeFactoryRepoConfiguration {
d.Set("vsts_configuration", repo)
d.Set("github_configuration", repo)
}

if err := d.Set("identity", flattenArmDataFactoryIdentity(resp.Identity)); err != nil {
return fmt.Errorf("Error flattening `identity`: %+v", err)
}

return tags.FlattenAndSet(d, resp.Tags)
}
41 changes: 41 additions & 0 deletions azurerm/data_source_arm_data_factory_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package azurerm

import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/resource"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
)

func TestAccAzureRMDataFactoryDataSource_basic(t *testing.T) {
dsn := "azurerm_data_factory.test"
ri := tf.AccRandTimeInt()
location := testLocation()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMDataFactoryDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMDataFactoryDataSource_basic(ri, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMDataFactoryExists(dsn),
),
},
},
})
}

func testAccAzureRMDataFactoryDataSource_basic(rInt int, location string) string {
config := testAccAzureRMDataFactory_basic(rInt, location)
return fmt.Sprintf(`
%s

data "azurerm_data_factory" "test" {
name = "${azurerm_data_factory.test.name}"
resource_group_name = "${azurerm_data_factory.test.resource_group_name}"
}
`, config)
}
1 change: 1 addition & 0 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_kubernetes_service_versions": dataSourceArmKubernetesServiceVersions(),
"azurerm_container_registry": dataSourceArmContainerRegistry(),
"azurerm_cosmosdb_account": dataSourceArmCosmosDbAccount(),
"azurerm_data_factory": dataSourceArmDataFactory(),
"azurerm_data_lake_store": dataSourceArmDataLakeStoreAccount(),
"azurerm_dev_test_lab": dataSourceArmDevTestLab(),
"azurerm_dev_test_virtual_network": dataSourceArmDevTestVirtualNetwork(),
Expand Down
4 changes: 4 additions & 0 deletions website/azurerm.erb
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@
<a href="/docs/providers/azurerm/d/dns_zone.html">azurerm_dns_zone</a>
</li>

<li>
<a href="/docs/providers/azurerm/d/data_factory.html">azurerm_data_factory</a>
</li>

<li>
<a href="/docs/providers/azurerm/d/data_lake_store.html">azurerm_data_lake_store</a>
</li>
Expand Down
89 changes: 89 additions & 0 deletions website/docs/d/data_factory.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
layout: "azurerm"
page_title: "Azure Resource Manager: azurerm_data_factory"
sidebar_current: "docs-azurerm-datasource-data-factory-x"
description: |-
Manages an Azure Data Factory (Version 2).
---

# Data Source: azurerm_data_factory

Use this data source to access information about an existing Azure Data Factory (Version 2).

## Example Usage

```hcl

data "azurerm_data_factory" "example" {
name = "${azurerm_data_factory.example.name}"
resource_group_name = "${azurerm_data_factory.example.resource_group_name}"
}

output "data_factory_id" {
value = "${azurerm_data_factory.example.id}"
}

```

## Argument Reference

The following arguments are supported:

* `name` - (Required) Specifies the name of the Data Factory to retrieve information about.

* `resource_group_name` - (Required) The name of the resource group where the Data Factory exists.

## Attributes Reference

The following attributes are exported:

* `id` - The Data Factory ID.

* `location` - The Azure location where the resource exists.

* `github_configuration` - A `github_configuration` block as defined below.

* `identity` - An `identity` block as defined below.

* `vsts_configuration` - A `vsts_configuration` block as defined below.

* `tags` - A mapping of tags assigned to the resource.
---

A `github_configuration` block exports the following:

* `account_name` - The GitHub account name.

* `branch_name` - The branch of the repository to get code from.

* `git_url` - The GitHub Enterprise host name.

* `repository_name` - The name of the git repository.

* `root_folder` - The root folder within the repository.

---

An `identity` block exports the following:

* `principal_id` - The ID of the Principal (Client) in Azure Active Directory.

* `tenant_id` - The ID of the Azure Active Directory Tenant.

* `type` - The identity type of the Data Factory.

---

A `vsts_configuration` block exports the following:

* `account_name` - The VSTS account name.

* `branch_name` - The branch of the repository to get code from.

* `project_name` - The name of the VSTS project.

* `repository_name` - The name of the git repository.

* `root_folder` - The root folder within the repository.

* `tenant_id` - The Tenant ID associated with the VSTS account.