Txt record too long error

I executed this code once and it worked perfectly

  new DnsTxtRecord(scope, `${name}-fe-apex-domain-txt-record`, {
    name: "@",
    zoneName: dnsZone.name,
    resourceGroupName: rg.name,
    ttl: 330,
    record: [{ value: staticsitedomain.validationToken }],
  });

Than I did new deploy and got this:

[2022-03-03T17:32:32.545] [ERROR] default - ╷
│ Error: expected length of record.0.value to be in the range (1 - 1024), got 
│ 
│   with azurerm_dns_txt_record.verisdev-userms-fe-apex-domain-txt-record,
│   on cdk.tf.json line 2843, in resource.azurerm_dns_txt_record.verisdev-userms-fe-apex-domain-txt-record:
│ 2843:         "record": [
│ 2844:           {
│ 2845:             "value": "${azurerm_static_site_custom_domain.verisdev-userms-fe-custom-domain.validation_token}"
│ 2846:           }
│ 2847:         ],

I execute the code once, it passed, it created the TXT record.
Now on each new yarn cdktf build when I try to deploy something else I get this error.

azuread provider v2.16.0_x5
azurerm provider v2.94.0

Any Solutions suggestions?

Are you able to view the dns record and the validation_token to make sure they match?
What does cdktf diff show?

I can see the DNS record (TXT record) with its value. As I mentioned before this execution was successful for the first time.
Even when I do yarn cdktf diff stackname I get the same error.

[2022-03-07T10:28:04.850] [ERROR] default - ╷
│ Error: expected length of record.0.value to be in the range (1 - 1024), got

│ with azurerm_dns_txt_record.verisdev-userms-fe-apex-domain-txt-record,
│ on cdk.tf.json line 2843, in resource.azurerm_dns_txt_record.verisdev-userms-fe-apex-domain-txt-record:
│ 2843: “record”: [
│ 2844: {
│ 2845: “value”: “${azurerm_static_site_custom_domain.verisdev-userms-fe-custom-domain.validation_token}”
│ 2846: }
│ 2847: ],

So I commented the code and it deleted the record. Then I uncommented it and execute yarn cdktf deploy stanckname and the code was deployed without the issue I mentioned above, new DNS txt record was created. Then for a test I did another yarn cdktf deploy stackname and it failed with the same error. The same is with yarn cdktf diff stackname. Basically terraform it is giving this error if there is already existing DNS txt record, which blocks my work, cause simply I can’t continue to deploy stuff without this error resolved

Basically i have this issue azurerm_static_site_custom_domain.validation_token dissapears after successfull validation yielding entire TF setup stuck on failed validation · Issue #14750 · hashicorp/terraform-provider-azurerm · GitHub
But can’t solve it with ternary expression, in TypeScript it not working as expected.

Any ideas on how would I handle it?

You could pass the variable as a configuration option at the Typescript level rather than a Terraform variable.

Could probably use fn.coalesce to replicate the ternary expression as a closer approximation of the workaround.

Yep this does the work.
Thanks!