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

Incorrect index accessor against optional property #11495

Closed
danielrbradley opened this issue Nov 30, 2022 · 2 comments
Closed

Incorrect index accessor against optional property #11495

danielrbradley opened this issue Nov 30, 2022 · 2 comments
Labels
area/codegen SDK-gen, program-gen, convert kind/bug Some behavior is incorrect or out of spec language/javascript resolution/duplicate This issue is a duplicate of another issue

Comments

@danielrbradley
Copy link
Member

danielrbradley commented Nov 30, 2022

What happened?

Attempting to access a nested property within an optional array property generates invalid TypeScript code.

Steps to reproduce

Run pulumi convert --language typescript --out typescript for the following YAML program.

variables:
  appName: my-app
resources:
  repository:
    type: awsx:ecr:Repository
  image:
    type: awsx:ecr:Image
    properties:
      repositoryUrl: ${repository.url}
      path: "./app"
  cluster:
    type: eks:Cluster
  clusterProvider:
    type: pulumi:providers:kubernetes
    properties:
      kubeconfig: ${cluster.kubeconfig}
      enableServerSideApply: true
  deployment:
    type: kubernetes:apps/v1:Deployment
    properties:
      metadata:
        labels:
          appClass: ${appName}
      spec:
        replicas: 2
        selector:
          matchLabels:
            appClass: ${appName}
        template:
          metadata:
            labels:
              appClass: ${appName}
          spec:
            containers:
              - name: ${appName}
                image: ${image.imageUri}
                ports:
                  - name: http
                    containerPort: 80
    options:
      provider: ${clusterProvider}
  service:
    type: kubernetes:core/v1:Service
    properties:
      metadata:
        labels:
          appClass: ${appName}
      spec:
        type: LoadBalancer
        selector:
          appClass: ${appName}
        ports:
          - port: 80
            targetPort: http
    options:
      provider: ${clusterProvider}
outputs:
  url: ${service.status.loadBalancer.ingress[0].hostname}

Expected Behavior

Output should be generated as:

export const url = service.status.apply(status => status?.loadBalancer?.ingress?.[0]?.hostname);

Actual Behavior

Output should be generated as:

export const url = service.status.apply(status => status?.loadBalancer?.ingress?[0]?.hostname);

Required change is a single dot:

-export const url = service.status.apply(status => status?.loadBalancer?.ingress?[0]?.hostname);
+export const url = service.status.apply(status => status?.loadBalancer?.ingress?.[0]?.hostname);

Output of pulumi about

CLI          
Version      3.48.0
Go Version   go1.19.3
Go Compiler  gc

Plugins
NAME        VERSION
awsx        unknown
eks         unknown
kubernetes  unknown
yaml        unknown

Host     
OS       darwin
Version  13.0.1
Arch     arm64

Current Stack: dev

Found no resources associated with dev

Found no pending operations associated with dev

Backend        
Name           pulumi.com
URL            https://app.pulumi.com/daniel-pulumi
User           daniel-pulumi
Organizations  daniel-pulumi, pulumi

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

@danielrbradley danielrbradley added kind/bug Some behavior is incorrect or out of spec language/javascript area/codegen SDK-gen, program-gen, convert needs-triage Needs attention from the triage team labels Nov 30, 2022
@justinvp justinvp added resolution/duplicate This issue is a duplicate of another issue and removed needs-triage Needs attention from the triage team labels Nov 30, 2022
@justinvp
Copy link
Member

I believe this is a dupe of #8068 which was fixed 2 days ago by #11477

@danielrbradley
Copy link
Member Author

Bah! I searched, but guess I missed it because it was closed 😆 Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/codegen SDK-gen, program-gen, convert kind/bug Some behavior is incorrect or out of spec language/javascript resolution/duplicate This issue is a duplicate of another issue
Projects
None yet
Development

No branches or pull requests

2 participants