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

[Bug]: Use correct types #951

Closed
benkeil opened this issue Jul 3, 2024 · 1 comment
Closed

[Bug]: Use correct types #951

benkeil opened this issue Jul 3, 2024 · 1 comment
Labels

Comments

@benkeil
Copy link

benkeil commented Jul 3, 2024

What happened?

The types returned by the resources are unusual.

What did you expect to happen?

Resources return the correct types

Please provide a minimal working example

Example when using the auto generated Provider with CDKTF. Everywhere where a toString() or toLong() appears is something not ok I assume.

import imports.hcloud.data_hcloud_image.DataHcloudImage
import imports.hcloud.firewall.Firewall
import imports.hcloud.firewall.FirewallRule
import imports.hcloud.network.Network
import imports.hcloud.network_subnet.NetworkSubnet
import imports.hcloud.primary_ip.PrimaryIp
import imports.hcloud.server.Server
import imports.hcloud.server.ServerPublicNet
import imports.hcloud.server_network.ServerNetworkA
import imports.hcloud.ssh_key.SshKey
import imports.hcloud.volume.Volume
import imports.hcloud.volume_attachment.VolumeAttachment
import software.constructs.Construct

class HetznerApplicationStack(
    scope: Construct,
    env: Environment,
) : DefaultTerraformStack(scope, "hetzner", env) {
  init {
    val sshKey =
        SshKey.Builder.create(this, "SshKey_Ben_Keil")
            .name("my-public-key")
            .publicKey(env.publicKey)
            .build()

    val documentsVolume =
        Volume.Builder.create(this, "Volume_Documents")
            .name("documents")
            .format("ext4")
            .size(10)
            .build()

    val network =
        Network.Builder.create(this, "Network_Paperless")
            .name(env.service)
            .ipRange("10.0.0.0/8")
            .build()

    NetworkSubnet.Builder.create(this, "Subnet_Paperless")
        .networkId(network.id.toLong())
        .type("cloud")
        .networkZone("eu-central")
        .ipRange("10.0.1.0/24")
        .build()

    val publicIpV4 =
        PrimaryIp.Builder.create(this, "PrimaryIp_V4")
            .name("primary-ip")
            .datacenter("fsn1-dc14")
            .type("ipv4")
            .assigneeType("server")
            .autoDelete(true)
            .build()

    val publicIpV6 =
        PrimaryIp.Builder.create(this, "PrimaryIp_V6")
            .name("primary-ip")
            .datacenter("fsn1-dc14")
            .type("ipv6")
            .assigneeType("server")
            .autoDelete(true)
            .build()

    val firewall =
        Firewall.Builder.create(this, "Firewall")
            .rule(
                listOf(
                    FirewallRule.builder()
                        .direction("in")
                        .protocol("icmp")
                        .sourceIps(listOf("0.0.0.0/0", "::/0"))
                        .build(),
                    FirewallRule.builder()
                        .direction("in")
                        .protocol("tcp")
                        .port("22")
                        .sourceIps(listOf("0.0.0.0/0", "::/0"))
                        .build(),
                ))
            .build()

    val image =
        DataHcloudImage.Builder.create(this, "Image_Ubuntu_24.04")
            .name("ubuntu-24.04")
            .withArchitecture("arm")
            .build()

    val server =
        Server.Builder.create(this, "Server")
            .name(env.service)
            // https://docs.hetzner.com/de/cloud/servers/overview/
            .serverType("CAX11")
            .image(image.id.toString())
            .location("fsn1")
            .datacenter("fsn1-dc14")
            .sshKeys(listOf(sshKey.id))
            .publicNet(
                listOf(
                    ServerPublicNet.builder()
                        .ipv4(publicIpV4.id.toLong())
                        .ipv6(publicIpV6.id.toLong())
                        .ipv4Enabled(true)
                        .ipv6Enabled(true)
                        .build()))
            .firewallIds(listOf(firewall.id.toLong()))
            .build()

    VolumeAttachment.Builder.create(this, "VolumeAttachment_Documents")
        .serverId(server.id.toLong())
        .volumeId(documentsVolume.id.toLong())
        .automount(true)
        .build()

    ServerNetworkA.Builder.create(this, "ServerNetwork")
        .serverId(server.id.toLong())
        .networkId(network.id.toLong())
        .ip("10.0.1.1")
        .build()
  }
}
@benkeil benkeil added the bug label Jul 3, 2024
@apricote
Copy link
Member

apricote commented Jul 9, 2024

Hey @benkeil,

this is something that we noticed while working on #752. The IDs of resources are defined as String while the say that they are integers in the docs, and any resource references also take integers (like serverId/volumeId in your example).

This is not a problem for hcl terraform, as terraform casts this automatically to the right type. We assumed that no one noticed so far, but looks like CDKTF is actually exposing this discrepancy.

We already opened #862 to fix this, so I am going to close this as a duplicate.

@apricote apricote closed this as not planned Won't fix, can't repro, duplicate, stale Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants