-
Notifications
You must be signed in to change notification settings - Fork 459
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
Comments
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. |
Could you provide a complete example (i.e. the stack) to reproduce this? |
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);
} |
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. |
It indeed doesn't use
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. |
#993 aims to solve this, I'm closing this issue so that we only have one tracking the effort |
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. |
Community Note
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]}).
The text was updated successfully, but these errors were encountered: