Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HostedZone: Referencing array attributes cross-stack breaks with Template Format Error #22846

Closed
surecloud-meason opened this issue Nov 9, 2022 · 5 comments
Labels
@aws-cdk/aws-route53 Related to Amazon Route 53 bug This issue is a bug. effort/small Small work item – less than a day of effort p1

Comments

@surecloud-meason
Copy link
Contributor

surecloud-meason commented Nov 9, 2022

Describe the bug

When referencing a HostedZoneNameServer from another stack the Output created is invalid and on deployment errors with:
"Template format error: Every Value member must be a string."

CDK Synth Cloudformation Snippet Generated:

Outputs:
  ExportsOutputFnGetAttprodukdnshostedzone423B3F93NameServers1C276690:
    Value:
      Fn::GetAtt:
        - produkdnshostedzone423B3F93
        - NameServers
    Export:
      Name: prod-uk-dns:ExportsOutputFnGetAttprodukdnshostedzone423B3F93NameServers1C276690

Expected Behavior

The auto created output handles lists correctly for use within another stack.

Current Behavior

The deploy fails due to an cloudformation format error .

Reproduction Steps

DNS Stack:

import {Construct} from 'constructs';
import {StackProps} from 'aws-cdk-lib';
import {PublicHostedZone} from 'aws-cdk-lib/aws-route53';

export interface DnsStackProps extends StackProps {
    zoneName: string;
}

export class Dns1Stack extends Stack {

    public readonly hostedZone: PublicHostedZone;

    constructor(scope: Construct, id: string, props: DnsStackProps) {
        super(scope, id, props);

        this.hostedZone = new PublicHostedZone(this, `${this.stackName}-hosted-zone`, {
                zoneName: props.zoneName,
            }
        );

    }
}

Stack Referencing the above stack

import {Construct} from 'constructs';
import {Duration, StackProps} from 'aws-cdk-lib';
import {PublicHostedZone} from 'aws-cdk-lib/aws-route53';

export interface DnsStackProps extends StackProps {
    zoneName: string;
    dnsHostedZone: PublicHostedZone;
}

export class Dns2Stack extends Stack {
    constructor(scope: Construct, id: string, props: DnsStackProps) {
        super(scope, id, props);

        const timeToLiveMinutes = 5;

        new NsRecord(this, `${this.stackName}-prod-env-ns-record-set`, {
            zone: hostedZone,
            recordName: props.dnsHostedZone.zoneName,
            values: props.dnsHostedZone.hostedZoneNameServers as string[],
            ttl: Duration.minutes(timeToLiveMinutes),
        });

    }
}

Stack Instantiations

const Dns1Stack = new Dns1Stack(app, `dns1`, {
    zoneName: `${deploymentType}.somedomain.com`,
    env: {
        region: 'us-east-1',
    },
});

const Dns2Stack = new Dns2Stack(app, `dns2`, {
    zoneName: 'somedomain.com',
    dnsHostedZone: Dns1Stack.hostedZone,
    env: {
        region: 'us-east-1',
    },
});

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.50.0

Framework Version

No response

Node.js Version

v16.18.0

OS

Ubuntu 20.04

Language

Typescript

Language Version

No response

Other information

No response

@surecloud-meason surecloud-meason added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 9, 2022
@github-actions github-actions bot added the @aws-cdk/aws-route53 Related to Amazon Route 53 label Nov 9, 2022
@peterwoodworth
Copy link
Contributor

Thanks for reporting this @surecloud-meason, I was able to reproduce this.

I'm pretty stumped why this is occurring. Everything in the template is formatted correctly, there should be no validation errors occurring here.

I've created a ticket for CloudFormation (P75318355), hopefully they'll be able to help out here. I'll let you know if there are any updates. Thanks!

@peterwoodworth peterwoodworth added p2 effort/small Small work item – less than a day of effort needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. and removed needs-triage This issue or PR still needs to be triaged. labels Nov 12, 2022
@peterwoodworth peterwoodworth removed the needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. label Nov 16, 2022
@peterwoodworth
Copy link
Contributor

Ah, the issue is due to the result of the output HostedZone.NameServers being a list of strings. Here is how the template could look instead:

Outputs:
  HZNameServer:
    Value: !Join ["", !GetAtt myHostedZone.NameServers]

You could work around this for now by creating your own CfnOutput and referencing it directly in the other stack when needed

@peterwoodworth peterwoodworth changed the title HostedZone: Referencing a HostedZone.hostedZoneNameServers From Another Stack Returns a Cloudformation Yaml Format Exception. "Template format error: Every Value member must be a string." HostedZone: Referencing array attributes cross-stack breaks with Template Format Error Nov 16, 2022
@peterwoodworth peterwoodworth added p1 and removed p2 labels Nov 16, 2022
@peterwoodworth peterwoodworth removed their assignment Nov 16, 2022
@comcalvi
Copy link
Contributor

comcalvi commented Jan 5, 2023

Is this still an issue? Pretty sure this has been fixed by #22873

@peterwoodworth
Copy link
Contributor

Yeah we can probably close this, I tested this prior to the change linked

@github-actions
Copy link

github-actions bot commented Jan 5, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-route53 Related to Amazon Route 53 bug This issue is a bug. effort/small Small work item – less than a day of effort p1
Projects
None yet
Development

No branches or pull requests

3 participants