Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1,250 changes: 651 additions & 599 deletions gen/templates/generic/model.go

Large diffs are not rendered by default.

46 changes: 43 additions & 3 deletions internal/provider/model_sdwan_centralized_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"

"github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
Expand Down Expand Up @@ -310,13 +311,52 @@ func (data *CentralizedPolicy) processImport(ctx context.Context) {
}
for ii := range data.Definitions[i].Entries {
if !data.Definitions[i].Entries[ii].SiteListIds.IsNull() {
data.Definitions[i].Entries[ii].SiteListVersions = types.ListNull(types.StringType)
var elementsSiteListVersions []attr.Value
var countSiteListVersions int = 0
if !(data.Definitions[i].Entries[ii].SiteListIds.IsNull() || data.Definitions[i].Entries[ii].SiteListIds.IsUnknown()) {
countSiteListVersions = len(data.Definitions[i].Entries[ii].SiteListIds.Elements())
}
if countSiteListVersions > 0 {
elementsSiteListVersions = make([]attr.Value, countSiteListVersions)
for i := 0; i < countSiteListVersions; i++ {
elementsSiteListVersions[i] = types.StringValue("0")
}
data.Definitions[i].Entries[ii].SiteListVersions = types.ListValueMust(types.StringType, elementsSiteListVersions)
} else {
data.Definitions[i].Entries[ii].SiteListVersions = types.ListNull(types.StringType)
}
}
if !data.Definitions[i].Entries[ii].VpnListIds.IsNull() {
data.Definitions[i].Entries[ii].VpnListVersions = types.ListNull(types.StringType)
var elementsVpnListVersions []attr.Value
var countVpnListVersions int = 0
if !(data.Definitions[i].Entries[ii].VpnListIds.IsNull() || data.Definitions[i].Entries[ii].VpnListIds.IsUnknown()) {
countVpnListVersions = len(data.Definitions[i].Entries[ii].VpnListIds.Elements())
}
if countVpnListVersions > 0 {
elementsVpnListVersions = make([]attr.Value, countVpnListVersions)
for i := 0; i < countVpnListVersions; i++ {
elementsVpnListVersions[i] = types.StringValue("0")
}
data.Definitions[i].Entries[ii].VpnListVersions = types.ListValueMust(types.StringType, elementsVpnListVersions)
} else {
data.Definitions[i].Entries[ii].VpnListVersions = types.ListNull(types.StringType)
}
}
if !data.Definitions[i].Entries[ii].RegionListIds.IsNull() {
data.Definitions[i].Entries[ii].RegionListVersions = types.ListNull(types.StringType)
var elementsRegionListVersions []attr.Value
var countRegionListVersions int = 0
if !(data.Definitions[i].Entries[ii].RegionListIds.IsNull() || data.Definitions[i].Entries[ii].RegionListIds.IsUnknown()) {
countRegionListVersions = len(data.Definitions[i].Entries[ii].RegionListIds.Elements())
}
if countRegionListVersions > 0 {
elementsRegionListVersions = make([]attr.Value, countRegionListVersions)
for i := 0; i < countRegionListVersions; i++ {
elementsRegionListVersions[i] = types.StringValue("0")
}
data.Definitions[i].Entries[ii].RegionListVersions = types.ListValueMust(types.StringType, elementsRegionListVersions)
} else {
data.Definitions[i].Entries[ii].RegionListVersions = types.ListNull(types.StringType)
}
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions internal/provider/model_sdwan_configuration_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,3 +568,22 @@ func (data ConfigurationGroup) hasFeatureVersionChanges(ctx context.Context, sta
}
return false
}

func (data ConfigurationGroup) processImport(ctx context.Context) {
var elementsFeatureList []attr.Value
var countFeatureProfile int = 0

if !(data.FeatureProfileIds.IsNull() || data.FeatureProfileIds.IsUnknown()) {
countFeatureProfile = len(data.FeatureProfileIds.Elements())
}

if countFeatureProfile > 0 {
elementsFeatureList = make([]attr.Value, countFeatureProfile)
for i := 0; i < countFeatureProfile; i++ {
elementsFeatureList[i] = types.Int64Value(0)
}
data.FeatureVersions = types.ListValueMust(types.Int64Type, elementsFeatureList)
} else {
data.FeatureVersions = types.ListNull(types.StringType)
}
}
16 changes: 15 additions & 1 deletion internal/provider/model_sdwan_mesh_topology_policy_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"

"github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
Expand Down Expand Up @@ -199,7 +200,20 @@ func (data *MeshTopologyPolicyDefinition) processImport(ctx context.Context) {
}
for i := range data.Regions {
if !data.Regions[i].SiteListIds.IsNull() {
data.Regions[i].SiteListVersions = types.ListNull(types.StringType)
var elementsSiteListVersions []attr.Value
var countSiteListVersions int = 0
if !(data.Regions[i].SiteListIds.IsNull() || data.Regions[i].SiteListIds.IsUnknown()) {
countSiteListVersions = len(data.Regions[i].SiteListIds.Elements())
}
if countSiteListVersions > 0 {
elementsSiteListVersions = make([]attr.Value, countSiteListVersions)
for i := 0; i < countSiteListVersions; i++ {
elementsSiteListVersions[i] = types.StringValue("0")
}
data.Regions[i].SiteListVersions = types.ListValueMust(types.StringType, elementsSiteListVersions)
} else {
data.Regions[i].SiteListVersions = types.ListNull(types.StringType)
}
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions internal/provider/model_sdwan_policy_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,22 @@ func (data PolicyGroup) hasPolicyVersionChanges(ctx context.Context, state *Poli
}
return false
}

func (data PolicyGroup) processImport(ctx context.Context) {
var elementsFeatureList []attr.Value
var countFeatureProfile int = 0

if !(data.FeatureProfileIds.IsNull() || data.FeatureProfileIds.IsUnknown()) {
countFeatureProfile = len(data.FeatureProfileIds.Elements())
}

if countFeatureProfile > 0 {
elementsFeatureList = make([]attr.Value, countFeatureProfile)
for i := 0; i < countFeatureProfile; i++ {
elementsFeatureList[i] = types.Int64Value(0)
}
data.PolicyVersions = types.ListValueMust(types.Int64Type, elementsFeatureList)
} else {
data.PolicyVersions = types.ListNull(types.StringType)
}
}
16 changes: 15 additions & 1 deletion internal/provider/model_sdwan_route_policy_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"

"github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
Expand Down Expand Up @@ -743,7 +744,20 @@ func (data *RoutePolicyDefinition) processImport(ctx context.Context) {
data.Sequences[i].MatchEntries[ii].AsPathListVersion = types.Int64Value(0)
}
if !data.Sequences[i].MatchEntries[ii].CommunityListIds.IsNull() {
data.Sequences[i].MatchEntries[ii].CommunityListVersions = types.ListNull(types.StringType)
var elementsCommunityListVersions []attr.Value
var countCommunityListVersions int = 0
if !(data.Sequences[i].MatchEntries[ii].CommunityListIds.IsNull() || data.Sequences[i].MatchEntries[ii].CommunityListIds.IsUnknown()) {
countCommunityListVersions = len(data.Sequences[i].MatchEntries[ii].CommunityListIds.Elements())
}
if countCommunityListVersions > 0 {
elementsCommunityListVersions = make([]attr.Value, countCommunityListVersions)
for i := 0; i < countCommunityListVersions; i++ {
elementsCommunityListVersions[i] = types.StringValue("0")
}
data.Sequences[i].MatchEntries[ii].CommunityListVersions = types.ListValueMust(types.StringType, elementsCommunityListVersions)
} else {
data.Sequences[i].MatchEntries[ii].CommunityListVersions = types.ListNull(types.StringType)
}
}
if data.Sequences[i].MatchEntries[ii].ExpandedCommunityListId != types.StringNull() {
data.Sequences[i].MatchEntries[ii].ExpandedCommunityListVersion = types.Int64Value(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"

"github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
Expand Down Expand Up @@ -191,7 +192,20 @@ func (data *VPNMembershipPolicyDefinition) processImport(ctx context.Context) {
data.Sites[i].SiteListVersion = types.Int64Value(0)
}
if !data.Sites[i].VpnListIds.IsNull() {
data.Sites[i].VpnListVersions = types.ListNull(types.StringType)
var elementsVpnListVersions []attr.Value
var countVpnListVersions int = 0
if !(data.Sites[i].VpnListIds.IsNull() || data.Sites[i].VpnListIds.IsUnknown()) {
countVpnListVersions = len(data.Sites[i].VpnListIds.Elements())
}
if countVpnListVersions > 0 {
elementsVpnListVersions = make([]attr.Value, countVpnListVersions)
for i := 0; i < countVpnListVersions; i++ {
elementsVpnListVersions[i] = types.StringValue("0")
}
data.Sites[i].VpnListVersions = types.ListValueMust(types.StringType, elementsVpnListVersions)
} else {
data.Sites[i].VpnListVersions = types.ListNull(types.StringType)
}
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions internal/provider/resource_sdwan_configuration_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ func (r *ConfigurationGroupResource) Create(ctx context.Context, req resource.Cr

diags = resp.State.Set(ctx, &plan)
resp.Diagnostics.Append(diags...)

helpers.SetFlagImporting(ctx, false, resp.Private, &resp.Diagnostics)
}

func (r *ConfigurationGroupResource) Deploy(ctx context.Context, plan ConfigurationGroup, state *ConfigurationGroup, diag *diag.Diagnostics, deleteOnError bool) {
Expand Down Expand Up @@ -350,6 +352,15 @@ func (r *ConfigurationGroupResource) Read(ctx context.Context, req resource.Read

state.fromBodyConfigGroup(ctx, res)

imp, diags := helpers.IsFlagImporting(ctx, req)
if resp.Diagnostics.Append(diags...); resp.Diagnostics.HasError() {
return
}

if imp {
state.processImport(ctx)
}

// Read config group device associations
if value := res.Get("devices"); value.Exists() && len(value.Array()) > 0 {
path := fmt.Sprintf("/v1/config-group/%v/device/associate/", state.Id.ValueString())
Expand Down Expand Up @@ -386,6 +397,8 @@ func (r *ConfigurationGroupResource) Read(ctx context.Context, req resource.Read

diags = resp.State.Set(ctx, &state)
resp.Diagnostics.Append(diags...)

helpers.SetFlagImporting(ctx, false, resp.Private, &resp.Diagnostics)
}

func (r *ConfigurationGroupResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
Expand Down
13 changes: 13 additions & 0 deletions internal/provider/resource_sdwan_policy_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ func (r *PolicyGroupResource) Create(ctx context.Context, req resource.CreateReq

diags = resp.State.Set(ctx, &plan)
resp.Diagnostics.Append(diags...)

helpers.SetFlagImporting(ctx, false, resp.Private, &resp.Diagnostics)
}

func (r *PolicyGroupResource) Deploy(ctx context.Context, plan PolicyGroup, state *PolicyGroup, diag *diag.Diagnostics, deleteOnError bool) {
Expand Down Expand Up @@ -303,6 +305,15 @@ func (r *PolicyGroupResource) Read(ctx context.Context, req resource.ReadRequest

state.fromBodyPolicyGroup(ctx, res)

imp, diags := helpers.IsFlagImporting(ctx, req)
if resp.Diagnostics.Append(diags...); resp.Diagnostics.HasError() {
return
}

if imp {
state.processImport(ctx)
}

// Read policy group device associations
path := fmt.Sprintf("/v1/policy-group/%v/device/associate/", state.Id.ValueString())
res, err = r.client.Get(path)
Expand Down Expand Up @@ -335,6 +346,8 @@ func (r *PolicyGroupResource) Read(ctx context.Context, req resource.ReadRequest

diags = resp.State.Set(ctx, &state)
resp.Diagnostics.Append(diags...)

helpers.SetFlagImporting(ctx, false, resp.Private, &resp.Diagnostics)
}

func (r *PolicyGroupResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
Expand Down
Loading