Skip to content

Commit

Permalink
[bugfix] Fix to set version to match the pre-migration version when a…
Browse files Browse the repository at this point in the history
… resource is migrated without changes
  • Loading branch information
akinross authored and lhercot committed Sep 4, 2024
1 parent 6513b85 commit 8058e84
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions gen/definitions/classes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ rtctrlProfile:
- "Tenants -> Networking -> L3Outs -> Route map for import and export Route Control"
- "Tenants -> Policies -> Protocol -> Route Maps for Route Control"
sub_category: "L3Out"
migration_version: 1

vzOOBBrCP:
resource_name: "out_of_band_contract"
Expand Down Expand Up @@ -252,6 +253,7 @@ tagAnnotation:
- "Too many DN formats to display, see model documentation for all possible parents of [tagAnnotation](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/tagAnnotation/overview)."

tagTag:
migration_version: 1
ui_locations:
- "Under every object as Policy Tags in the Operational tab in recent APIC versions."
resource_notes:
Expand Down
17 changes: 12 additions & 5 deletions gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1006,10 +1006,13 @@ func (m *Model) setClassModel(metaPath string, child bool, definitions Definitio
}
}

if isMigrationResource(m.PkgName, definitions) {
version, changes := isMigrationResource(m.PkgName, definitions)
if version {
m.SetMigrationVersion(definitions)
}
if changes {
m.SetMigrationClassTypes(definitions)
m.SetLegacyChildren(definitions)
m.SetMigrationVersion(definitions)
m.SetLegacyAttributes(definitions)
}

Expand Down Expand Up @@ -2134,15 +2137,19 @@ func (m *Model) GetOverwriteAttributeMigration(definitions Definitions, attribut
return nil
}

func isMigrationResource(classPkgName string, definitions Definitions) bool {
func isMigrationResource(classPkgName string, definitions Definitions) (bool, bool) {
version := false
changes := false
if v, ok := definitions.Classes[classPkgName]; ok {
for key := range v.(map[interface{}]interface{}) {
if key.(string) == "migration_blocks" {
return true
changes = true
} else if key.(string) == "migration_version" {
version = true
}
}
}
return false
return version, changes
}

// Set variables that are used during the rendering of the example and documentation templates
Expand Down
2 changes: 2 additions & 0 deletions gen/templates/resource.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,8 @@ func (r *{{.ResourceClassName}}Resource) Schema(ctx context.Context, req resourc
MarkdownDescription: "The {{.ResourceName}} resource for the '{{.PkgName}}' class",
{{- if .LegacyAttributes}}
Version: {{add .LegacySchemaVersion 1}},
{{- else if .LegacySchemaVersion}}
Version: {{.LegacySchemaVersion}},
{{- end}}

Attributes: map[string]schema.Attribute{
Expand Down
1 change: 1 addition & 0 deletions internal/provider/resource_aci_route_control_profile.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions internal/provider/resource_aci_tag.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8058e84

Please sign in to comment.