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
3 changes: 2 additions & 1 deletion gen/definitions/classes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,7 @@ fvRsBDToProfile:

fvRsBDToRelayP:
resource_name: "relation_from_bridge_domain_to_dhcp_relay_policy"
class_version: "1.0(1e)-6.1(1e)"

fvRsCtx:
resource_name: "relation_to_vrf"
Expand Down Expand Up @@ -1082,7 +1083,7 @@ commPol:
sub_category: "Fabric Policies"
ui_locations:
- "Fabric -> Fabric Policies -> Policies -> Pod -> Management Access"
class_version: "6.0(2h)-6.0(8g),6.1(3f)-"
class_version_tests: "6.0(2h)-6.0(8g),6.1(3f)-"
contained_by:
- "polUni"
rn_prepend: "fabric"
Expand Down
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 @@ -1277,6 +1337,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 @@ -2027,15 +2088,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 @@ -2795,10 +2861,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[interface{}]interface{}) {
if key.(string) == "class_version" {
if key.(string) == matchKey {
return value.(string)
}
}
Expand Down
14 changes: 14 additions & 0 deletions gen/templates/class_versions.go.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 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


func classVersions() map[string]string {
return map[string]string{
{{- range $key, $value := . }}
"{{$key}}": "{{$value}}",
{{- end}}
}
}
37 changes: 37 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,37 @@ 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, fmt.Sprintf("/api/node/class/topSystem.json"), "GET", nil)
if diags.HasError() {
return ""
}

if requestData.Search("imdata").Search("topSystem").Data() != nil {
attributes := requestData.Search("imdata").Search("topSystem").Search("attributes").Data().([]interface{})
var versions []string
for _, attributeMap := range attributes {
if role, ok := attributeMap.(map[string]interface{})["role"]; ok && role == "controller" {
if v, ok := attributeMap.(map[string]interface{})["version"]; ok {
versions = append(versions, v.(string))

}
}
}
if len(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 topSysytem 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