Skip to content

Commit

Permalink
Allow full path variables when attaching devices
Browse files Browse the repository at this point in the history
  • Loading branch information
danischm committed Nov 22, 2023
1 parent 5856d6a commit 4ca8541
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Remove redundant `per_tunnel_qos` and `per_tunnel_qos_aggregator` attributes from `sdwan_cisco_vpn_interface_feature_template` resource and data source
- Add `base_action` attribute to `sdwan_custom_control_topology_policy_definition` resource and data source
- Add `base_action` attribute to `sdwan_traffic_data_policy_definition` resource and data source
- Allow full path variables in `sdwan_attach_feature_device_template` resource `variables` section

## 0.2.10

Expand Down
1 change: 1 addition & 0 deletions docs/guides/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ description: |-
- Remove redundant `per_tunnel_qos` and `per_tunnel_qos_aggregator` attributes from `sdwan_cisco_vpn_interface_feature_template` resource and data source
- Add `base_action` attribute to `sdwan_custom_control_topology_policy_definition` resource and data source
- Add `base_action` attribute to `sdwan_traffic_data_policy_definition` resource and data source
- Allow full path variables in `sdwan_attach_feature_device_template` resource `variables` section

## 0.2.10

Expand Down
31 changes: 22 additions & 9 deletions internal/provider/model_sdwan_attach_feature_device_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ func (data AttachFeatureDeviceTemplate) getVariables(ctx context.Context, client
// Resolve variable names and insert template variable values
var templateVariables map[string]string
item.Variables.ElementsAs(ctx, &templateVariables, false)
for k, _ := range variables {
for k := range variables {
_, ok := templateVariables[k]
if ok {
variables[k] = templateVariables[k]
continue
}
templateVariableName, ok := mappings[k]
if ok {
variables[k] = templateVariables[templateVariableName]
Expand Down Expand Up @@ -185,16 +190,16 @@ func (data *AttachFeatureDeviceTemplate) readVariables(ctx context.Context, clie
if len(varName) > 0 {
varName = varName[1 : len(varName)-1]
}
mappings[v.Get("property").String()] = varName
mappings[varName] = v.Get("property").String()
} else {
// handle factory default feature template variables
property := v.Get("property").String()
if property == "//system/host-name" {
mappings[property] = "system_host_name"
mappings["system_host_name"] = property
} else if property == "//system/system-ip" {
mappings[property] = "system_system_ip"
mappings["system_system_ip"] = property
} else if property == "//system/site-id" {
mappings[property] = "system_site_id"
mappings["system_site_id"] = property
}
}
}
Expand All @@ -209,15 +214,23 @@ func (data *AttachFeatureDeviceTemplate) readVariables(ctx context.Context, clie
return true
})
}

// Resolve variable names and insert template variable values
templateVariables := make(map[string]attr.Value)
for k, _ := range variables {
var templateVariables map[string]string
newTemplateVariables := make(map[string]attr.Value)
data.Devices[i].Variables.ElementsAs(ctx, &templateVariables, false)
for k := range templateVariables {
_, ok := variables[k]
if ok {
newTemplateVariables[k] = types.StringValue(variables[k])
continue
}
templateVariableName, ok := mappings[k]
if ok {
templateVariables[templateVariableName] = types.StringValue(variables[k])
newTemplateVariables[k] = types.StringValue(variables[templateVariableName])
}
}
data.Devices[i].Variables = types.MapValueMust(types.StringType, templateVariables)
data.Devices[i].Variables = types.MapValueMust(types.StringType, newTemplateVariables)
}

return nil
Expand Down
1 change: 1 addition & 0 deletions templates/guides/changelog.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ description: |-
- Remove redundant `per_tunnel_qos` and `per_tunnel_qos_aggregator` attributes from `sdwan_cisco_vpn_interface_feature_template` resource and data source
- Add `base_action` attribute to `sdwan_custom_control_topology_policy_definition` resource and data source
- Add `base_action` attribute to `sdwan_traffic_data_policy_definition` resource and data source
- Allow full path variables in `sdwan_attach_feature_device_template` resource `variables` section

## 0.2.10

Expand Down

0 comments on commit 4ca8541

Please sign in to comment.