-
Notifications
You must be signed in to change notification settings - Fork 106
[bugfix] fix child classes to be queried only when apic versions allows (DCNE-589) #1407
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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)" |
| 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}} | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ import ( | |
| ) | ||
|
|
||
| var globalAnnotation string | ||
| var apicVersion string | ||
| var globalAllowExistingOnCreate bool | ||
|
|
||
| // Ensure AciProvider satisfies various provider interfaces. | ||
|
|
@@ -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 | ||
| } | ||
|
|
@@ -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{}) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this merge attributes with same value but not with different values?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 "" | ||
| } | ||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.