Skip to content

Resolve import issue #489

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

Merged
merged 9 commits into from
Aug 8, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.6.3 (unreleased)

- BREAKING CHANGE: Rename `tls_ssl_profile_version` attribute of `sdwan_tls_ssl_decryption_policy_definition` resource to `tls_ssl_profile_policy_version`
- BREAKING CHANGE: Rename `sla_class_list` attribute of `sdwan_application_aware_routing_policy_definition` resource to `sla_class_list_id`
- BREAKING CHANGE: Rename `preferred_color_group_list` attribute of `sdwan_application_aware_routing_policy_definition` resource to `preferred_color_group_list_id`
- BREAKING CHANGE: Rename `preferred_color_group_list` attribute of `sdwan_traffic_data_policy_definition` resource to `preferred_color_group_list_id`

## 0.6.2

- Fix issue causing changes to applied feature templates to fail, [link](https://github.com/CiscoDevNet/terraform-provider-sdwan/issues/417)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ Read-Only:
Read-Only:

- `preferred_color` (String) preferred color (Single value or multiple values separated by spaces)
- `preferred_color_group_list` (String) Preferred color group list ID
- `preferred_color_group_list_id` (String) Preferred color group list ID
- `preferred_color_group_list_version` (Number) Preferred color group list version
- `sla_class_list` (String) SLA class list ID
- `sla_class_list_id` (String) SLA class list ID
- `sla_class_list_version` (Number) SLA class list version
- `type` (String) Type of SLA class parameter

Expand Down
2 changes: 1 addition & 1 deletion docs/data-sources/tls_ssl_decryption_policy_definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ Read-Only:
- `rule_name` (String) Country
- `target_vpns` (Set of String) List of VPN IDs
- `tls_ssl_profile_policy_id` (String) TLS SSL Profile Policy ID
- `tls_ssl_profile_version` (Number) TLS SSL Profile Policy version
- `tls_ssl_profile_policy_version` (Number) TLS SSL Profile Policy version
2 changes: 1 addition & 1 deletion docs/data-sources/traffic_data_policy_definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Read-Only:
- `next_hop_loose` (Boolean) Use routing table entry to forward the packet in case Next-hop is not available
- `policer_list_id` (String) Policer list ID
- `policer_list_version` (Number) Policer list version
- `preferred_color_group_list` (String) Preferred color group list ID
- `preferred_color_group_list_id` (String) Preferred color group list ID
- `preferred_color_group_list_version` (Number) Preferred color group list version
- `service_tloc_color` (String) Service TLOC color
- `service_tloc_encapsulation` (String) Service TLOC encapsulation
Expand Down
7 changes: 7 additions & 0 deletions docs/guides/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ description: |-

# Changelog

## 0.6.3 (unreleased)

- BREAKING CHANGE: Rename `tls_ssl_profile_version` attribute of `sdwan_tls_ssl_decryption_policy_definition` resource to `tls_ssl_profile_policy_version`
- BREAKING CHANGE: Rename `sla_class_list` attribute of `sdwan_application_aware_routing_policy_definition` resource to `sla_class_list_id`
- BREAKING CHANGE: Rename `preferred_color_group_list` attribute of `sdwan_application_aware_routing_policy_definition` resource to `preferred_color_group_list_id`
- BREAKING CHANGE: Rename `preferred_color_group_list` attribute of `sdwan_traffic_data_policy_definition` resource to `preferred_color_group_list_id`

## 0.6.2

- Fix issue causing changes to applied feature templates to fail, [link](https://github.com/CiscoDevNet/terraform-provider-sdwan/issues/417)
Expand Down
4 changes: 2 additions & 2 deletions docs/resources/application_aware_routing_policy_definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ Required:
Optional:

- `preferred_color` (String) preferred color (Single value or multiple values separated by spaces), Attribute conditional on `type` being equal to `preferredColor`
- `preferred_color_group_list` (String) Preferred color group list ID, Attribute conditional on `type` being equal to `preferredColorGroup`
- `preferred_color_group_list_id` (String) Preferred color group list ID, Attribute conditional on `type` being equal to `preferredColorGroup`
- `preferred_color_group_list_version` (Number) Preferred color group list version
- `sla_class_list` (String) SLA class list ID, Attribute conditional on `type` being equal to `name`
- `sla_class_list_id` (String) SLA class list ID, Attribute conditional on `type` being equal to `name`
- `sla_class_list_version` (Number) SLA class list version


Expand Down
2 changes: 1 addition & 1 deletion docs/resources/tls_ssl_decryption_policy_definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Optional:
- `rule_name` (String) Country
- `target_vpns` (Set of String) List of VPN IDs
- `tls_ssl_profile_policy_id` (String) TLS SSL Profile Policy ID
- `tls_ssl_profile_version` (Number) TLS SSL Profile Policy version
- `tls_ssl_profile_policy_version` (Number) TLS SSL Profile Policy version

## Import

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/traffic_data_policy_definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Optional:
- `next_hop_loose` (Boolean) Use routing table entry to forward the packet in case Next-hop is not available, Attribute conditional on `type` being equal to `nextHopLoose`
- `policer_list_id` (String) Policer list ID, Attribute conditional on `type` being equal to `policer`
- `policer_list_version` (Number) Policer list version
- `preferred_color_group_list` (String) Preferred color group list ID, Attribute conditional on `type` being equal to `preferredColorGroup`
- `preferred_color_group_list_id` (String) Preferred color group list ID, Attribute conditional on `type` being equal to `preferredColorGroup`
- `preferred_color_group_list_version` (Number) Preferred color group list version
- `service_tloc_color` (String) Service TLOC color, Attribute conditional on `type` being equal to `service`
- `service_tloc_encapsulation` (String) Service TLOC encapsulation, Attribute conditional on `type` being equal to `service`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ attributes:
description: Type of SLA class parameter
example: name
- model_name: ref
tf_name: sla_class_list
tf_name: sla_class_list_id
conditional_attribute:
name: type
value: name
Expand All @@ -331,7 +331,7 @@ attributes:
description: SLA class list version
exclude_test: true
- model_name: ref
tf_name: preferred_color_group_list
tf_name: preferred_color_group_list_id
conditional_attribute:
name: type
value: preferredColorGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ attributes:
type: String
description: TLS SSL Profile Policy ID
example: 2d8cbc1b-f969-4999-a0bd-f77a070ba5f7
- tf_name: tls_ssl_profile_version
- tf_name: tls_ssl_profile_policy_version
tf_only: true
type: Version
description: TLS SSL Profile Policy version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ attributes:
description: Policer list version
exclude_test: true
- model_name: ref
tf_name: preferred_color_group_list
tf_name: preferred_color_group_list_id
conditional_attribute:
name: type
value: preferredColorGroup
Expand Down
19 changes: 19 additions & 0 deletions gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,13 @@ func ToGoName(s string) string {
return s
}

func ToVersionName(s string) string {
s = ToGoName(s)
m := strings.ReplaceAll(s, "Versions", "Ids")
m = strings.ReplaceAll(m, "Version", "Id")
return m
}

// Templating helper function to convert string to camel case
func CamelCase(s string) string {
var g []string
Expand Down Expand Up @@ -397,6 +404,16 @@ func HasReference(attributes []YamlConfigAttribute) bool {
return false
}

// Templating helper function to return true if reference included in attributes
func HasStaticValue(attributes []YamlConfigAttribute) bool {
for _, attr := range attributes {
if attr.Value != "" {
return true
}
}
return false
}

// Templating helper function to return number of reference included in attributes
func CountReferences(attributes []YamlConfigAttribute) int {
count := 0
Expand Down Expand Up @@ -547,6 +564,7 @@ func contains(s []string, str string) bool {
// Map of templating functions
var functions = template.FuncMap{
"toGoName": ToGoName,
"toVersionName": ToVersionName,
"camelCase": CamelCase,
"snakeCase": SnakeCase,
"sprintf": fmt.Sprintf,
Expand All @@ -557,6 +575,7 @@ var functions = template.FuncMap{
"hasVersionAttribute": HasVersionAttribute,
"getResponseModelPath": GetResponseModelPath,
"hasReference": HasReference,
"hasStaticValue": HasStaticValue,
"countReferences": CountReferences,
"add": Add,
"getGjsonType": GetGjsonType,
Expand Down
80 changes: 80 additions & 0 deletions gen/templates/generic/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Type types.String `tfsdk:"type"`
{{- end}}
}


{{ range .Attributes}}
{{- if not .Value}}
{{- $childName := toGoName .TfName}}
Expand Down Expand Up @@ -676,3 +677,82 @@ func (data *{{camelCase .Name}}) updateVersions(ctx context.Context, state *{{ca
}
{{end}}
// End of section. //template:end updateVersions

// Section below is generated&owned by "gen/generator.go". //template:begin processImport
func (data *{{camelCase .Name}}) processImport(ctx context.Context) {
{{- if .HasVersion}}
data.Version = types.Int64Value(0)
{{- end}}
{{- if .TypeValue}}
data.Type = types.StringValue("{{ .TypeValue }}")
{{- end}}
{{- range .Attributes}}
{{- $name := toGoName .TfName}}
{{- if not .Value}}
{{- if .Value}}
data.{{toGoName .TfName}} = {{if eq .Type "String"}}types.StringValue("{{ .Value }}"){{else if eq .Type "Bool"}}types.BoolValue({{ .Value }}){{else if eq .Type "List"}}{{ .Value }}{{else}}types.ListNull({{ .Value }}){{end}}
{{- end}}
{{- if eq .Type "Version"}}
if data.{{toVersionName .TfName}} != types.StringNull() {
data.{{toGoName .TfName}} = types.Int64Value(0)
}
{{- else if eq .Type "Versions"}}
if !data.{{toVersionName .TfName}}.IsNull() {
data.{{toGoName .TfName}} = types.ListNull(types.StringType)
}
{{- else if and (isNestedListSet .) (hasVersionAttribute .Attributes)}}
for i := range data.{{toGoName .TfName}} {

{{- range .Attributes}}
{{- $cname := toGoName .TfName}}
{{- if not .Value}}
{{- if eq .Type "Version"}}
if data.{{$name}}[i].{{toVersionName .TfName}} != types.StringNull() {
data.{{$name}}[i].{{toGoName .TfName}} = types.Int64Value(0)
}
{{- else if eq .Type "Versions"}}
if !data.{{$name}}[i].{{toVersionName .TfName}}.IsNull() {
data.{{$name}}[i].{{toGoName .TfName}} = types.ListNull(types.StringType)
}
{{- else if and (isNestedListSet .) (hasVersionAttribute .Attributes)}}
for ii := range data.{{$name}}[i].{{toGoName .TfName}} {

{{- range .Attributes}}
{{- $ccname := toGoName .TfName}}
{{- if not .Value}}
{{- if eq .Type "Version"}}
if data.{{$name}}[i].{{$cname}}[ii].{{toVersionName .TfName}} != types.StringNull() {
data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}} = types.Int64Value(0)
}
{{- else if eq .Type "Versions"}}
if !data.{{$name}}[i].{{$cname}}[ii].{{toVersionName .TfName}}.IsNull() {
data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}} = types.ListNull(types.StringType)
}
{{- else if and (isNestedListSet .) (hasVersionAttribute .Attributes)}}
for iii := range data.{{$name}}[i].{{$cname}}[ii].{{toGoName .TfName}} {

{{- range .Attributes}}
{{- if eq .Type "Version"}}
if data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toVersionName .TfName}} != types.StringNull() {
data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toGoName .TfName}} = types.Int64Value(0)
}
{{- else if eq .Type "Versions"}}
if !data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toVersionName .TfName}}.IsNull() {
data.{{$name}}[i].{{$cname}}[ii].{{$ccname}}[iii].{{toGoName .TfName}} = types.ListNull(types.StringType)
}
{{- end}}
{{- end}}
}
{{- end}}
{{- end}}
{{- end}}
}
{{- end}}
{{- end}}
{{- end}}
}
{{- end}}
{{- end}}
{{- end}}
}
// End of section. //template:end processImport
14 changes: 11 additions & 3 deletions gen/templates/generic/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,15 @@ func (r *{{camelCase .Name}}Resource) Read(ctx context.Context, req resource.Rea
}

