-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new data source
azurerm_data_factory
(#4517)
Fixes #4421.
- Loading branch information
1 parent
caf3ed0
commit 1d2f611
Showing
5 changed files
with
301 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`, | ||
), | ||
}, | ||
|
||
"resource_group_name": azure.SchemaResourceGroupNameForDataSource(), | ||
|
||
"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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |