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

LoadBalancer "name" cannot be longer than 32 characters #62

Closed
Tracked by #111
lukehoban opened this issue Nov 11, 2022 · 3 comments · Fixed by #227
Closed
Tracked by #111

LoadBalancer "name" cannot be longer than 32 characters #62

lukehoban opened this issue Nov 11, 2022 · 3 comments · Fixed by #227
Assignees
Labels
impact/usability Something that impacts users' ability to use the product easily and intuitively kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Milestone

Comments

@lukehoban
Copy link
Contributor

Question from Community Slack:

I have a question about names and length of names. When set up an sample infrastructure with Pulumi CDK I got this error message when running pulumi preview:

Diagnostics:
  aws:lb:LoadBalancer (loadbalancedserviceLB1BE8EDCE):
    error: aws:lb/loadBalancer:LoadBalancer resource 'loadbalancedserviceLB1BE8EDCE' has a problem: "name" cannot be longer than 32 characters: "loadbalancedserviceLB1BE8EDCE-403d9b7". Examine values at 'LoadBalancer.Name'.

The corresponding code looks like this:

const lbservice = new ApplicationLoadBalancedFargateService(this, 'loadbalanced-service', {
  cluster,
  taskDefinition: taskdef,
  desiredCount: 2,
  serviceName: 'my-service',
  circuitBreaker: { rollback: true },
  publicLoadBalancer: true,
  listenerPort: webserverPort,
});

The name part is not an issue with regular AWS CDK, and Pulumi generates a different (shorter) name than AWS CDK, but still too short compared to name lengths allowed by CloudFormation, it seems. The question is really what to think and consider in terms of name issues here, what would be preferred approaches besides keeping construct id values short - and how many levels will this work out with?

I suspect that the issue is that we should be passing name through explicitly in the mapping linked below if provided (which it will always be I believe?) so that Pulumi doesn't apply it's own autonaming here. If you open an issue on this - we can look into whether that is indeed the right resolution.

case 'AWS::ElasticLoadBalancingV2::LoadBalancer': {

@eriklz
Copy link

eriklz commented Nov 11, 2022

Yes, AWS CDK will always have a name associated with a construct, and the name must be unique at the specific construct/component level. The global name associated with the resource is built from the hierarchy of resource names, with some characters stripped out.

That model can also cause very long names. This tends to become more of a problem with CDK pipelines, since the pipeline itself gets encoded into the name hierarchy and sometimes things hit a 128 character limit and will not work (with CloudFormation). However, if it works to use pretty much the same model, then it will at least be predictable in terms of names compared to AWS CDK (CloudFormation flavour).

@iwahbe iwahbe added impact/usability Something that impacts users' ability to use the product easily and intuitively kind/bug Some behavior is incorrect or out of spec labels Jul 24, 2023
@lukehoban lukehoban mentioned this issue May 18, 2024
6 tasks
@corymhall
Copy link
Contributor

This one is going to be tricky to fix generally. We are using the CloudFormation logicalId which can be up to 128 characters. CloudFormation will then generate a unique resource name using the Stack name and the resource name, but will make sure the generated name fits within any unique service limits.

So for example if I have a stack with the name AwsCdkTestAppStack and a LB with the logicalId myapplicationloadbalancerwithalongname802BEFCA, I might end up with a resource name of AwsCdk-myapp-ed0Q19JSgqxi

I can think of a couple of options

  1. Let the user override the CloudFormation logicalId
(lb.node.defaultChild as CfnResource).overrideLogicalId('shortername');
  1. Update the aws-native autonaming implementation to modify the names to be within the max characters rather than throw an error

  2. pulumi-cdk could process the schema similar to autonaming and modify the logicalId if it is too long.

@mjeffryes mjeffryes added this to the 0.113 milestone Nov 13, 2024
corymhall added a commit to pulumi/pulumi-aws-native that referenced this issue Nov 14, 2024
Most resources have some limits on what the resource name can be.
Unfortunately a lot of those limits are not currently stored in the
CloudFormation schema.

This PR introduces a new schema overlay where we can manually store
min/max length constraints for resource names.

This is the first step in addressing #1816. I will follow this up with
another PR to trim names to fit within the constraints.

re #1816, re pulumi/pulumi-cdk#62
corymhall added a commit to pulumi/pulumi-aws-native that referenced this issue Nov 14, 2024
Most resources have some limits on what the resource name can be.
Unfortunately a lot of those limits are not currently stored in the
CloudFormation schema.

This PR introduces a new schema overlay where we can manually store
min/max length constraints for resource names.

This is the first step in addressing #1816. I will follow this up with
another PR to trim names to fit within the constraints.

re #1816, re pulumi/pulumi-cdk#62
corymhall added a commit to pulumi/pulumi-aws-native that referenced this issue Nov 14, 2024
This PR adds some new functionality to control the auto naming behavior.
The new behavior lives behind a provider config variable and must be
explicitly enabled by the user. The existing behavior will remain the
default behavior of the provider.

**What's new**

- `autoTrim`: When this is set to true the provider will automatically
  trim the generated name to fit within the `maxLength` requirement.
- `randomSuffixMinLength`: Set this to control the minimum length of the
  random suffix that is generated. This is especially useful in
  combination with `autoTrim` to ensure that you still end up with
  unique names (e.g. a random suffix of 1 character is not very unique)

closes #1816, re pulumi/pulumi-cdk#62
corymhall added a commit to pulumi/pulumi-aws-native that referenced this issue Nov 18, 2024
This PR adds some new functionality to control the auto naming behavior.
The new behavior lives behind a provider config variable and must be
explicitly enabled by the user. The existing behavior will remain the
default behavior of the provider.

**What's new**

- `autoTrim`: When this is set to true the provider will automatically
  trim the generated name to fit within the `maxLength` requirement.
- `randomSuffixMinLength`: Set this to control the minimum length of the
  random suffix that is generated. This is especially useful in
  combination with `autoTrim` to ensure that you still end up with
  unique names (e.g. a random suffix of 1 character is not very unique)

closes #1816, re
pulumi/pulumi-cdk#62
@corymhall corymhall assigned corymhall and unassigned flostadler Nov 18, 2024
corymhall added a commit that referenced this issue Nov 18, 2024
This PR enables the aws-native `AutoNaming.autoTrim` feature by default.
It does this by creating an aws-native provider by default if the user
does not provide one.

I've updated tests to remove the workarounds.

**Alternatives**

1. We could require that the user configure this themselves.
2. Is there a way to set config values programatically?

closes #62, closes #70
corymhall added a commit that referenced this issue Nov 18, 2024
This PR enables the aws-native `AutoNaming.autoTrim` feature by default.
It does this by creating an aws-native provider by default if the user
does not provide one.

I've updated tests to remove the workarounds.

**Alternatives**

1. We could require that the user configure this themselves.
2. Is there a way to set config values programatically?

closes #62, closes #70
corymhall added a commit that referenced this issue Nov 19, 2024
This PR enables the aws-native `AutoNaming.autoTrim` feature by default.
It does this by creating an aws-native provider by default if the user
does not provide one.

I've updated tests to remove the workarounds.

**Alternatives**

1. We could require that the user configure this themselves.
2. Is there a way to set config values programatically?

closes #62, closes #70
@pulumi-bot pulumi-bot added the resolution/fixed This issue was fixed label Nov 19, 2024
@pulumi-bot
Copy link
Contributor

This issue has been addressed in PR #227 and shipped in release v1.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impact/usability Something that impacts users' ability to use the product easily and intuitively kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants