All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.io.cloudshiftdev.awscdklib.network.NatEipPool.kt Maven / Gradle / Ivy

There is a newer version: 10.1.0
Show newest version
package io.cloudshiftdev.awscdklib.network

import io.cloudshiftdev.awscdk.CfnOutput
import io.cloudshiftdev.awscdk.RemovalPolicy
import io.cloudshiftdev.awscdk.services.ec2.CfnEIP
import io.cloudshiftdev.constructs.Construct

public class NatEipPool(scope: Construct, id: String, poolSize: Int) : Construct(scope, id) {
    public val eips: List

    init {
        var count = 1
        val eipConstructs =
            generateSequence { (count++).takeIf { it <= poolSize } }
                .map {
                    val eip = CfnEIP(this, "EIP$it") { domain("vpc") }
                    eip.applyRemovalPolicy(RemovalPolicy.RETAIN)
                    eip
                }
                .toList()

        eips = eipConstructs.map { it.attrAllocationId() }

        eipConstructs.forEachIndexed { idx, eip ->
            val outputId = "natPublicIp${idx + 1}"
            CfnOutput(scope, outputId) { value(eip.attrPublicIp()) }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy