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

azurerm_data_factory_pipeline - support type for parameters and variables #27092

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
80 changes: 37 additions & 43 deletions internal/services/datafactory/data_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,35 +66,29 @@ 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),
func expandDataFactoryParameters(input []interface{}) map[string]*datafactory.ParameterSpecification {
parameters := make(map[string]*datafactory.ParameterSpecification)
for _, v := range input {
val := v.(map[string]interface{})
parameters[val["name"].(string)] = &datafactory.ParameterSpecification{
Type: datafactory.ParameterType(val["type"].(string)),
DefaultValue: val["default_value"],
stephybun marked this conversation as resolved.
Show resolved Hide resolved
}
}

return output
return parameters
}

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

func flattenDataFactoryParameters(input map[string]*datafactory.ParameterSpecification) []interface{} {
parameters := make([]interface{}, 0, len(input))
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
param := map[string]interface{}{
"name": k,
"type": string(v.Type),
"default_value": v.DefaultValue,
}
parameters = append(parameters, param)
}

return output
return parameters
}

func flattenDataFactoryAnnotations(input *[]interface{}) []string {
Expand All @@ -113,35 +107,35 @@ 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),
func expandDataFactoryVariables(input []interface{}) map[string]*datafactory.VariableSpecification {
variables := make(map[string]*datafactory.VariableSpecification)
for _, v := range input {
val := v.(map[string]interface{})
variables[val["name"].(string)] = &datafactory.VariableSpecification{
Type: datafactory.VariableType(val["type"].(string)),
DefaultValue: val["default_value"],
}
}

return output
return variables
}

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

func flattenDataFactoryVariables(input map[string]*datafactory.VariableSpecification) []interface{} {
variables := make([]interface{}, 0, len(input))
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)
}
// convert value to string if it is bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this only necessary for variable? How about parameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the api can do the conversion for parameters but not for variables

// this is needed because the API returns the default value as a bool
if _, ok := v.DefaultValue.(bool); ok {
v.DefaultValue = fmt.Sprintf("%v", v.DefaultValue)
}

output[k] = val
variable := map[string]interface{}{
"name": k,
"type": string(v.Type),
"default_value": v.DefaultValue,
}
variables = append(variables, variable)
}

return output
return variables
}

// DatasetColumn describes the attributes needed to specify a structure column for a dataset
Expand Down
70 changes: 57 additions & 13 deletions internal/services/datafactory/data_factory_pipeline_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,61 @@ func resourceDataFactoryPipeline() *pluginsdk.Resource {
},

"parameters": {
Type: pluginsdk.TypeMap,
Type: pluginsdk.TypeSet,
Optional: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"default_value": {
Type: pluginsdk.TypeString,
Required: true,
},
"type": {
Type: pluginsdk.TypeString,
Optional: true,
Default: string(datafactory.ParameterTypeString),
ValidateFunc: validation.StringInSlice([]string{
string(datafactory.ParameterTypeString),
string(datafactory.ParameterTypeInt),
string(datafactory.ParameterTypeFloat),
string(datafactory.ParameterTypeBool),
string(datafactory.ParameterTypeArray),
string(datafactory.ParameterTypeObject),
string(datafactory.ParameterTypeSecureString),
}, false),
},
},
},
},

"variables": {
Type: pluginsdk.TypeMap,
Type: pluginsdk.TypeSet,
Optional: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"default_value": {
Type: pluginsdk.TypeString,
Required: true,
},
"type": {
Type: pluginsdk.TypeString,
Optional: true,
Default: string(datafactory.VariableTypeString),
ValidateFunc: validation.StringInSlice([]string{
string(datafactory.VariableTypeString),
string(datafactory.VariableTypeArray),
}, false),
},
},
},
},

Expand Down Expand Up @@ -141,11 +184,12 @@ func resourceDataFactoryPipelineCreateUpdate(d *pluginsdk.ResourceData, meta int
}

pipeline := &azuresdkhacks.Pipeline{
Parameters: expandDataFactoryParameters(d.Get("parameters").(map[string]interface{})),
Variables: expandDataFactoryVariables(d.Get("variables").(map[string]interface{})),
Description: utils.String(d.Get("description").(string)),
}

pipeline.Parameters = expandDataFactoryParameters(d.Get("parameters").(*pluginsdk.Set).List())
pipeline.Variables = expandDataFactoryVariables(d.Get("variables").(*pluginsdk.Set).List())

if v, ok := d.GetOk("activities_json"); ok {
activities, err := deserializeDataFactoryPipelineActivities(v.(string))
if err != nil {
Expand Down Expand Up @@ -230,6 +274,11 @@ func resourceDataFactoryPipelineRead(d *pluginsdk.ResourceData, meta interface{}
return fmt.Errorf("setting `parameters`: %+v", err)
}

variables := flattenDataFactoryVariables(props.Variables)
if err := d.Set("variables", variables); err != nil {
return fmt.Errorf("setting `variables`: %+v", err)
}

annotations := flattenDataFactoryAnnotations(props.Annotations)
if err := d.Set("annotations", annotations); err != nil {
return fmt.Errorf("setting `annotations`: %+v", err)
Expand All @@ -255,11 +304,6 @@ func resourceDataFactoryPipelineRead(d *pluginsdk.ResourceData, meta interface{}
}
}

variables := flattenDataFactoryVariables(props.Variables)
if err := d.Set("variables", variables); err != nil {
return fmt.Errorf("setting `variables`: %+v", err)
}

if activities := props.Activities; activities != nil {
activitiesJson, err := serializeDataFactoryPipelineActivities(activities)
if err != nil {
Expand Down
Loading
Loading