state.fromBody(ctx, res)
{{- if .HasVersion}}
if state.Version.IsNull() {
state.Version = types.Int64Value(0)

{{- if and (not .NoImport) (or (hasVersionAttribute .Attributes) (hasStaticValue .Attributes))}}
imp, diags := helpers.IsFlagImporting(ctx, req)
if resp.Diagnostics.Append(diags...); resp.Diagnostics.HasError() {
return
}

if imp {
state.processImport(ctx)
}
{{- end}}

Expand Down Expand Up @@ -619,6 +625,8 @@ func (r *{{camelCase .Name}}Resource) ImportState(ctx context.Context, req resou
{{- else}}
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
{{- end}}

helpers.SetFlagImporting(ctx, true, resp.Private, &resp.Diagnostics)
}
{{- end}}
// End of section. //template:end import
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,15 @@ func (d *ApplicationAwareRoutingPolicyDefinitionDataSource) Schema(ctx context.C
MarkdownDescription: "Type of SLA class parameter",
Computed: true,
},
"sla_class_list": schema.StringAttribute{
"sla_class_list_id": schema.StringAttribute{
MarkdownDescription: "SLA class list ID",
Computed: true,
},
"sla_class_list_version": schema.Int64Attribute{
MarkdownDescription: "SLA class list version",
Computed: true,
},
"preferred_color_group_list": schema.StringAttribute{
"preferred_color_group_list_id": schema.StringAttribute{
MarkdownDescription: "Preferred color group list ID",
Computed: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (d *TLSSSLDecryptionPolicyDefinitionDataSource) Schema(ctx context.Context,
MarkdownDescription: "TLS SSL Profile Policy ID",
Computed: true,
},
"tls_ssl_profile_version": schema.Int64Attribute{
"tls_ssl_profile_policy_version": schema.Int64Attribute{
MarkdownDescription: "TLS SSL Profile Policy version",
Computed: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func (d *TrafficDataPolicyDefinitionDataSource) Schema(ctx context.Context, req
MarkdownDescription: "Policer list version",
Computed: true,
},
"preferred_color_group_list": schema.StringAttribute{
"preferred_color_group_list_id": schema.StringAttribute{
MarkdownDescription: "Preferred color group list ID",
Computed: true,
},
Expand Down
4 changes: 4 additions & 0 deletions internal/provider/model_sdwan_activate_centralized_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,7 @@ func (data ActivateCentralizedPolicy) getPushBody(ctx context.Context, client *s
attachPayload, _ := sjson.Set("", "deviceTemplateList", deviceTemplateList)
return attachPayload, nil
}

// Section below is generated&owned by "gen/generator.go". //template:begin processImport

// End of section. //template:end processImport
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,22 @@ func (data *AdvancedInspectionProfilePolicyDefinition) updateVersions(ctx contex
}

// End of section. //template:end updateVersions

// Section below is generated&owned by "gen/generator.go". //template:begin processImport
func (data *AdvancedInspectionProfilePolicyDefinition) processImport(ctx context.Context) {
data.Version = types.Int64Value(0)
if data.IntrusionPreventionId != types.StringNull() {
data.IntrusionPreventionVersion = types.Int64Value(0)
}
if data.UrlFilteringId != types.StringNull() {
data.UrlFilteringVersion = types.Int64Value(0)
}
if data.AdvancedMalwareProtectionId != types.StringNull() {
data.AdvancedMalwareProtectionVersion = types.Int64Value(0)
}
if data.TlsSslDecryptionId != types.StringNull() {
data.TlsSslDecryptionVersion = types.Int64Value(0)
}
}

// End of section. //template:end processImport
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,10 @@ func (data *AdvancedMalwareProtectionPolicyDefinition) hasChanges(ctx context.Co
// Section below is generated&owned by "gen/generator.go". //template:begin updateVersions

// End of section. //template:end updateVersions

// Section below is generated&owned by "gen/generator.go". //template:begin processImport
func (data *AdvancedMalwareProtectionPolicyDefinition) processImport(ctx context.Context) {
data.Version = types.Int64Value(0)
}

// End of section. //template:end processImport
7 changes: 7 additions & 0 deletions internal/provider/model_sdwan_allow_url_list_policy_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,10 @@ func (data *AllowURLListPolicyObject) hasChanges(ctx context.Context, state *All
// Section below is generated&owned by "gen/generator.go". //template:begin updateVersions

// End of section. //template:end updateVersions

// Section below is generated&owned by "gen/generator.go". //template:begin processImport
func (data *AllowURLListPolicyObject) processImport(ctx context.Context) {
data.Version = types.Int64Value(0)
}

// End of section. //template:end processImport
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,10 @@ func (data *AppProbeClassPolicyObject) hasChanges(ctx context.Context, state *Ap
// Section below is generated&owned by "gen/generator.go". //template:begin updateVersions

// End of section. //template:end updateVersions

// Section below is generated&owned by "gen/generator.go". //template:begin processImport
func (data *AppProbeClassPolicyObject) processImport(ctx context.Context) {
data.Version = types.Int64Value(0)
}

// End of section. //template:end processImport
Loading