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

ContainerPorts in Docker Provider Container getter returns string identifier rather than container ports #434

Closed
Tracked by #525
morganhoke-pm opened this issue Nov 18, 2020 · 7 comments · Fixed by #1725
Labels
bug Something isn't working cdktf schema

Comments

@morganhoke-pm
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

cdktf & Language Versions

Terraform v0.13.2
0.0.18

Affected Resource(s)

Docker provider Container

Expected Behavior

Container.ports should return a list of ContainerPorts.

Actual Behavior

Container.ports returns the fqn of the ContainerPorts object.
console.log(container.ports);
// Log output is ${docker_container.container-name.ports}

Steps to Reproduce

Create a container resource with some ports, then try to access the ports later.

Important Factoids

I ran in to this trying to write an aspect to verify that all containers had unique external ports on their network. I think that the provider code is maybe incorrect, it returns interpolationForAttribute('ports') as any. It could return the private backing field _ports, or the attribute lookup could be updated. I tried retuning getListAttribute, but I got a list of Token (i.e. #{Token[TOKEN.1]}).

@morganhoke-pm morganhoke-pm added the bug Something isn't working label Nov 18, 2020
@morganhoke-pm
Copy link
Author

I just realized that there's portsInput to get the private backing field, but I agree with the comment that this seems dangerous. Ideally we'd have a way to read this back using a get*Attribute. I think the reason getListAttribute didn't work immediately is that it assumes we're always dealing with a list of strings, and it relies on the token library to get those out.

@skorfmann
Copy link
Contributor

Could you provide a complete example (i.e. the stack) to reproduce this?

@morganhoke-pm
Copy link
Author

morganhoke-pm commented Nov 18, 2020

This issue appears pretty widespread--for instance, when getting networks, I get back that similar list of tokens, rather than the expected values.

Here's a truncated sample I'm working with:

class MyStack extends TerraformStack {
 networkId: string;

 constructor(scope: Construct, name: string) {
   super(scope, name);
new DockerProvider(this, 'docker', {
     host: 'tcp://localhost:2375',
     registryAuth: [
       { //redacted
        }
]
   });
const kaijuLocalNetwork = new Network(this, 'kaiju-local', {
     name: 'kaiju-local',
     driver: 'bridge'
   });

   this.networkId = kaijuLocalNetwork.id;
const authImage = new Image(this, 'web-auth', {
     name: 'web-auth-local:latest',
     keepLocally: true
   });
const authContainer = new Container(this, 'web-auth-container', {
     image: authImage.latest,
     restart: 'on-failure',
     name: 'kaiju-web-auth',
     networks: [this.networkId],
     ports: [
       {
         external: 18080,
         internal: 8080
       },
       {
         external: 40000,
         internal: 40000
       }
     ],
     capabilities: [{ add: ['SYS_PTRACE'] }],
     dependsOn: [kaijuLocalNetwork]
   });

   console.log(authContainer.ports); 
}

@morganhoke-pm
Copy link
Author

authContainer.ports there at the end is a string, even though it's typed to ConainerPorts[] in the .d.ts. As a result, when I try to iterate it as an array, it blows up.

For now, I'm able to iterate over portsInput, but my understanding is that the current port getter is intended to get the internal representation, which is closer to what the actual output will be.

@jsteinich
Copy link
Collaborator

I think the reason getListAttribute didn't work immediately is that it assumes we're always dealing with a list of strings, and it relies on the token library to get those out.

It indeed doesn't use getListAttribute because the token system only supports lists of strings currently.

This issue appears pretty widespread

Yes. Some related items are #424 and #25 start to get at some of the pieces. I'll try to work on a longer writeup in the next couple of days explaining in more detail the current situation.

@DanielMSchmidt
Copy link
Contributor

#993 aims to solve this, I'm closing this issue so that we only have one tracking the effort

@github-actions
Copy link
Contributor

I'm going to lock this issue because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you've found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working cdktf schema
Projects
None yet
5 participants