Sorry. I tried to oversimplify the configuration.
This is how my execution plan looks like
resource "dcnm_fabric" "test" {
name = "TERRAFORM_FABRIC"
asn = "65002"
ibgp_peer_template_config = " template peer TEST\n remote-as 65002\n address-family l2vpn evpn"
}
This is how the state file looks after executing terraform apply
{
"version": 4,
"terraform_version": "1.3.1",
"serial": 13,
"lineage": "e1d55485-d67c-5f34-4846-e9637c2415a2",
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "dcnm_fabric",
"name": "test",
"provider": "provider[\"registry.terraform.io/ciscodevnet/dcnm\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"asn": 65002,
"fabric_id": "FABRIC-4",
"ibgp_bfd": false,
"ibgp_peer_template_config": " template peer TEST\\n remote-as 65002\\n address-family l2vpn evpn"
},
"sensitive_attributes": [],
"private": "bnVsbA=="
}
]
}
],
"check_results": []
}
At this point there is a drift between the value in the Execution Plan and the value in the State File for the key ibgp_peer_template_config
. Therefore a new execution of terraform apply
triggers an update:
# dcnm_fabric.test will be updated in-place
~ resource "dcnm_fabric" "test" {
~ ibgp_peer_template_config = <<-EOT
- " template peer TEST\n remote-as 65002\n address-family l2vpn evpn"
+ template peer TEST
+ remote-as 65002
+ address-family l2vpn evpn
EOT
id = "4"
name = "TERRAFORM_FABRIC"
# (52 unchanged attributes hidden)
}
Plan: 0 to add, 1 to change, 0 to destroy.
I have the feeling there is something wrong when I set the value of the key ibgp_peer_template_config
in the Read method.
This is how the method looks: (Some line are omitted)
func resourceDCNMFabricRead(d *schema.ResourceData, m interface{}) error {
//..
d.Set("ibgp_peer_template_config", cont.S("IBGP_PEER_TEMPLATE").String())
//
I have already debugged the code and can confirm that the value of the operation cont.S("IBGP_PEER_TEMPLATE").String()
is " template peer TEST\n remote-as 65002\n address-family l2vpn evpn"
. I cannot find any other reason why the state file includes additional \
characters for this specific key