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

synth: Unresolved condition dependency using CfnCondition from another stack #26560

Open
matusfaro opened this issue Jul 28, 2023 · 2 comments
Open
Labels
bug This issue is a bug. effort/medium Medium work item – several days of effort p2 package/tools Related to AWS CDK Tools or CLI

Comments

@matusfaro
Copy link

Describe the bug

Using a CfnCondition created in another stack causes an unresolved dependency. The condition is defined in the other stack while the stack that is using it does not have "conditions" defined in CloudFormation.

Expected Behavior

I would expect the condition to be created in all the stacks that need it. Unless a condition can be an output of a stack that can be consumed by another stack? I'm unsure of the inner workings.

Current Behavior

Current stack B uses the condition dsdnsconditionemptysubdomainstaging created in another stack A:

     "Fn::Join": [
      "api",
      [
       ".",
       {
        "Fn::If": [
         "dsdnsconditionemptysubdomainstaging",
         {
          "Fn::ImportValue": "ds-dns-staging:ExportsOutputRefdnsDomain91549E00"
         },
         {
          "Fn::ImportValue": "ds-dns-staging:ExportsOutputRefdnsDomain91549E00"
         }
        ]
       }
      ]
     ]
    },

while only the other stack A has the condition defined:

 "Conditions": {
  "dsdnsconditionemptysubdomainstaging": {
   "Fn::Equals": [
    {
     "Ref": "dnsSubdomain"
    },
    ""
   ]
  },

Reproduction Steps

        App app = new App();
        StackA stackA = new StackA(app);
        new StackB(app, stackA);
        app.synth();
class StackA extends Stack {
        String fqdn;
        public StackA (...) {
             fqdn = Fn.join(
                "...",
                List.of(Fn.conditionIf(
                        // If subdomain is empty
                        CfnCondition.Builder.create(scope, "condition-empty-subdomain")
                                .expression(Fn.conditionEquals(dnsSubdomainParam.getValueAsString(), ""))
                                .build()
                                .getLogicalId(),
                        // Then supply the domain only
                        dnsDomainParam.getValueAsString(),
                        // Else prefix the domain with a dot to separate the subdomain
                        Fn.join(".", List.of(dnsDomainParam.getValueAsString()))
                ).toString()));
        }
}
class StackB extends Stack {
        public StackB (..., StackA stackA) {
                  // Use stackA.fqdn
        }
}

Error msg:

Template error: unresolved condition dependency dsdnsconditionemptysubdomainstaging in Fn::If

Possible Solution

Workaround is to create the CfnCondition in every stack.

Additional Information/Context

No response

CDK CLI Version

2.77.0

Framework Version

No response

Node.js Version

16

OS

osx 14

Language

Java

Language Version

Java 11

Other information

No response

@matusfaro matusfaro added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 28, 2023
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Jul 28, 2023
@pahud
Copy link
Contributor

pahud commented Jul 31, 2023

Are you creating the CfnCondition in stackA and evaluate that condition in StackB with Fn::If?

@pahud pahud added p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jul 31, 2023
@matusfaro
Copy link
Author

matusfaro commented Jul 31, 2023

Are you creating the CfnCondition in stackA and evaluate that condition in StackB with Fn::If?

Yes, as a workaround I am creating the condition and parameters on both stacks. But the same code does not work when you create it in one stack and attempt to use it in the other.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. effort/medium Medium work item – several days of effort p2 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

No branches or pull requests

2 participants