Skip to content

Commit

Permalink
Merge pull request #14492 from hashicorp/f/df-deprecate-name
Browse files Browse the repository at this point in the history
`azurerm_data_factory_linked_service_*` rename `data_factory_name` to `data_factory_id`
  • Loading branch information
stephybun authored Dec 7, 2021
2 parents 167ffe2 + 59febe2 commit c2f2b37
Show file tree
Hide file tree
Showing 54 changed files with 805 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,24 @@ func resourceDataFactoryLinkedServiceAzureBlobStorage() *pluginsdk.Resource {
ValidateFunc: validate.LinkedServiceDatasetName,
},

// TODO remove in 3.0
"data_factory_name": {
Type: pluginsdk.TypeString,
Required: true,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validate.DataFactoryName(),
Deprecated: "`data_factory_name` is deprecated in favour of `data_factory_id` and will be removed in version 3.0 of the AzureRM provider",
ExactlyOneOf: []string{"data_factory_id"},
},

"data_factory_id": {
Type: pluginsdk.TypeString,
Optional: true, // TODO set to Required in 3.0
Computed: true, // TODO remove in 3.0
ForceNew: true,
ValidateFunc: validate.DataFactoryID,
ExactlyOneOf: []string{"data_factory_name"},
},

// There's a bug in the Azure API where this is returned in lower-case
Expand Down Expand Up @@ -177,7 +190,21 @@ func resourceDataFactoryLinkedServiceBlobStorageCreateUpdate(d *pluginsdk.Resour
ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()

id := parse.NewLinkedServiceID(subscriptionId, d.Get("resource_group_name").(string), d.Get("data_factory_name").(string), d.Get("name").(string))
// TODO remove/simplify this after deprecation in 3.0
var err error
var dataFactoryId *parse.DataFactoryId
if v := d.Get("data_factory_name").(string); v != "" {
newDataFactoryId := parse.NewDataFactoryID(subscriptionId, d.Get("resource_group_name").(string), d.Get("data_factory_name").(string))
dataFactoryId = &newDataFactoryId
}
if v := d.Get("data_factory_id").(string); v != "" {
dataFactoryId, err = parse.DataFactoryID(v)
if err != nil {
return err
}
}

id := parse.NewLinkedServiceID(subscriptionId, dataFactoryId.ResourceGroup, dataFactoryId.FactoryName, d.Get("name").(string))

if d.IsNewResource() {
existing, err := client.Get(ctx, id.ResourceGroup, id.FactoryName, id.Name, "")
Expand Down Expand Up @@ -274,6 +301,8 @@ func resourceDataFactoryLinkedServiceBlobStorageRead(d *pluginsdk.ResourceData,
return err
}

dataFactoryId := parse.NewDataFactoryID(id.SubscriptionId, id.ResourceGroup, id.FactoryName)

resp, err := client.Get(ctx, id.ResourceGroup, id.FactoryName, id.Name, "")
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
Expand All @@ -286,7 +315,9 @@ func resourceDataFactoryLinkedServiceBlobStorageRead(d *pluginsdk.ResourceData,

d.Set("name", resp.Name)
d.Set("resource_group_name", id.ResourceGroup)
// TODO remove in 3.0
d.Set("data_factory_name", id.FactoryName)
d.Set("data_factory_id", dataFactoryId.ID())

blobStorage, ok := resp.Properties.AsAzureBlobStorageLinkedService()
if !ok {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ resource "azurerm_data_factory" "test" {
resource "azurerm_data_factory_linked_service_azure_blob_storage" "test" {
name = "acctestlsblob%d"
resource_group_name = azurerm_resource_group.test.name
data_factory_name = azurerm_data_factory.test.name
data_factory_id = azurerm_data_factory.test.id
connection_string = "DefaultEndpointsProtocol=https;AccountName=foo;AccountKey=bar"
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
Expand All @@ -169,7 +169,7 @@ resource "azurerm_data_factory" "test" {
resource "azurerm_data_factory_linked_service_azure_blob_storage" "test" {
name = "acctestlsblob%d"
resource_group_name = azurerm_resource_group.test.name
data_factory_name = azurerm_data_factory.test.name
data_factory_id = azurerm_data_factory.test.id
connection_string = "DefaultEndpointsProtocol=https;AccountName=foo2;AccountKey=bar"
annotations = ["test1", "test2", "test3"]
description = "test description"
Expand Down Expand Up @@ -268,7 +268,7 @@ resource "azurerm_role_assignment" "test" {
resource "azurerm_data_factory_linked_service_azure_blob_storage" "test" {
name = "acctestBlobStorage%[1]d"
resource_group_name = azurerm_resource_group.test.name
data_factory_name = azurerm_data_factory.test.name
data_factory_id = azurerm_data_factory.test.id
service_endpoint = azurerm_storage_account.test.primary_blob_endpoint
use_managed_identity = true
}
Expand Down Expand Up @@ -301,7 +301,7 @@ data "azurerm_client_config" "current" {
resource "azurerm_data_factory_linked_service_azure_blob_storage" "test" {
name = "acctestBlobStorage%d"
resource_group_name = azurerm_resource_group.test.name
data_factory_name = azurerm_data_factory.test.name
data_factory_id = azurerm_data_factory.test.id
sas_uri = "https://storageaccountname.blob.core.windows.net/sascontainer/sasblob.txt?sv=2019-02-02&st=2019-04-29T22:18:26Z&se=2019-04-30T02:23:26Z&sr=b&sp=rw&sip=168.1.5.60-168.1.5.70&spr=https&sig=koLniLcK0tMLuMfYeuSQwB+BLnWibhPqnrINxaIRbvU<"
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
Expand Down Expand Up @@ -348,7 +348,7 @@ resource "azurerm_data_factory_linked_service_key_vault" "test" {
resource "azurerm_data_factory_linked_service_azure_blob_storage" "test" {
name = "acctestBlobStorage"
resource_group_name = azurerm_resource_group.test.name
data_factory_name = azurerm_data_factory.test.name
data_factory_id = azurerm_data_factory.test.id
sas_uri = "https://storageaccountname.blob.core.windows.net"
key_vault_sas_token {
linked_service_name = azurerm_data_factory_linked_service_key_vault.test.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,24 @@ func resourceDataFactoryLinkedServiceAzureDatabricks() *pluginsdk.Resource {
ValidateFunc: validate.LinkedServiceDatasetName,
},

// TODO remove in 3.0
"data_factory_name": {
Type: pluginsdk.TypeString,
Required: true,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validate.DataFactoryName(),
Deprecated: "`data_factory_name` is deprecated in favour of `data_factory_id` and will be removed in version 3.0 of the AzureRM provider",
ExactlyOneOf: []string{"data_factory_id"},
},

"data_factory_id": {
Type: pluginsdk.TypeString,
Optional: true, // TODO set to Required in 3.0
Computed: true, // TODO remove in 3.0
ForceNew: true,
ValidateFunc: validate.DataFactoryID,
ExactlyOneOf: []string{"data_factory_name"},
},

// There's a bug in the Azure API where this is returned in lower-case
Expand Down Expand Up @@ -261,7 +274,21 @@ func resourceDataFactoryLinkedServiceDatabricksCreateUpdate(d *pluginsdk.Resourc
ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()

id := parse.NewLinkedServiceID(subscriptionId, d.Get("resource_group_name").(string), d.Get("data_factory_name").(string), d.Get("name").(string))
// TODO 3.0: remove/simplify this after deprecation
var err error
var dataFactoryId *parse.DataFactoryId
if v := d.Get("data_factory_name").(string); v != "" {
newDataFactoryId := parse.NewDataFactoryID(subscriptionId, d.Get("resource_group_name").(string), d.Get("data_factory_name").(string))
dataFactoryId = &newDataFactoryId
}
if v := d.Get("data_factory_id").(string); v != "" {
dataFactoryId, err = parse.DataFactoryID(v)
if err != nil {
return err
}
}

id := parse.NewLinkedServiceID(subscriptionId, dataFactoryId.ResourceGroup, dataFactoryId.FactoryName, d.Get("name").(string))

if d.IsNewResource() {
existing, err := client.Get(ctx, id.ResourceGroup, id.FactoryName, id.Name, "")
Expand Down Expand Up @@ -430,6 +457,8 @@ func resourceDataFactoryLinkedServiceDatabricksRead(d *pluginsdk.ResourceData, m
return err
}

dataFactoryId := parse.NewDataFactoryID(id.SubscriptionId, id.ResourceGroup, id.FactoryName)

resp, err := client.Get(ctx, id.ResourceGroup, id.FactoryName, id.Name, "")
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
Expand All @@ -442,7 +471,9 @@ func resourceDataFactoryLinkedServiceDatabricksRead(d *pluginsdk.ResourceData, m

d.Set("name", resp.Name)
d.Set("resource_group_name", id.ResourceGroup)
// TODO 3.0: remove
d.Set("data_factory_name", id.FactoryName)
d.Set("data_factory_id", dataFactoryId.ID())

databricks, ok := resp.Properties.AsAzureDatabricksLinkedService()
if !ok {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ data "azurerm_client_config" "current" {
resource "azurerm_data_factory_linked_service_azure_databricks" "test" {
name = "acctestDatabricksLinkedService%d"
resource_group_name = azurerm_resource_group.test.name
data_factory_name = azurerm_data_factory.test.name
data_factory_id = azurerm_data_factory.test.id
msi_work_space_resource_id = "/subscriptions/11111111-1111-1111-1111-111111111111/resourceGroups/test/providers/Microsoft.Databricks/workspaces/testworkspace"
description = "Initial description"
Expand Down Expand Up @@ -167,7 +167,7 @@ data "azurerm_client_config" "current" {
resource "azurerm_data_factory_linked_service_azure_databricks" "test" {
name = "acctestDatabricksLinkedService%d"
resource_group_name = azurerm_resource_group.test.name
data_factory_name = azurerm_data_factory.test.name
data_factory_id = azurerm_data_factory.test.id
access_token = "SomeFakeAccessToken"
description = "Initial description"
annotations = ["test1", "test2"]
Expand Down Expand Up @@ -218,7 +218,7 @@ resource "azurerm_data_factory_linked_service_key_vault" "test" {
resource "azurerm_data_factory_linked_service_azure_databricks" "test" {
name = "acctestDatabricksLinkedService%d"
resource_group_name = azurerm_resource_group.test.name
data_factory_name = azurerm_data_factory.test.name
data_factory_id = azurerm_data_factory.test.id
key_vault_password {
linked_service_name = azurerm_data_factory_linked_service_key_vault.test.name
secret_name = "secret"
Expand Down Expand Up @@ -258,7 +258,7 @@ data "azurerm_client_config" "current" {
resource "azurerm_data_factory_linked_service_azure_databricks" "test" {
name = "acctestDatabricksLinkedService%d"
resource_group_name = azurerm_resource_group.test.name
data_factory_name = azurerm_data_factory.test.name
data_factory_id = azurerm_data_factory.test.id
msi_work_space_resource_id = "/subscriptions/11111111-1111-1111-1111-111111111111/resourceGroups/test/providers/Microsoft.Databricks/workspaces/testworkspace"
description = "Initial description"
Expand Down Expand Up @@ -312,7 +312,7 @@ resource "azurerm_data_factory" "test" {
resource "azurerm_data_factory_linked_service_azure_databricks" "test" {
name = "acctestDatabricksLinkedService%d"
resource_group_name = azurerm_resource_group.test.name
data_factory_name = azurerm_data_factory.test.name
data_factory_id = azurerm_data_factory.test.id
description = "Initial Description"
annotations = ["a1", "a2"]
parameters = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,24 @@ func resourceDataFactoryLinkedServiceAzureFileStorage() *pluginsdk.Resource {
ValidateFunc: validate.LinkedServiceDatasetName,
},

// TODO remove in 3.0
"data_factory_name": {
Type: pluginsdk.TypeString,
Required: true,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validate.DataFactoryName(),
Deprecated: "`data_factory_name` is deprecated in favour of `data_factory_id` and will be removed in version 3.0 of the AzureRM provider",
ExactlyOneOf: []string{"data_factory_id"},
},

"data_factory_id": {
Type: pluginsdk.TypeString,
Optional: true, // TODO set to Required in 3.0
Computed: true, // TODO remove in 3.0
ForceNew: true,
ValidateFunc: validate.DataFactoryID,
ExactlyOneOf: []string{"data_factory_name"},
},

// There's a bug in the Azure API where this is returned in lower-case
Expand Down Expand Up @@ -152,7 +165,21 @@ func resourceDataFactoryLinkedServiceAzureFileStorageCreateUpdate(d *pluginsdk.R
ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()

id := parse.NewLinkedServiceID(subscriptionId, d.Get("resource_group_name").(string), d.Get("data_factory_name").(string), d.Get("name").(string))
// TODO 3.0: remove/simplify this after deprecation
var err error
var dataFactoryId *parse.DataFactoryId
if v := d.Get("data_factory_name").(string); v != "" {
newDataFactoryId := parse.NewDataFactoryID(subscriptionId, d.Get("resource_group_name").(string), d.Get("data_factory_name").(string))
dataFactoryId = &newDataFactoryId
}
if v := d.Get("data_factory_id").(string); v != "" {
dataFactoryId, err = parse.DataFactoryID(v)
if err != nil {
return err
}
}

id := parse.NewLinkedServiceID(subscriptionId, dataFactoryId.ResourceGroup, dataFactoryId.FactoryName, d.Get("name").(string))

if d.IsNewResource() {
existing, err := client.Get(ctx, id.ResourceGroup, id.FactoryName, id.Name, "")
Expand Down Expand Up @@ -236,6 +263,8 @@ func resourceDataFactoryLinkedServiceAzureFileStorageRead(d *pluginsdk.ResourceD
return err
}

dataFactoryId := parse.NewDataFactoryID(id.SubscriptionId, id.ResourceGroup, id.FactoryName)

resp, err := client.Get(ctx, id.ResourceGroup, id.FactoryName, id.Name, "")
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
Expand All @@ -248,7 +277,9 @@ func resourceDataFactoryLinkedServiceAzureFileStorageRead(d *pluginsdk.ResourceD

d.Set("name", resp.Name)
d.Set("resource_group_name", id.ResourceGroup)
// TODO 3.0: remove
d.Set("data_factory_name", id.FactoryName)
d.Set("data_factory_id", dataFactoryId.ID())

fileStorage, ok := resp.Properties.AsAzureFileStorageLinkedService()
if !ok {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ resource "azurerm_data_factory" "test" {
resource "azurerm_data_factory_linked_service_azure_file_storage" "test" {
name = "acctestlsblob%d"
resource_group_name = azurerm_resource_group.test.name
data_factory_name = azurerm_data_factory.test.name
data_factory_id = azurerm_data_factory.test.id
connection_string = "DefaultEndpointsProtocol=https;AccountName=foo;AccountKey=bar"
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
Expand All @@ -154,7 +154,7 @@ resource "azurerm_data_factory" "test" {
resource "azurerm_data_factory_linked_service_azure_file_storage" "test" {
name = "acctestlsblob%d"
resource_group_name = azurerm_resource_group.test.name
data_factory_name = azurerm_data_factory.test.name
data_factory_id = azurerm_data_factory.test.id
connection_string = "DefaultEndpointsProtocol=https;AccountName=foo2;AccountKey=bar"
annotations = ["test1", "test2", "test3"]
description = "test description"
Expand Down Expand Up @@ -231,7 +231,7 @@ resource "azurerm_data_factory" "test" {
resource "azurerm_data_factory_linked_service_azure_file_storage" "test" {
name = "acctestlsblob%d"
resource_group_name = azurerm_resource_group.test.name
data_factory_name = azurerm_data_factory.test.name
data_factory_id = azurerm_data_factory.test.id
connection_string = "DefaultEndpointsProtocol=https;AccountName=foo;AccountKey=bar"
file_share = "myshare"
}
Expand Down Expand Up @@ -269,7 +269,7 @@ resource "azurerm_data_factory_linked_service_key_vault" "test" {
resource "azurerm_data_factory_linked_service_azure_file_storage" "test" {
name = "acctestlsblob%d"
resource_group_name = azurerm_resource_group.test.name
data_factory_name = azurerm_data_factory.test.name
data_factory_id = azurerm_data_factory.test.id
connection_string = "DefaultEndpointsProtocol=https;AccountName=foo;AccountKey=bar"
file_share = "myshare"
key_vault_password {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,24 @@ func resourceDataFactoryLinkedServiceAzureFunction() *pluginsdk.Resource {
ValidateFunc: validate.LinkedServiceDatasetName,
},

// TODO 3.0 rename this to data_factory_id
// TODO remove in 3.0
"data_factory_name": {
Type: pluginsdk.TypeString,
Required: true,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validate.DataFactoryName(),
Deprecated: "`data_factory_name` is deprecated in favour of `data_factory_id` and will be removed in version 3.0 of the AzureRM provider",
ExactlyOneOf: []string{"data_factory_id"},
},

"data_factory_id": {
Type: pluginsdk.TypeString,
Optional: true, // TODO set to Required in 3.0
Computed: true, // TODO remove in 3.0
ForceNew: true,
ValidateFunc: validate.DataFactoryID,
ExactlyOneOf: []string{"data_factory_name"},
},

// There's a bug in the Azure API where this is returned in lower-case
Expand Down Expand Up @@ -137,7 +149,19 @@ func resourceDataFactoryLinkedServiceAzureFunctionCreateUpdate(d *pluginsdk.Reso
ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()

dataFactoryId := parse.NewDataFactoryID(subscriptionId, d.Get("resource_group_name").(string), d.Get("data_factory_name").(string))
// TODO 3.0: remove/simplify this after deprecation
var err error
var dataFactoryId *parse.DataFactoryId
if v := d.Get("data_factory_name").(string); v != "" {
newDataFactoryId := parse.NewDataFactoryID(subscriptionId, d.Get("resource_group_name").(string), d.Get("data_factory_name").(string))
dataFactoryId = &newDataFactoryId
}
if v := d.Get("data_factory_id").(string); v != "" {
dataFactoryId, err = parse.DataFactoryID(v)
if err != nil {
return err
}
}

id := parse.NewLinkedServiceID(subscriptionId, dataFactoryId.ResourceGroup, dataFactoryId.FactoryName, d.Get("name").(string))

Expand Down Expand Up @@ -209,6 +233,8 @@ func resourceDataFactoryLinkedServiceAzureFunctionRead(d *pluginsdk.ResourceData
return err
}

dataFactoryId := parse.NewDataFactoryID(id.SubscriptionId, id.ResourceGroup, id.FactoryName)

resp, err := client.Get(ctx, id.ResourceGroup, id.FactoryName, id.Name, "")
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
Expand All @@ -221,7 +247,9 @@ func resourceDataFactoryLinkedServiceAzureFunctionRead(d *pluginsdk.ResourceData

d.Set("name", id.Name)
d.Set("resource_group_name", id.ResourceGroup)
// TODO 3.0: remove
d.Set("data_factory_name", id.FactoryName)
d.Set("data_factory_id", dataFactoryId.ID())

azureFunction, ok := resp.Properties.AsAzureFunctionLinkedService()
if !ok {
Expand Down
Loading

0 comments on commit c2f2b37

Please sign in to comment.