Skip to content

Commit

Permalink
[ignore] Add target_dn overwrite for documentations and examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmicol committed Sep 4, 2024
1 parent 3be62a2 commit 3803b57
Show file tree
Hide file tree
Showing 20 changed files with 105 additions and 64 deletions.
4 changes: 2 additions & 2 deletions docs/resources/netflow_exporter_policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ resource "aci_netflow_exporter_policy" "full_example_tenant" {
relation_to_vrf = [
{
annotation = "annotation_1"
target_dn = "uni/tn-test_tenant/ctx-test_vrf"
target_dn = aci_vrf.example.id
}
]
relation_to_epg = [
{
annotation = "annotation_1"
target_dn = "uni/tn-test_tenant/ap-test_ap/epg-test_epg"
target_dn = aci_application_epg.example.id
}
]
annotations = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ resource "aci_netflow_exporter_policy" "full_example_tenant" {
relation_to_vrf = [
{
annotation = "annotation_1"
target_dn = "uni/tn-test_tenant/ctx-test_vrf"
target_dn = aci_vrf.example.id
}
]
relation_to_epg = [
{
annotation = "annotation_1"
target_dn = "uni/tn-test_tenant/ap-test_ap/epg-test_epg"
target_dn = aci_application_epg.example.id
}
]
annotations = [
Expand Down
2 changes: 2 additions & 0 deletions gen/definitions/properties.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,7 @@ netflowRsExporterToEPg:
targets:
- class_name: "fvAEPg"
target_dn: "uni/tn-test_tenant/ap-test_ap/epg-test_epg"
target_dn_overwrite_docs: "aci_application_epg.example.id"
relation_resource_name: "epg"
static: true

Expand All @@ -991,6 +992,7 @@ netflowRsExporterToCtx:
targets:
- class_name: "fvCtx"
target_dn: "uni/tn-test_tenant/ctx-test_vrf"
target_dn_overwrite_docs: "aci_vrf.example.id"
relation_resource_name: "vrf"
static: true

Expand Down
10 changes: 9 additions & 1 deletion gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@ type TestDependency struct {
ParentDnKey string
TargetDn string
TargetDnRef string
TargetDnOverwriteDocs string
TargetResourceName string
RelationResourceName string
Static bool
Expand Down Expand Up @@ -2072,10 +2073,14 @@ func getTestDependency(className string, targetMap map[interface{}]interface{},
testDependency.Static = static.(bool)
}

if targetDnOverwriteDocs, ok := targetMap["target_dn_overwrite_docs"]; ok {
testDependency.TargetDnOverwriteDocs = targetDnOverwriteDocs.(string)
}

return testDependency
}

func GetTestTargetDn(targets []interface{}, resourceName, targetDnValue string, reference bool, targetClasses interface{}, index int) string {
func GetTestTargetDn(targets []interface{}, resourceName, targetDnValue string, reference bool, targetClasses interface{}, index int, overwriteDocs bool) string {

var filteredTargets []interface{}
targetResourceName := strings.TrimPrefix(resourceName, "relation_to_")
Expand Down Expand Up @@ -2109,6 +2114,9 @@ func GetTestTargetDn(targets []interface{}, resourceName, targetDnValue string,
if reference && !static {
return target.(map[interface{}]interface{})["target_dn_ref"].(string)
}
if v, ok := target.(map[interface{}]interface{})["target_dn_overwrite_docs"].(string); ok && overwriteDocs && v != "" {
return v
}
return target.(map[interface{}]interface{})["target_dn"].(string)
}
}
Expand Down
2 changes: 1 addition & 1 deletion gen/templates/datasource_example.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ data "aci_{{$.ResourceName}}" "example_{{getResourceName $key $.Definitions}}" {
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = aci_{{getResourceName .NamedPropertyClass $.Definitions}}.example.name
{{- else if eq .SnakeCaseName "t_dn" }}{{$attributeKey := overwriteProperty .PkgName .SnakeCaseName $.Definitions}}
{{- range $index, $testParent := $.TestVars.parents }}
{{- if eq $index $parentIndex }}{{$attributeVale := getTestTargetDn $.TestVars.targets $.TestVars.resourceName "" true $testParent.target_classes $index | replace "test" "example" | replace "_0" "" | replace "_1" "_2" }}
{{- if eq $index $parentIndex }}{{$attributeVale := getTestTargetDn $.TestVars.targets $.TestVars.resourceName "" true $testParent.target_classes $index true | replace "test" "example" | replace "_0" "" | replace "_1" "_2" }}
{{$attributeKey}} = {{if containsString $attributeVale "."}}{{$attributeVale}}{{else}}"{{$attributeVale}}"{{end}}
{{- $parentIndex = add $parentIndex 1 }}{{- break}}
{{- end}}
Expand Down
10 changes: 5 additions & 5 deletions gen/templates/datasource_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestAccDataSource{{$.resourceClassName}}With{{capitalize .class_name}} (t *
Check: resource.ComposeAggregateTestCheckFunc(
{{- range $key, $value := $.datasource_required}}
{{- if eq $key "target_dn" }}
resource.TestCheckResourceAttr("data.aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{getTestTargetDn $.targets $.resourceName $value false $target_classes 0}}"),
resource.TestCheckResourceAttr("data.aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{getTestTargetDn $.targets $.resourceName $value false $target_classes 0 false}}"),
{{- else }}
resource.TestCheckResourceAttr("data.aci_{{$.resourceName}}.test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}", "{{$key}}", "{{$value}}"),
{{- end }}
Expand Down Expand Up @@ -95,7 +95,7 @@ const testConfig{{$.resourceClassName}}DataSourceDependencyWith{{capitalize .cla
data "aci_{{$.resourceName}}" "test{{- if eq $.resourceClassName $parentClassName }}_1{{- end }}" {
parent_dn = {{.parent_dn}}
{{- range $key, $value := $.datasource_required}}
{{- if eq $key "target_dn" }}{{$attributeValue := getTestTargetDn $.targets $.resourceName $value true $target_classes 0}}
{{- if eq $key "target_dn" }}{{$attributeValue := getTestTargetDn $.targets $.resourceName $value true $target_classes 0 false}}
{{$key}} = {{if containsString $attributeValue "."}}{{$attributeValue}}{{else}}"{{$attributeValue}}"{{end}}
{{- else }}
{{$key}} = "{{$value}}"
Expand All @@ -110,7 +110,7 @@ data "aci_{{$.resourceName}}" "test_non_existing" {
parent_dn = {{.parent_dn}}
{{- range $key, $value := $.datasource_non_existing}}
{{- if and (eq $key "target_dn") (not (hasPrefix $value "topology/")) }}
{{$key}} = "{{getTestTargetDn $.targets $.resourceName $value false $target_classes 0}}_not_existing"
{{$key}} = "{{getTestTargetDn $.targets $.resourceName $value false $target_classes 0 false}}_not_existing"
{{- else }}
{{$key}} = "{{$value}}"
{{- end }}
Expand All @@ -122,7 +122,7 @@ data "aci_{{$.resourceName}}" "test_non_existing" {
const testConfig{{.resourceClassName}}DataSource = testConfig{{.resourceClassName}}All + `
data "aci_{{$.resourceName}}" "test" {
{{- range $key, $value := $.datasource_required}}
{{- if eq $key "target_dn" }}{{$attributeValue := getTestTargetDn $.targets $.resourceName $value true nil 0}}
{{- if eq $key "target_dn" }}{{$attributeValue := getTestTargetDn $.targets $.resourceName $value true nil 0 false}}
{{$key}} = {{if containsString $attributeValue "."}}{{$attributeValue}}{{else}}"{{$attributeValue}}"{{end}}
{{- else }}
{{$key}} = "{{$value}}"
Expand All @@ -136,7 +136,7 @@ const testConfig{{$.resourceClassName}}NotExisting = testConfig{{.resourceClassN
data "aci_{{$.resourceName}}" "test_non_existing" {
{{- range $key, $value := $.datasource_non_existing}}
{{- if and (eq $key "target_dn") (not (hasPrefix $value "topology/")) }}
{{$key}} = "{{getTestTargetDn $.targets $.resourceName $value false nil 0}}_not_existing"
{{$key}} = "{{getTestTargetDn $.targets $.resourceName $value false nil 0 false}}_not_existing"
{{- else }}
{{$key}} = "{{$value}}"
{{- end }}
Expand Down
2 changes: 1 addition & 1 deletion gen/templates/resource_example.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ resource "aci_{{$.ResourceName}}" "example_{{getResourceName $key $.Definitions}
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = aci_{{getResourceName .NamedPropertyClass $.Definitions}}.example.name
{{- else if eq .SnakeCaseName "t_dn" }}{{$attributeKey := overwriteProperty .PkgName .SnakeCaseName $.Definitions}}
{{- range $index, $testParent := $.TestVars.parents }}
{{- if eq $index $parentIndex }}{{$attributeValue := getTestTargetDn $.TestVars.targets $.TestVars.resourceName "" true $testParent.target_classes $index | replace "test" "example" | replace "_0" "" | replace "_1" "_2" }}
{{- if eq $index $parentIndex }}{{$attributeValue := getTestTargetDn $.TestVars.targets $.TestVars.resourceName "" true $testParent.target_classes $index true | replace "test" "example" | replace "_0" "" | replace "_1" "_2" }}
{{$attributeKey}} = {{if containsString $attributeValue "."}}{{$attributeValue}}{{else}}"{{$attributeValue}}"{{end}}
{{- $parentIndex = add $parentIndex 1 }}{{- break}}
{{- end}}
Expand Down
6 changes: 3 additions & 3 deletions gen/templates/resource_example_all_attributes.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ resource "aci_{{$.ResourceName}}" "full_example_{{getResourceName $key $.Definit
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = aci_{{getResourceName .NamedPropertyClass $.Definitions}}.example.name
{{- else if eq .SnakeCaseName "t_dn" }}{{$attributeKey := overwriteProperty .PkgName .SnakeCaseName $.Definitions}}
{{- range $index, $testParent := $.TestVars.parents }}
{{- if eq $index $parentIndex }}{{$attributeVale := getTestTargetDn $.TestVars.targets $.TestVars.resourceName "" true $testParent.target_classes $index | replace "test" "example" | replace "_0" "" | replace "_1" "_2" }}
{{- if eq $index $parentIndex }}{{$attributeVale := getTestTargetDn $.TestVars.targets $.TestVars.resourceName "" true $testParent.target_classes $index true | replace "test" "example" | replace "_0" "" | replace "_1" "_2" }}
{{$attributeKey}} = {{if containsString $attributeVale "."}}{{$attributeVale}}{{else}}"{{$attributeVale}}"{{end}}
{{- $parentIndex = add $parentIndex 1 }}{{- break}}
{{- end}}
Expand All @@ -24,7 +24,7 @@ resource "aci_{{$.ResourceName}}" "full_example_{{getResourceName $key $.Definit
{ {{- range .Properties}}{{- if not .ReadOnly }}{{- if ne .NamedPropertyClass ""}}
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = aci_{{getResourceName .NamedPropertyClass $.Definitions}}.example.name
{{- else if eq .SnakeCaseName "t_dn" }}
{{- range $index, $testParent := $.TestVars.parents }}{{$attributeVale := getTestTargetDn $.TestVars.child_targets $ChildResourceName "target_dn_0" true nil 0 | replace "test_0" "example_2" }}
{{- range $index, $testParent := $.TestVars.parents }}{{$attributeVale := getTestTargetDn $.TestVars.child_targets $ChildResourceName "target_dn_0" true nil 0 true | replace "test_0" "example_2" }}
target_dn = {{if containsString $attributeVale "."}}{{$attributeVale}}{{else}}"{{$attributeVale}}"{{end}}
{{- break}}
{{- end}}
Expand Down Expand Up @@ -52,7 +52,7 @@ resource "aci_{{$.ResourceName}}" "full_example" {
{{$ChildResourceName}} = [
{ {{- range .Properties}}{{- if not .ReadOnly }}{{- if ne .NamedPropertyClass ""}}
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = aci_{{getResourceName .NamedPropertyClass $.Definitions}}.example.name
{{- else if eq .SnakeCaseName "t_dn" }}{{$attributeVale := getTestTargetDn $.TestVars.child_targets $ChildResourceName "target_dn_0" true nil 0 | replace "test_0" "example_2" }}
{{- else if eq .SnakeCaseName "t_dn" }}{{$attributeVale := getTestTargetDn $.TestVars.child_targets $ChildResourceName "target_dn_0" true nil 0 true | replace "test_0" "example_2" }}
target_dn = {{if containsString $attributeVale "."}}{{$attributeVale}}{{else}}"{{$attributeVale}}"{{end}}
{{- else if .IgnoreInTest}}
{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = "{{.IgnoreInTestExampleValue}}"
Expand Down
Loading

0 comments on commit 3803b57

Please sign in to comment.