From 32589bb86faf47d7db0379cdf186ba51b2be23da Mon Sep 17 00:00:00 2001 From: akinross Date: Tue, 2 Jul 2024 11:38:26 +0200 Subject: [PATCH] [ignore] Fix examples for target_dns in resources --- docs/resources/endpoint_security_group.md | 2 +- docs/resources/relation_to_contract_master.md | 8 ++++---- .../resource-all-attributes.tf | 2 +- .../resource-all-attributes.tf | 4 ++-- .../aci_relation_to_contract_master/resource.tf | 4 ++-- gen/templates/resource_example.tf.tmpl | 11 ++++++++--- .../resource_example_all_attributes.tf.tmpl | 16 +++++++++++++--- 7 files changed, 31 insertions(+), 16 deletions(-) diff --git a/docs/resources/endpoint_security_group.md b/docs/resources/endpoint_security_group.md index 52536853e..08fb58d06 100644 --- a/docs/resources/endpoint_security_group.md +++ b/docs/resources/endpoint_security_group.md @@ -94,7 +94,7 @@ resource "aci_endpoint_security_group" "full_example_application_profile" { relation_to_contract_masters = [ { annotation = "annotation_1" - target_dn = "target_dn_0" + target_dn = aci_endpoint_security_group.example_2.id } ] annotations = [ diff --git a/docs/resources/relation_to_contract_master.md b/docs/resources/relation_to_contract_master.md index bbd916654..5a14eb6e4 100644 --- a/docs/resources/relation_to_contract_master.md +++ b/docs/resources/relation_to_contract_master.md @@ -41,12 +41,12 @@ The configuration snippet below creates a Relation To Contract Master with only resource "aci_relation_to_contract_master" "example_application_epg" { parent_dn = aci_application_epg.example.id - target_dn = aci_endpoint_security_group.example.id + target_dn = aci_application_epg.example_2.id } resource "aci_relation_to_contract_master" "example_endpoint_security_group" { parent_dn = aci_endpoint_security_group.example.id - target_dn = aci_endpoint_security_group.example.id + target_dn = aci_endpoint_security_group.example_2.id } ``` @@ -59,7 +59,7 @@ The configuration snippet below shows all possible attributes of the Relation To resource "aci_relation_to_contract_master" "full_example_application_epg" { parent_dn = aci_application_epg.example.id annotation = "annotation" - target_dn = aci_endpoint_security_group.example.id + target_dn = aci_application_epg.example_2.id annotations = [ { key = "key_0" @@ -77,7 +77,7 @@ resource "aci_relation_to_contract_master" "full_example_application_epg" { resource "aci_relation_to_contract_master" "full_example_endpoint_security_group" { parent_dn = aci_endpoint_security_group.example.id annotation = "annotation" - target_dn = aci_endpoint_security_group.example.id + target_dn = aci_endpoint_security_group.example_2.id annotations = [ { key = "key_0" diff --git a/examples/resources/aci_endpoint_security_group/resource-all-attributes.tf b/examples/resources/aci_endpoint_security_group/resource-all-attributes.tf index e050bd624..b8449af06 100644 --- a/examples/resources/aci_endpoint_security_group/resource-all-attributes.tf +++ b/examples/resources/aci_endpoint_security_group/resource-all-attributes.tf @@ -47,7 +47,7 @@ resource "aci_endpoint_security_group" "full_example_application_profile" { relation_to_contract_masters = [ { annotation = "annotation_1" - target_dn = "target_dn_0" + target_dn = aci_endpoint_security_group.example_2.id } ] annotations = [ diff --git a/examples/resources/aci_relation_to_contract_master/resource-all-attributes.tf b/examples/resources/aci_relation_to_contract_master/resource-all-attributes.tf index f1b2bd5bf..f95698f1e 100644 --- a/examples/resources/aci_relation_to_contract_master/resource-all-attributes.tf +++ b/examples/resources/aci_relation_to_contract_master/resource-all-attributes.tf @@ -2,7 +2,7 @@ resource "aci_relation_to_contract_master" "full_example_application_epg" { parent_dn = aci_application_epg.example.id annotation = "annotation" - target_dn = aci_endpoint_security_group.example.id + target_dn = aci_application_epg.example_2.id annotations = [ { key = "key_0" @@ -20,7 +20,7 @@ resource "aci_relation_to_contract_master" "full_example_application_epg" { resource "aci_relation_to_contract_master" "full_example_endpoint_security_group" { parent_dn = aci_endpoint_security_group.example.id annotation = "annotation" - target_dn = aci_endpoint_security_group.example.id + target_dn = aci_endpoint_security_group.example_2.id annotations = [ { key = "key_0" diff --git a/examples/resources/aci_relation_to_contract_master/resource.tf b/examples/resources/aci_relation_to_contract_master/resource.tf index 2f50f1d54..c2a68431d 100644 --- a/examples/resources/aci_relation_to_contract_master/resource.tf +++ b/examples/resources/aci_relation_to_contract_master/resource.tf @@ -1,10 +1,10 @@ resource "aci_relation_to_contract_master" "example_application_epg" { parent_dn = aci_application_epg.example.id - target_dn = aci_endpoint_security_group.example.id + target_dn = aci_application_epg.example_2.id } resource "aci_relation_to_contract_master" "example_endpoint_security_group" { parent_dn = aci_endpoint_security_group.example.id - target_dn = aci_endpoint_security_group.example.id + target_dn = aci_endpoint_security_group.example_2.id } diff --git a/gen/templates/resource_example.tf.tmpl b/gen/templates/resource_example.tf.tmpl index 7ad76667a..bbb4bd2b7 100644 --- a/gen/templates/resource_example.tf.tmpl +++ b/gen/templates/resource_example.tf.tmpl @@ -1,12 +1,17 @@ -{{- if .DocumentationExamples}}{{- range $key := .DocumentationExamples}} +{{- if .DocumentationExamples}}{{$parentIndex := 0}}{{- range $key := .DocumentationExamples}} resource "aci_{{$.ResourceName}}" "example_{{getResourceName $key $.Definitions}}" { {{- if $.HasParent}} parent_dn = {{createParentDnValue $key "example" $.Definitions}} {{- end}} {{- range $.Properties}}{{- if .IsRequired}}{{- if ne .NamedPropertyClass ""}} {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = aci_{{getResourceName .NamedPropertyClass $.Definitions}}.example.name - {{- else if eq .SnakeCaseName "t_dn" }} - {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = {{lookupTestValue .PkgName .SnakeCaseName $.TestVars $.Definitions | replace ".test_0.id" ".example.id"}} + {{- else if eq .SnakeCaseName "t_dn" }}{{$attributeKey := overwriteProperty .PkgName .SnakeCaseName $.Definitions}} + {{- range $index, $testParent := $.TestVars.parents }} + {{- if eq $index $parentIndex }} + {{$attributeKey}} = {{getTestTargetDn $.TestVars.targets $.TestVars.resourceName "" true $testParent.target_classes $index | replace "test" "example" | replace "_0" "" | replace "_1" "_2" }} + {{- $parentIndex = add $parentIndex 1 }}{{- break}} + {{- end}} + {{- end}} {{- else}} {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = "{{lookupTestValue .PkgName .SnakeCaseName $.TestVars $.Definitions}}"{{- end}}{{- end}} {{- end}} diff --git a/gen/templates/resource_example_all_attributes.tf.tmpl b/gen/templates/resource_example_all_attributes.tf.tmpl index 47a48a655..efee67a7a 100644 --- a/gen/templates/resource_example_all_attributes.tf.tmpl +++ b/gen/templates/resource_example_all_attributes.tf.tmpl @@ -1,12 +1,17 @@ -{{- if .DocumentationExamples}}{{- range $key := .DocumentationExamples}} +{{- if .DocumentationExamples}}{{$parentIndex := 0}}{{- range $key := .DocumentationExamples}} resource "aci_{{$.ResourceName}}" "full_example_{{getResourceName $key $.Definitions}}" { {{- if $.HasParent}} parent_dn = {{createParentDnValue $key "example" $.Definitions}} {{- end}} {{- range $.Properties}}{{- if ne .NamedPropertyClass ""}} {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = aci_{{getResourceName .NamedPropertyClass $.Definitions}}.example.name - {{- else if eq .SnakeCaseName "t_dn" }} - {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = {{lookupTestValue .PkgName .SnakeCaseName $.TestVars $.Definitions | replace ".test_0.id" ".example.id"}} + {{- else if eq .SnakeCaseName "t_dn" }}{{$attributeKey := overwriteProperty .PkgName .SnakeCaseName $.Definitions}} + {{- range $index, $testParent := $.TestVars.parents }} + {{- if eq $index $parentIndex }} + {{$attributeKey}} = {{getTestTargetDn $.TestVars.targets $.TestVars.resourceName "" true $testParent.target_classes $index | replace "test" "example" | replace "_0" "" | replace "_1" "_2" }} + {{- $parentIndex = add $parentIndex 1 }}{{- break}} + {{- end}} + {{- end}} {{- else if eq .ValueType "bitmask"}}{{ $bitmaskTestValue := lookupTestValue .PkgName .SnakeCaseName $.TestVars $.Definitions}} {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = [{{range $index, $value := $bitmaskTestValue}}{{if lt $index (substract (len $bitmaskTestValue) 1)}}"{{$value}}",{{else}}"{{$value}}"{{end}}{{end}}] {{- else}} @@ -16,6 +21,11 @@ resource "aci_{{$.ResourceName}}" "full_example_{{getResourceName $key $.Definit {{$ChildResourceName}} = [ { {{- range .Properties}}{{- if ne .NamedPropertyClass ""}} {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = aci_{{getResourceName .NamedPropertyClass $.Definitions}}.example.name + {{- else if eq .SnakeCaseName "t_dn" }} + {{- range $index, $testParent := $.TestVars.parents }} + target_dn = {{getTestTargetDn $.TestVars.child_targets $ChildResourceName "target_dn_0" true nil 0 | replace "test_0" "example_2" }} + {{- break}} + {{- end}} {{- else}} {{overwriteProperty .PkgName .SnakeCaseName $.Definitions}} = "{{lookupChildTestValue .PkgName $ChildResourceName .SnakeCaseName $.TestVars 0 $.Definitions}}"{{- end}}{{ end}} }