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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion docs/data-sources/bridge_domain.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ data "aci_bridge_domain" "example_tenant" {
* `tags` - (list) A list of Tags (ACI object [tagTag](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/tagTag/overview)). This attribute is supported in ACI versions: 3.2(1l) and later.
* `key` (key) - (string) The key used to uniquely identify this configuration object.
* `value` (value) - (string) The value of the property.
* `relation_to_dhcp_relay_policy` - (map) A map of Relation From Bridge Domain To DHCP Relay Policy (ACI object [fvRsBDToRelayP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvRsBDToRelayP/overview)) pointing to DHCP Relay Policy (ACI Object [dhcpRelayP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/dhcpRelayP/overview)).
* `relation_to_dhcp_relay_policy` - (map) A map of Relation From Bridge Domain To DHCP Relay Policy (ACI object [fvRsBDToRelayP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvRsBDToRelayP/overview)) pointing to DHCP Relay Policy (ACI Object [dhcpRelayP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/dhcpRelayP/overview)). This attribute is supported in ACI versions: 1.0(1e) to 6.1(1e)
* `annotation` (annotation) - (string) The annotation of the Relation From Bridge Domain To DHCP Relay Policy object. This attribute is supported in ACI versions: 3.2(1l) and later.
* `dhcp_relay_policy_name` (tnDhcpRelayPName) - (string) The name of the DHCP Relay Policy object.
* `annotations` - (list) A list of Annotations (ACI object [tagAnnotation](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/tagAnnotation/overview)). This attribute is supported in ACI versions: 3.2(1l) and later.
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/bridge_domain.md
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ All examples for the Bridge Domain resource can be found in the [examples](https

* `key` (key) - (string) The key used to uniquely identify this configuration object.
* `value` (value) - (string) The value of the property.
* `relation_to_dhcp_relay_policy` - (map) A map of Relation From Bridge Domain To DHCP Relay Policy (ACI object [fvRsBDToRelayP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvRsBDToRelayP/overview)) pointing to DHCP Relay Policy (ACI Object [dhcpRelayP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/dhcpRelayP/overview)) which can be configured using the [aci_dhcp_relay_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/dhcp_relay_policy) resource.
* `relation_to_dhcp_relay_policy` - (map) A map of Relation From Bridge Domain To DHCP Relay Policy (ACI object [fvRsBDToRelayP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvRsBDToRelayP/overview)) pointing to DHCP Relay Policy (ACI Object [dhcpRelayP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/dhcpRelayP/overview)) which can be configured using the [aci_dhcp_relay_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/dhcp_relay_policy) resource. This attribute is supported in ACI versions: 1.0(1e) to 6.1(1e)
#### Optional ####

* `annotation` (annotation) - (string) The annotation of the Relation From Bridge Domain To DHCP Relay Policy object. This attribute is supported in ACI versions: 3.2(1l) and later.
Expand Down
2 changes: 1 addition & 1 deletion gen/definitions/classes/commPol.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class_version: 6.0(2h)-6.0(8g),6.1(3f)-
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't it be defined for both?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was done only for testing, the commPol class itself is supported but there was some behaviour of the class which made us skip it in those versions of testing. I did not want to change this behaviour but I needed a way to mention deprecated class like the case of fvRsBDToRelayP. So the class_version is now use for overall override of the class version when not in meta. The class_version_tests is only applied to the tests.

class_version_tests: 6.0(2h)-6.0(8g),6.1(3f)-
contained_by:
- polUni
resource_name: management_access_policy
Expand Down
1 change: 1 addition & 0 deletions gen/definitions/classes/fvRsBDToRelayP.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
resource_name: relation_from_bridge_domain_to_dhcp_relay_policy
class_version: "1.0(1e)-6.1(1e)"
86 changes: 79 additions & 7 deletions gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,63 @@ var templateFuncs = template.FuncMap{
"getCustomTestDependency": GetCustomTestDependency,
"getIgnoreInLegacy": GetIgnoreInLegacy,
"isSensitiveAttribute": IsSensitiveAttribute,
"getChildVersion": GetChildVersion,
"getChildClassNames": GetChildClassNames,
"getLegacyAttributeVersion": GetLegacyAttributeVersion,
"getLegacyAttributeVersionInTest": GetLegacyAttributeVersionInTest,
}

func GetChildClassNames(model Model, childClassNames []string) []string {

if childClassNames == nil {
childClassNames = []string{}
}

for _, child := range model.Children {
if !slices.Contains(childClassNames, child.PkgName) {
childClassNames = append(childClassNames, child.PkgName)
}

if child.HasChild {
childClassNames = GetChildClassNames(child, childClassNames)
}

}
sort.Strings(childClassNames)
return childClassNames
}

func GetLegacyAttributeVersion(attributename string, model Model) string {

for _, property := range model.Properties {
if property.Name == attributename {
return property.RawVersion
}
}

for _, child := range model.Children {
if child.ResourceClassName == attributename {
return child.RawVersions
}
}

return "no_version_found"
}

func GetLegacyAttributeVersionInTest(attributename string, versions interface{}) string {

if version, ok := versions.(map[interface{}]interface{})[attributename]; ok {
return version.(string)
}
return "no_version_found"
}

func GetChildVersion(children []interface{}) string {

if versions, ok := children[0].(map[interface{}]interface{})["child_versions"]; ok {
return versions.(string)
}
return ""
}

func IsSensitiveAttribute(attributeName string, properties map[string]Property) bool {
Expand Down Expand Up @@ -524,6 +581,7 @@ func GetNewChildAttributes(legacyAttributes map[string]LegacyAttribute, properti
var labels = []string{"dns_provider", "filter_entry"}
var duplicateLabels = []string{}
var resourceNames = map[string]string{}
var classVersions = map[string]string{}
var targetRelationalPropertyClasses = map[string]string{}
var alwaysIncludeChildren = []string{"tag:Annotation", "tag:Tag"}
var excludeChildResourceNamesFromDocs = []string{"", "annotation", "tag"}
Expand Down Expand Up @@ -969,6 +1027,8 @@ func renderTemplate(templateName, outputFileName, outputPath string, outputData
err = tmpl.Execute(&buffer, outputData.([]string))
} else if strings.Contains(templateName, "custom_type.go.tmpl") {
err = tmpl.Execute(&buffer, outputData.(Property))
} else if strings.Contains(templateName, "class_versions.go.tmpl") {
err = tmpl.Execute(&buffer, outputData.(map[string]string))
} else {
err = tmpl.Execute(&buffer, outputData.(Model))
}
Expand Down Expand Up @@ -1293,6 +1353,7 @@ func main() {
classModels := getClassModels(definitions)
annotationUnsupported := generateAnnotationUnsupported()

renderTemplate("class_versions.go.tmpl", "versions.go", providerPath, classVersions)
renderTemplate("provider.go.tmpl", "provider.go", providerPath, classModels)
renderTemplate("index.md.tmpl", "index.md", docsPath, ProviderModel{Example: string(getExampleCode(providerExamplePath))})
if len(annotationUnsupported) > 0 {
Expand Down Expand Up @@ -2055,15 +2116,20 @@ func (m *Model) SetClassComment(classDetails interface{}) {
}

func (m *Model) SetClassVersions(classDetails interface{}) {
versions, ok := classDetails.(map[string]interface{})["versions"]
if ok {
m.RawVersions = versions.(string)
m.Versions = formatVersion(versions.(string))

m.RawVersions = GetOverwriteClassVersion(m.PkgName, m.Definitions, false)
if m.RawVersions == "" {
v, ok := classDetails.(map[string]interface{})["versions"]
if ok {
m.RawVersions = v.(string)
}
}
m.Versions = formatVersion(m.RawVersions)
classVersions[m.PkgName] = m.RawVersions
}

func (m *Model) SetTestApplicableFromVersion(classDetails interface{}) {
m.ClassVersion = GetOverwriteClassVersion(m.PkgName, m.Definitions)
m.ClassVersion = GetOverwriteClassVersion(m.PkgName, m.Definitions, true)
if m.ClassVersion == "" {
versions, ok := classDetails.(map[string]interface{})["versions"]
if ok {
Expand Down Expand Up @@ -2823,10 +2889,16 @@ func GetOverwriteTestType(classPkgName string, definitions Definitions) string {
return ""
}

func GetOverwriteClassVersion(classPkgName string, definitions Definitions) string {
func GetOverwriteClassVersion(classPkgName string, definitions Definitions, tests bool) string {

matchKey := "class_version"
if tests {
matchKey = "class_version_tests"
}

if v, ok := definitions.Classes[classPkgName]; ok {
for key, value := range v.(map[string]interface{}) {
if key == "class_version" {
if key == matchKey {
return value.(string)
}
}
Expand Down
12 changes: 12 additions & 0 deletions gen/templates/class_versions.go.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Code generated by "gen/generator.go"; DO NOT EDIT.
// In order to regenerate this file execute `go generate` from the repository root.
// More details can be found in the [README](https://github.com/CiscoDevNet/terraform-provider-aci/blob/master/README.md).

package provider


var classVersions = map[string]string{
{{- range $key, $value := . }}
"{{$key}}": "{{$value}}",
{{- end}}
}
34 changes: 34 additions & 0 deletions gen/templates/provider.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
)

var globalAnnotation string
var apicVersion string
var globalAllowExistingOnCreate bool

// Ensure AciProvider satisfies various provider interfaces.
Expand Down Expand Up @@ -199,6 +200,8 @@ func (p *AciProvider) Configure(ctx context.Context, req provider.ConfigureReque
aciClient = client.GetClient(url, username, client.PrivateKey(privateKey), client.AdminCert(certName), client.Insecure(isInsecure), client.ProxyUrl(proxyUrl), client.ProxyCreds(proxyCreds), client.ValidateRelationDn(validateRelationDn), client.MaxRetries(maxRetries))
}

apicVersion = getVersionAPIC(ctx, &resp.Diagnostics, aciClient)

resp.DataSourceData = aciClient
resp.ResourceData = aciClient
}
Expand Down Expand Up @@ -354,3 +357,34 @@ func (p *AciProvider) Functions(ctx context.Context) []func() function.Function
NewCompareVersionsFunction,
}
}

func getVersionAPIC(ctx context.Context, diags *diag.Diagnostics, client *client.Client) string {
requestData := DoRestRequest(ctx, diags, client, "/api/node/class/topSystem.json?query-target-filter=eq(topSystem.role,\"controller\")", "GET", nil)
if diags.HasError() {
return ""
}

if requestData.Search("imdata").Search("topSystem").Data() != nil {
attributes := requestData.Search("imdata").Search("topSystem").Search("attributes").Data().([]interface{})
Copy link
Member

Choose a reason for hiding this comment

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

Does this merge attributes with same value but not with different values?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am not sure what you mean by this comment but I did spot an issue with the version appending. The duplicates should be removed for the length check

var versions []string
for _, attributeMap := range attributes {
if version, ok := attributeMap.(map[string]interface{})["version"].(string); ok {
versions = append(versions, version)
}
}
if len(slices.Compact(versions)) == 1 {
return versions[0]
}
diags.AddError(
"Controller version mismatch detected",
fmt.Sprintf("The versions of the APIC controllers must all match. Versions found: %s", versions),
)
} else {
diags.AddError(
"Data for topSystem class could not be retrieved",
fmt.Sprintf("The versions of the APIC controllers could not be determined"),
)
}

return ""
}
3 changes: 2 additions & 1 deletion gen/templates/resource.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2045,7 +2045,8 @@ func (r *{{.ResourceClassName}}Resource) ImportState(ctx context.Context, req re

func getAndSet{{.ResourceClassName}}Attributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *{{.ResourceClassName}}ResourceModel) {
{{- if .HasChild}}
requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), "{{- .PkgName}},{{ template "rspSubtreeClassFilter" . }}"), "GET", nil)
childClasses := getChildClassesForGetRequest([]string{ {{ range (getChildClassNames . nil)}}"{{.}}",{{ end}} })
requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=full&rsp-subtree-class=%s", data.Id.ValueString(), strings.Join(childClasses, ",")), "GET", nil)
{{- else}}
requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "GET", nil)
{{- end}}
Expand Down
Loading
Loading