Skip to content

Commit c984442

Browse files
committed
[ignore] temporary commit for review of new list resources
1 parent 3faee10 commit c984442

14 files changed

+1124
-9
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
# Documentation generated by "gen/generator.go"; DO NOT EDIT.
3+
# In order to regenerate this file execute `go generate` from the repository root.
4+
# More details can be found in the [README](https://github.com/CiscoDevNet/terraform-provider-aci/blob/master/README.md).
5+
subcategory: "Application Management"
6+
layout: "aci"
7+
page_title: "ACI: aci_relation_to_domain"
8+
sidebar_current: "docs-aci-list-resource-aci_relation_to_domain"
9+
description: |-
10+
Manages ACI Relation To Domain
11+
---
12+
13+
# aci_relation_to_domain #
14+
15+
List existing ACI Relation To Domain objects with the [terraform query](https://developer.hashicorp.com/terraform/cli/commands/query) command.
16+
17+
For more information about the usage see the official Hashicorp documentation for [importing existing resources in bulk](https://developer.hashicorp.com/terraform/language/v1.14.x/import/bulk?page=import&page=bulk).
18+
19+
## API Information ##
20+
21+
* Class: [fvRsDomAtt](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvRsDomAtt/overview)
22+
23+
* Supported in ACI versions: 1.0(1e) and later.
24+
25+
* Distinguished Name Format: `uni/tn-{name}/ap-{name}/epg-{name}/rsdomAtt-[{tDn}]`
26+
27+
## GUI Information ##
28+
29+
* Location: `Tenants -> Application Profiles -> Application EPGs -> Domains (VMs and Bare-Metals)`
30+
31+
## Example Usage ##
32+
33+
The configuration snippet below shows an example for Relation To Domain with only required attributes.
34+
35+
```hcl
36+
list "aci_relation_to_domain" "example" {
37+
provider = aci
38+
}
39+
```
40+
41+
The configuration snippet below shows an example for Relation To Domain with filter capabilties.
42+
43+
```hcl
44+
list "aci_relation_to_domain" "example" {
45+
provider = aci
46+
config {
47+
filter = "query-target-filter=eq(fvRsDomAtt.dn,\"uni/tn-{name}/ap-{name}/epg-{name}/rsdomAtt-[{tDn}]\")"
48+
}
49+
}
50+
```
51+
52+
## Schema ##
53+
54+
### Optional ###
55+
56+
* `config` - (map) A map that contains all configurable options for the list resource.
57+
58+
### Optional ###
59+
60+
* `filter` - (string) A filter to restrict the results of the class query to APIC. See [Cisco APIC REST API Configuration Guide, Release 4.2(x) and Later](https://www.cisco.com/c/en/us/td/docs/dcn/aci/apic/all/apic-rest-api-configuration-guide/cisco-apic-rest-api-configuration-guide-42x-and-later/m_using_the_rest_api.html#concept_1B75A78853DD46AABC15B048AAFAD1AD) for more information about composing filter query expressions.

docs/list-resources/tenant.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
# Documentation generated by "gen/generator.go"; DO NOT EDIT.
3+
# In order to regenerate this file execute `go generate` from the repository root.
4+
# More details can be found in the [README](https://github.com/CiscoDevNet/terraform-provider-aci/blob/master/README.md).
5+
subcategory: "Application Management"
6+
layout: "aci"
7+
page_title: "ACI: aci_tenant"
8+
sidebar_current: "docs-aci-list-resource-aci_tenant"
9+
description: |-
10+
Manages ACI Tenant
11+
---
12+
13+
# aci_tenant #
14+
15+
List existing ACI Tenant objects with the [terraform query](https://developer.hashicorp.com/terraform/cli/commands/query) command.
16+
17+
For more information about the usage see the official Hashicorp documentation for [importing existing resources in bulk](https://developer.hashicorp.com/terraform/language/v1.14.x/import/bulk?page=import&page=bulk).
18+
19+
## API Information ##
20+
21+
* Class: [fvTenant](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvTenant/overview)
22+
23+
* Supported in ACI versions: 1.0(1e) and later.
24+
25+
* Distinguished Name Format: `uni/tn-{name}`
26+
27+
## GUI Information ##
28+
29+
* Location: `Tenants`
30+
31+
## Example Usage ##
32+
33+
The configuration snippet below shows an example for Tenant with only required attributes.
34+
35+
```hcl
36+
list "aci_tenant" "example" {
37+
provider = aci
38+
}
39+
```
40+
41+
The configuration snippet below shows an example for Tenant with filter capabilties.
42+
43+
```hcl
44+
list "aci_tenant" "example" {
45+
provider = aci
46+
config {
47+
filter = "query-target-filter=eq(fvTenant.dn,\"uni/tn-{name}\")"
48+
}
49+
}
50+
```
51+
52+
## Schema ##
53+
54+
### Optional ###
55+
56+
* `config` - (map) A map that contains all configurable options for the list resource.
57+
58+
### Optional ###
59+
60+
* `filter` - (string) A filter to restrict the results of the class query to APIC. See [Cisco APIC REST API Configuration Guide, Release 4.2(x) and Later](https://www.cisco.com/c/en/us/td/docs/dcn/aci/apic/all/apic-rest-api-configuration-guide/cisco-apic-rest-api-configuration-guide-42x-and-later/m_using_the_rest_api.html#concept_1B75A78853DD46AABC15B048AAFAD1AD) for more information about composing filter query expressions.

gen/definitions/properties.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ global:
9696

9797
resource_name_overwrite:
9898
relation_from_l3out_consumer_label_to_external_epg: "external_network_instance_profile"
99+
relation_from_attachable_access_entity_profile_to_domain: "domain"
99100
relation_to_external_epgs: "external_network_instance_profile"
100101
relation_from_l3out_consumer_label_to_route_control_profile: "route_control_profile"
101102
relation_to_vrf: "vrf"

gen/generator.go

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const (
7070
datasourcesExamplesPath = "./examples/data-sources"
7171
docsPath = "./docs"
7272
resourcesDocsPath = "./docs/resources"
73+
listResourcesDocsPath = "./docs/list-resources"
7374
datasourcesDocsPath = "./docs/data-sources"
7475
providerPath = "./internal/provider/"
7576
)
@@ -155,6 +156,8 @@ var templateFuncs = template.FuncMap{
155156
"getCustomTestDependency": GetCustomTestDependency,
156157
"getIgnoreInLegacy": GetIgnoreInLegacy,
157158
"isSensitiveAttribute": IsSensitiveAttribute,
159+
"getChildClassNames": GetChildClassNames,
160+
"getRnForListTesting": GetRnForListTesting,
158161
}
159162

160163
func IsSensitiveAttribute(attributeName string, properties map[string]Property) bool {
@@ -167,6 +170,25 @@ func IsSensitiveAttribute(attributeName string, properties map[string]Property)
167170
return false
168171
}
169172

173+
func GetChildClassNames(model Model, childClassNames []string) []string {
174+
175+
if childClassNames == nil {
176+
childClassNames = []string{}
177+
}
178+
179+
for _, child := range model.Children {
180+
if !slices.Contains(childClassNames, child.PkgName) {
181+
childClassNames = append(childClassNames, child.PkgName)
182+
}
183+
184+
if child.HasChild {
185+
childClassNames = GetChildClassNames(child, childClassNames)
186+
}
187+
188+
}
189+
return childClassNames
190+
}
191+
170192
func GetDeprecatedExplanation(attributeName, replacedByAttributeName string) string {
171193
return fmt.Sprintf("Attribute '%s' is deprecated, please refer to '%s' instead. The attribute will be removed in the next major version of the provider.", attributeName, replacedByAttributeName)
172194
}
@@ -762,12 +784,14 @@ func LookupTestValue(classPkgName, originalPropertyName string, testVars map[str
762784
// Referencing is done based on target_dn logic
763785
// This lookup is created as a workaround to reference in an examples on non target_dn attributes
764786
// Redesign of testing / example creation logic should be done to cover this reference use-case
765-
if classDetails, ok := definitions.Properties[classPkgName]; ok {
766-
for key, value := range classDetails.(map[interface{}]interface{}) {
767-
if key.(string) == "example_value_overwrite" {
768-
for k, v := range value.(map[interface{}]interface{}) {
769-
if k.(string) == propertyName {
770-
return v.(string)
787+
if testVars["overwriteTestValue"].(bool) {
788+
if classDetails, ok := definitions.Properties[classPkgName]; ok {
789+
for key, value := range classDetails.(map[interface{}]interface{}) {
790+
if key.(string) == "example_value_overwrite" {
791+
for k, v := range value.(map[interface{}]interface{}) {
792+
if k.(string) == propertyName {
793+
return v.(string)
794+
}
771795
}
772796
}
773797
}
@@ -1040,9 +1064,50 @@ func getTestVars(model Model) (map[string]interface{}, error) {
10401064
// Adds the resource name and resource class name to the testVars map to be used in test template rendering
10411065
testVarsMap["resourceName"] = model.ResourceName
10421066
testVarsMap["resourceClassName"] = model.ResourceClassName
1067+
testVarsMap["pkgName"] = model.PkgName
1068+
// allow access to the model from testvars
1069+
testVarsMap["model"] = model
1070+
// bool to prevent/allow overwriting during value lookup for list resource testing
1071+
testVarsMap["overwriteTestValue"] = true
10431072
return testVarsMap, nil
10441073
}
10451074

1075+
func GetRnForListTesting(targetClasses interface{}, testVars map[string]interface{}) string {
1076+
model := testVars["model"].(Model)
1077+
rn := model.RnFormat
1078+
for _, property := range model.Properties {
1079+
if property.IsNaming {
1080+
var testValue string
1081+
if property.PropertyName == "tDn" {
1082+
testValue = GetTestTargetDn(testVars["targets"].([]interface{}), GetTargetResourceName(model.ResourceName), testValue, false, targetClasses, 0, false)
1083+
} else {
1084+
testVars["overwriteTestValue"] = false
1085+
testValue = LookupTestValue(model.PkgName, property.PropertyName, testVars, model.Definitions, model.Properties).(string)
1086+
if testValue == "test_value" {
1087+
testValue = LookupTestValue(model.PkgName, property.SnakeCaseName, testVars, model.Definitions, model.Properties).(string)
1088+
}
1089+
if testValue == "test_value" {
1090+
testValue = fmt.Sprintf("test_%s", property.SnakeCaseName)
1091+
}
1092+
testVars["overwriteTestValue"] = true
1093+
}
1094+
if len(testValue) > 0 && testValue[0] == '"' {
1095+
testValue = testValue[1 : len(testValue)-1]
1096+
}
1097+
rn = strings.ReplaceAll(rn, fmt.Sprintf("{%s}", property.PropertyName), testValue)
1098+
}
1099+
}
1100+
1101+
if len(model.ContainedBy) == 1 {
1102+
defaultParentValue := GetDefaultValues(model.PkgName, "parent_dn", model.Definitions)
1103+
if defaultParentValue != "" && strings.HasPrefix(defaultParentValue, "uni/") {
1104+
rn = fmt.Sprintf("%s/%s", defaultParentValue[4:], rn)
1105+
}
1106+
}
1107+
1108+
return rn
1109+
}
1110+
10461111
// Retrieves the property and classs overwrite definitions from the definitions YAML files
10471112
func getDefinitions() Definitions {
10481113
definitions := Definitions{}
@@ -1143,9 +1208,10 @@ func migrateLegacyDocumentation() {
11431208

11441209
// Container function to clean all directories properly
11451210
func cleanDirectories() {
1146-
cleanDirectory(docsPath, []string{"resources", "data-sources", "guides"})
1211+
cleanDirectory(docsPath, []string{"list-resources", "resources", "data-sources", "guides"})
11471212
cleanDirectory(providerPath, []string{"provider_test.go", "utils.go", "test_constants.go", "resource_aci_rest_managed.go", "resource_aci_rest_managed_test.go", "data_source_aci_rest_managed.go", "data_source_aci_rest_managed_test.go", "annotation_unsupported.go", "data_source_aci_system.go", "data_source_aci_system_test.go", "function_compare_versions.go", "function_compare_versions_test.go"})
11481213
cleanDirectory(resourcesDocsPath, []string{})
1214+
cleanDirectory(listResourcesDocsPath, []string{})
11491215
cleanDirectory(datasourcesDocsPath, []string{"system.md"})
11501216
cleanDirectory(testVarsPath, []string{})
11511217
cleanDirectory("./internal/custom_types", []string{})
@@ -1330,6 +1396,7 @@ func main() {
13301396
}
13311397
}
13321398
renderTemplate("resource.go.tmpl", fmt.Sprintf("resource_%s_%s.go", providerName, model.ResourceName), providerPath, model)
1399+
renderTemplate("resource_list.go.tmpl", fmt.Sprintf("resource_%s_%s_list.go", providerName, model.ResourceName), providerPath, model)
13331400
renderTemplate("datasource.go.tmpl", fmt.Sprintf("data_source_%s_%s.go", providerName, model.ResourceName), providerPath, model)
13341401

13351402
os.Mkdir(fmt.Sprintf("%s/%s_%s", resourcesExamplesPath, providerName, model.ResourceName), 0755)
@@ -1342,6 +1409,7 @@ func main() {
13421409
// Leverage the hclwrite package to format the example code
13431410
model.ExampleResource = string(hclwrite.Format(getExampleCode(fmt.Sprintf("%s/%s_%s/resource.tf", resourcesExamplesPath, providerName, model.ResourceName))))
13441411
renderTemplate("resource.md.tmpl", fmt.Sprintf("%s.md", model.ResourceName), resourcesDocsPath, model)
1412+
renderTemplate("resource_list.md.tmpl", fmt.Sprintf("%s.md", model.ResourceName), listResourcesDocsPath, model)
13451413

13461414
os.Mkdir(fmt.Sprintf("%s/%s_%s", datasourcesExamplesPath, providerName, model.ResourceName), 0755)
13471415
renderTemplate("provider_example.tf.tmpl", fmt.Sprintf("%s_%s/provider.tf", providerName, model.ResourceName), datasourcesExamplesPath, model)
@@ -1351,6 +1419,7 @@ func main() {
13511419
renderTemplate("datasource.md.tmpl", fmt.Sprintf("%s.md", model.ResourceName), datasourcesDocsPath, model)
13521420
renderTemplate("resource_test.go.tmpl", fmt.Sprintf("resource_%s_%s_test.go", providerName, model.ResourceName), providerPath, model)
13531421
renderTemplate("datasource_test.go.tmpl", fmt.Sprintf("data_source_%s_%s_test.go", providerName, model.ResourceName), providerPath, model)
1422+
renderTemplate("resource_list_test.go.tmpl", fmt.Sprintf("resource_%s_%s_list_test.go", providerName, model.ResourceName), providerPath, model)
13541423
}
13551424
}
13561425
}

gen/templates/provider.go.tmpl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ import (
1717
// "github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
1818

1919
"github.com/hashicorp/terraform-plugin-framework/datasource"
20+
"github.com/hashicorp/terraform-plugin-framework/list"
2021
"github.com/hashicorp/terraform-plugin-framework/provider"
2122
"github.com/hashicorp/terraform-plugin-framework/provider/schema"
2223
"github.com/hashicorp/terraform-plugin-framework/resource"
24+
"github.com/hashicorp/terraform-plugin-framework/resource/identityschema"
2325
// temporary unused until muxing is removed
2426
// "github.com/hashicorp/terraform-plugin-framework/schema/validator"
2527
"github.com/hashicorp/terraform-plugin-framework/types"
@@ -33,6 +35,7 @@ var globalAllowExistingOnCreate bool
3335
// Ensure AciProvider satisfies various provider interfaces.
3436
var _ provider.Provider = &AciProvider{}
3537
var _ provider.ProviderWithFunctions = &AciProvider{}
38+
var _ provider.ProviderWithListResources = (*AciProvider)(nil)
3639

3740
// Struct model for identity data handling
3841
type IdentityModel struct {
@@ -217,6 +220,17 @@ func (p *AciProvider) Configure(ctx context.Context, req provider.ConfigureReque
217220

218221
resp.DataSourceData = aciClient
219222
resp.ResourceData = aciClient
223+
resp.ListResourceData = aciClient
224+
}
225+
226+
func (p *AciProvider) ListResources(ctx context.Context) []func() list.ListResource {
227+
return []func() list.ListResource{
228+
{{- range . }}
229+
{{- if or (and .IdentifiedBy (not (and .MaxOneClassAllowed (hasPrefix .RnFormat "rs")))) .Include}}
230+
New{{.ResourceClassName}}ListResource,
231+
{{- end }}
232+
{{- end }}
233+
}
220234
}
221235

222236
func (p *AciProvider) Resources(ctx context.Context) []func() resource.Resource {

0 commit comments

Comments
 (0)