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

Fn::Join no longer works with nested Fn:: methods #1076

Closed
elexisvenator opened this issue Nov 5, 2018 · 5 comments
Closed

Fn::Join no longer works with nested Fn:: methods #1076

elexisvenator opened this issue Nov 5, 2018 · 5 comments

Comments

@elexisvenator
Copy link

Problem file: fn.ts
Problem method: FnJoin constructor
Last working version: 5bb7c93 (0.13)
Broke in version: 33c32a8 (current, 0.14.1)

Problem
FN::Join no longer work when the listOfValues parameter contains another function, such as Fn::GetAtt.
For example, this code attempts to output the array of IP addresses for an AD Resource:

import { cloudformation as DirectoryService } from '@aws-cdk/aws-directoryservice';
import { FnJoin } from '@aws-cdk/cdk';

const adResource = new DirectoryService.MicrosoftADResource(this, `MicrosoftADDirectoryService`, {
  vpcSettings: {
    vpcId: vpcId
    // 2 subnets = 2 ip addresses
    subnetIds: [
      subnetA,
      subnetB,
    ],
  },
  // other params here
});

// create an output, works in 0.13.x, not in 0.14.1
const ipAddressOutput = new Output(this, 'MicrosoftAdDnsIpAddresses', {
  value: new FnJoin(',', adResource.microsoftAdDnsIpAddresses.resolve() as string[])
}).makeImportValue().toString()

// workaround
const ipAddressOutput2 = new Output(this, 'MicrosoftAdDnsIpAddresses', {
  value: {
    'Fn::Join': [
      ',',
      adResource.microsoftAdDnsIpAddresses.resolve()
    ]
  },
}).makeImportValue().toString()

Cause(?)
It looks like the latest changes to FN::Join are designed to unpack nested joins, but I don't see how this would work if the join contained a non-join function.
There was a previous commit 5996442 that did something similar, but was rolled back for unrelated reasons. That commit seems to be doing a lot more to make sure there were only nested joins before unpacking them. Maybe that logic can be brought in?

Until then, I am handwriting Fn::Join json objects as a workaround.

@elexisvenator
Copy link
Author

For L2 instances, there is slightly different voodoo you have to do for a workaround. The cast as unknown as string makes me sad :(

return new Ssm.ParameterResource(this, 'MicrosoftAdDnsIpAddressesParam', {
      name: this.domainSsmParameterPrefix + 'directory-dns',
      type: 'StringList',
      value: {
        'Fn::Join': [
          this.delimeter,
          microsoftAdDnsIpAddresses.resolve()
        ]
      } as unknown as string,

@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 5, 2018

Thanks for reporting, having a look

@rix0rrr rix0rrr self-assigned this Nov 5, 2018
@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 5, 2018

I think the issue is in this line:

  value: new FnJoin(',', adResource.microsoftAdDnsIpAddresses.resolve() as string[])

The fact that you were able to bypass the typechecker here and make that work is actually an accident.

Related issues: #674, #744

@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 5, 2018

Your current best workaround will be this:

new Fn('Fn::Join', [', ', adResource.microsoftAdDnsIpAddresses])

Until we sort that issue.

@rix0rrr rix0rrr removed their assignment Nov 5, 2018
@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 5, 2018

I'm going to close this, as your issue is a more specific case of another issue: lack of support for array tokens, and there is a workable workaround for it.

Feel free to reopen if you disagree.

@rix0rrr rix0rrr closed this as completed Nov 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants