Skip to content

Commit

Permalink
azurerm_data_factory_pipeline - migrate to hashicorp/go-azure-sdk (
Browse files Browse the repository at this point in the history
…#28768)

* migrate data factory pipeline to go-azure-sdk

* remove sdk hack for pipelines client since this has been migrated to go-azure-sdk

* lint pedanticness

* use pointer.From to set variables and parameters into state
  • Loading branch information
stephybun authored Feb 17, 2025
1 parent 1d1af1f commit 48d4ded
Show file tree
Hide file tree
Showing 373 changed files with 22,042 additions and 1,399 deletions.
903 changes: 0 additions & 903 deletions internal/services/datafactory/azuresdkhacks/models.go

This file was deleted.

207 changes: 0 additions & 207 deletions internal/services/datafactory/azuresdkhacks/pipelines.go

This file was deleted.

12 changes: 8 additions & 4 deletions internal/services/datafactory/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/factories"
"github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/managedprivateendpoints"
"github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/managedvirtualnetworks"
"github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/pipelines"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
"github.com/jackofallops/kermit/sdk/datafactory/2018-06-01/datafactory" // nolint: staticcheck
)
Expand All @@ -19,13 +20,13 @@ type Client struct {
Credentials *credentials.CredentialsClient
ManagedPrivateEndpoints *managedprivateendpoints.ManagedPrivateEndpointsClient
ManagedVirtualNetworks *managedvirtualnetworks.ManagedVirtualNetworksClient
PipelinesClient *pipelines.PipelinesClient

// TODO: convert to using hashicorp/go-azure-sdk
DataFlowClient *datafactory.DataFlowsClient
DatasetClient *datafactory.DatasetsClient
IntegrationRuntimesClient *datafactory.IntegrationRuntimesClient
LinkedServiceClient *datafactory.LinkedServicesClient
PipelinesClient *datafactory.PipelinesClient
TriggersClient *datafactory.TriggersClient
}

Expand Down Expand Up @@ -67,8 +68,11 @@ func NewClient(o *common.ClientOptions) (*Client, error) {
LinkedServiceClient := datafactory.NewLinkedServicesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&LinkedServiceClient.Client, o.ResourceManagerAuthorizer)

PipelinesClient := datafactory.NewPipelinesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&PipelinesClient.Client, o.ResourceManagerAuthorizer)
PipelinesClient, err := pipelines.NewPipelinesClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building Pipelines client: %+v", err)
}
o.Configure(PipelinesClient.Client, o.Authorizers.ResourceManager)

TriggersClient := datafactory.NewTriggersClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&TriggersClient.Client, o.ResourceManagerAuthorizer)
Expand All @@ -78,13 +82,13 @@ func NewClient(o *common.ClientOptions) (*Client, error) {
Credentials: credentialsClient,
ManagedPrivateEndpoints: managedPrivateEndpointsClient,
ManagedVirtualNetworks: managedVirtualNetworksClient,
PipelinesClient: PipelinesClient,

// TODO: port to `hashicorp/go-azure-sdk`
DataFlowClient: &dataFlowClient,
DatasetClient: &DatasetClient,
IntegrationRuntimesClient: &IntegrationRuntimesClient,
LinkedServiceClient: &LinkedServiceClient,
PipelinesClient: &PipelinesClient,
TriggersClient: &TriggersClient,
}, nil
}
96 changes: 0 additions & 96 deletions internal/services/datafactory/data_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
package datafactory

import (
"encoding/json"
"fmt"
"log"
"sort"
"strings"

"github.com/hashicorp/terraform-provider-azurerm/internal/services/datafactory/azuresdkhacks"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/utils"
"github.com/jackofallops/kermit/sdk/datafactory/2018-06-01/datafactory" // nolint: staticcheck
Expand Down Expand Up @@ -66,37 +63,6 @@ func azureRmDataFactoryLinkedServiceConnectionStringDiff(_, old string, new stri
return true
}

func expandDataFactoryParameters(input map[string]interface{}) map[string]*datafactory.ParameterSpecification {
output := make(map[string]*datafactory.ParameterSpecification)

for k, v := range input {
output[k] = &datafactory.ParameterSpecification{
Type: datafactory.ParameterTypeString,
DefaultValue: v.(string),
}
}

return output
}

func flattenDataFactoryParameters(input map[string]*datafactory.ParameterSpecification) map[string]interface{} {
output := make(map[string]interface{})

for k, v := range input {
if v != nil {
// we only support string parameters at this time
val, ok := v.DefaultValue.(string)
if !ok {
log.Printf("[DEBUG] Skipping parameter %q since it's not a string", k)
}

output[k] = val
}
}

return output
}

func flattenDataFactoryAnnotations(input *[]interface{}) []string {
annotations := make([]string, 0)
if input == nil {
Expand All @@ -113,37 +79,6 @@ func flattenDataFactoryAnnotations(input *[]interface{}) []string {
return annotations
}

func expandDataFactoryVariables(input map[string]interface{}) map[string]*datafactory.VariableSpecification {
output := make(map[string]*datafactory.VariableSpecification)

for k, v := range input {
output[k] = &datafactory.VariableSpecification{
Type: datafactory.VariableTypeString,
DefaultValue: v.(string),
}
}

return output
}

func flattenDataFactoryVariables(input map[string]*datafactory.VariableSpecification) map[string]interface{} {
output := make(map[string]interface{})

for k, v := range input {
if v != nil {
// we only support string parameters at this time
val, ok := v.DefaultValue.(string)
if !ok {
log.Printf("[DEBUG] Skipping variable %q since it's not a string", k)
}

output[k] = val
}
}

return output
}

// DatasetColumn describes the attributes needed to specify a structure column for a dataset
type DatasetColumn struct {
Name string `json:"name,omitempty" tfschema:"name"`
Expand Down Expand Up @@ -290,37 +225,6 @@ func flattenDataFactorySnowflakeSchemaColumns(input interface{}) []interface{} {
return output
}

func deserializeDataFactoryPipelineActivities(jsonData string) (*[]datafactory.BasicActivity, error) {
jsonData = fmt.Sprintf(`{ "activities": %s }`, jsonData)
pipeline := &azuresdkhacks.Pipeline{}
err := pipeline.UnmarshalJSON([]byte(jsonData))
if err != nil {
return nil, err
}
return pipeline.Activities, nil
}

func serializeDataFactoryPipelineActivities(activities *[]datafactory.BasicActivity) (string, error) {
pipeline := &datafactory.Pipeline{Activities: activities}
result, err := pipeline.MarshalJSON()
if err != nil {
return "nil", err
}

var m map[string]*json.RawMessage
err = json.Unmarshal(result, &m)
if err != nil {
return "", err
}

activitiesJson, err := json.Marshal(m["activities"])
if err != nil {
return "", err
}

return string(activitiesJson), nil
}

func suppressJsonOrderingDifference(_, old, new string, _ *pluginsdk.ResourceData) bool {
return utils.NormalizeJson(old) == utils.NormalizeJson(new)
}
Expand Down
Loading

0 comments on commit 48d4ded

Please sign in to comment.