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

com.pulumi.digitalocean.kotlin.LoadBalancer.kt Maven / Gradle / Ivy

@file:Suppress("NAME_SHADOWING", "DEPRECATION")

package com.pulumi.digitalocean.kotlin

import com.pulumi.core.Output
import com.pulumi.digitalocean.kotlin.outputs.LoadBalancerDomain
import com.pulumi.digitalocean.kotlin.outputs.LoadBalancerFirewall
import com.pulumi.digitalocean.kotlin.outputs.LoadBalancerForwardingRule
import com.pulumi.digitalocean.kotlin.outputs.LoadBalancerGlbSettings
import com.pulumi.digitalocean.kotlin.outputs.LoadBalancerHealthcheck
import com.pulumi.digitalocean.kotlin.outputs.LoadBalancerStickySessions
import com.pulumi.kotlin.KotlinCustomResource
import com.pulumi.kotlin.PulumiTagMarker
import com.pulumi.kotlin.ResourceMapper
import com.pulumi.kotlin.options.CustomResourceOptions
import com.pulumi.kotlin.options.CustomResourceOptionsBuilder
import com.pulumi.resources.Resource
import kotlin.Boolean
import kotlin.Deprecated
import kotlin.Int
import kotlin.String
import kotlin.Suppress
import kotlin.Unit
import kotlin.collections.List
import com.pulumi.digitalocean.kotlin.outputs.LoadBalancerDomain.Companion.toKotlin as loadBalancerDomainToKotlin
import com.pulumi.digitalocean.kotlin.outputs.LoadBalancerFirewall.Companion.toKotlin as loadBalancerFirewallToKotlin
import com.pulumi.digitalocean.kotlin.outputs.LoadBalancerForwardingRule.Companion.toKotlin as loadBalancerForwardingRuleToKotlin
import com.pulumi.digitalocean.kotlin.outputs.LoadBalancerGlbSettings.Companion.toKotlin as loadBalancerGlbSettingsToKotlin
import com.pulumi.digitalocean.kotlin.outputs.LoadBalancerHealthcheck.Companion.toKotlin as loadBalancerHealthcheckToKotlin
import com.pulumi.digitalocean.kotlin.outputs.LoadBalancerStickySessions.Companion.toKotlin as loadBalancerStickySessionsToKotlin

/**
 * Builder for [LoadBalancer].
 */
@PulumiTagMarker
public class LoadBalancerResourceBuilder internal constructor() {
    public var name: String? = null

    public var args: LoadBalancerArgs = LoadBalancerArgs()

    public var opts: CustomResourceOptions = CustomResourceOptions()

    /**
     * @param name The _unique_ name of the resulting resource.
     */
    public fun name(`value`: String) {
        this.name = value
    }

    /**
     * @param block The arguments to use to populate this resource's properties.
     */
    public suspend fun args(block: suspend LoadBalancerArgsBuilder.() -> Unit) {
        val builder = LoadBalancerArgsBuilder()
        block(builder)
        this.args = builder.build()
    }

    /**
     * @param block A bag of options that control this resource's behavior.
     */
    public suspend fun opts(block: suspend CustomResourceOptionsBuilder.() -> Unit) {
        this.opts = com.pulumi.kotlin.options.CustomResourceOptions.opts(block)
    }

    internal fun build(): LoadBalancer {
        val builtJavaResource = com.pulumi.digitalocean.LoadBalancer(
            this.name,
            this.args.toJava(),
            this.opts.toJava(),
        )
        return LoadBalancer(builtJavaResource)
    }
}

/**
 * Provides a DigitalOcean Load Balancer resource. This can be used to create,
 * modify, and delete Load Balancers.
 * ## Example Usage
 * 
 * ```typescript
 * import * as pulumi from "@pulumi/pulumi";
 * import * as digitalocean from "@pulumi/digitalocean";
 * const web = new digitalocean.Droplet("web", {
 *     name: "web-1",
 *     size: digitalocean.DropletSlug.DropletS1VCPU1GB,
 *     image: "ubuntu-18-04-x64",
 *     region: digitalocean.Region.NYC3,
 * });
 * const _public = new digitalocean.LoadBalancer("public", {
 *     name: "loadbalancer-1",
 *     region: digitalocean.Region.NYC3,
 *     forwardingRules: [{
 *         entryPort: 80,
 *         entryProtocol: "http",
 *         targetPort: 80,
 *         targetProtocol: "http",
 *     }],
 *     healthcheck: {
 *         port: 22,
 *         protocol: "tcp",
 *     },
 *     dropletIds: [web.id],
 * });
 * ```
 * ```python
 * import pulumi
 * import pulumi_digitalocean as digitalocean
 * web = digitalocean.Droplet("web",
 *     name="web-1",
 *     size=digitalocean.DropletSlug.DROPLET_S1_VCPU1_GB,
 *     image="ubuntu-18-04-x64",
 *     region=digitalocean.Region.NYC3)
 * public = digitalocean.LoadBalancer("public",
 *     name="loadbalancer-1",
 *     region=digitalocean.Region.NYC3,
 *     forwarding_rules=[{
 *         "entry_port": 80,
 *         "entry_protocol": "http",
 *         "target_port": 80,
 *         "target_protocol": "http",
 *     }],
 *     healthcheck={
 *         "port": 22,
 *         "protocol": "tcp",
 *     },
 *     droplet_ids=[web.id])
 * ```
 * ```csharp
 * using System.Collections.Generic;
 * using System.Linq;
 * using Pulumi;
 * using DigitalOcean = Pulumi.DigitalOcean;
 * return await Deployment.RunAsync(() =>
 * {
 *     var web = new DigitalOcean.Droplet("web", new()
 *     {
 *         Name = "web-1",
 *         Size = DigitalOcean.DropletSlug.DropletS1VCPU1GB,
 *         Image = "ubuntu-18-04-x64",
 *         Region = DigitalOcean.Region.NYC3,
 *     });
 *     var @public = new DigitalOcean.LoadBalancer("public", new()
 *     {
 *         Name = "loadbalancer-1",
 *         Region = DigitalOcean.Region.NYC3,
 *         ForwardingRules = new[]
 *         {
 *             new DigitalOcean.Inputs.LoadBalancerForwardingRuleArgs
 *             {
 *                 EntryPort = 80,
 *                 EntryProtocol = "http",
 *                 TargetPort = 80,
 *                 TargetProtocol = "http",
 *             },
 *         },
 *         Healthcheck = new DigitalOcean.Inputs.LoadBalancerHealthcheckArgs
 *         {
 *             Port = 22,
 *             Protocol = "tcp",
 *         },
 *         DropletIds = new[]
 *         {
 *             web.Id,
 *         },
 *     });
 * });
 * ```
 * ```go
 * package main
 * import (
 * 	"github.com/pulumi/pulumi-digitalocean/sdk/v4/go/digitalocean"
 * 	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
 * )
 * func main() {
 * 	pulumi.Run(func(ctx *pulumi.Context) error {
 * 		web, err := digitalocean.NewDroplet(ctx, "web", &digitalocean.DropletArgs{
 * 			Name:   pulumi.String("web-1"),
 * 			Size:   pulumi.String(digitalocean.DropletSlugDropletS1VCPU1GB),
 * 			Image:  pulumi.String("ubuntu-18-04-x64"),
 * 			Region: pulumi.String(digitalocean.RegionNYC3),
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		_, err = digitalocean.NewLoadBalancer(ctx, "public", &digitalocean.LoadBalancerArgs{
 * 			Name:   pulumi.String("loadbalancer-1"),
 * 			Region: pulumi.String(digitalocean.RegionNYC3),
 * 			ForwardingRules: digitalocean.LoadBalancerForwardingRuleArray{
 * 				&digitalocean.LoadBalancerForwardingRuleArgs{
 * 					EntryPort:      pulumi.Int(80),
 * 					EntryProtocol:  pulumi.String("http"),
 * 					TargetPort:     pulumi.Int(80),
 * 					TargetProtocol: pulumi.String("http"),
 * 				},
 * 			},
 * 			Healthcheck: &digitalocean.LoadBalancerHealthcheckArgs{
 * 				Port:     pulumi.Int(22),
 * 				Protocol: pulumi.String("tcp"),
 * 			},
 * 			DropletIds: pulumi.IntArray{
 * 				web.ID(),
 * 			},
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		return nil
 * 	})
 * }
 * ```
 * ```java
 * package generated_program;
 * import com.pulumi.Context;
 * import com.pulumi.Pulumi;
 * import com.pulumi.core.Output;
 * import com.pulumi.digitalocean.Droplet;
 * import com.pulumi.digitalocean.DropletArgs;
 * import com.pulumi.digitalocean.LoadBalancer;
 * import com.pulumi.digitalocean.LoadBalancerArgs;
 * import com.pulumi.digitalocean.inputs.LoadBalancerForwardingRuleArgs;
 * import com.pulumi.digitalocean.inputs.LoadBalancerHealthcheckArgs;
 * import java.util.List;
 * import java.util.ArrayList;
 * import java.util.Map;
 * import java.io.File;
 * import java.nio.file.Files;
 * import java.nio.file.Paths;
 * public class App {
 *     public static void main(String[] args) {
 *         Pulumi.run(App::stack);
 *     }
 *     public static void stack(Context ctx) {
 *         var web = new Droplet("web", DropletArgs.builder()
 *             .name("web-1")
 *             .size("s-1vcpu-1gb")
 *             .image("ubuntu-18-04-x64")
 *             .region("nyc3")
 *             .build());
 *         var public_ = new LoadBalancer("public", LoadBalancerArgs.builder()
 *             .name("loadbalancer-1")
 *             .region("nyc3")
 *             .forwardingRules(LoadBalancerForwardingRuleArgs.builder()
 *                 .entryPort(80)
 *                 .entryProtocol("http")
 *                 .targetPort(80)
 *                 .targetProtocol("http")
 *                 .build())
 *             .healthcheck(LoadBalancerHealthcheckArgs.builder()
 *                 .port(22)
 *                 .protocol("tcp")
 *                 .build())
 *             .dropletIds(web.id())
 *             .build());
 *     }
 * }
 * ```
 * ```yaml
 * resources:
 *   web:
 *     type: digitalocean:Droplet
 *     properties:
 *       name: web-1
 *       size: s-1vcpu-1gb
 *       image: ubuntu-18-04-x64
 *       region: nyc3
 *   public:
 *     type: digitalocean:LoadBalancer
 *     properties:
 *       name: loadbalancer-1
 *       region: nyc3
 *       forwardingRules:
 *         - entryPort: 80
 *           entryProtocol: http
 *           targetPort: 80
 *           targetProtocol: http
 *       healthcheck:
 *         port: 22
 *         protocol: tcp
 *       dropletIds:
 *         - ${web.id}
 * ```
 * 
 * When managing certificates attached to the load balancer, make sure to add the `create_before_destroy`
 * lifecycle property in order to ensure the certificate is correctly updated when changed. The order of
 * operations will then be: `Create new certificate` > `Update loadbalancer with new certificate` ->
 * `Delete old certificate`. When doing so, you must also change the name of the certificate,
 * as there cannot be multiple certificates with the same name in an account.
 * ## Import
 * Load Balancers can be imported using the `id`, e.g.
 * ```sh
 * $ pulumi import digitalocean:index/loadBalancer:LoadBalancer myloadbalancer 4de7ac8b-495b-4884-9a69-1050c6793cd6
 * ```
 */
public class LoadBalancer internal constructor(
    override val javaResource: com.pulumi.digitalocean.LoadBalancer,
) : KotlinCustomResource(javaResource, LoadBalancerMapper) {
    /**
     * **Deprecated** This field has been deprecated. You can no longer specify an algorithm for load balancers.
     * or `least_connections`. The default value is `round_robin`.
     */
    @Deprecated(
        message = """
  This field has been deprecated. You can no longer specify an algorithm for load balancers.
  """,
    )
    public val algorithm: Output?
        get() = javaResource.algorithm().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })

    /**
     * A boolean value indicating whether to disable automatic DNS record creation for Let's Encrypt certificates that are added to the load balancer. Default value is `false`.
     */
    public val disableLetsEncryptDnsRecords: Output?
        get() = javaResource.disableLetsEncryptDnsRecords().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * A list of `domains` required to ingress traffic to a Global Load Balancer. The `domains` block is documented below.
     * **NOTE**: this is a closed beta feature and not available for public use.
     */
    public val domains: Output>
        get() = javaResource.domains().applyValue({ args0 ->
            args0.map({ args0 ->
                args0.let({ args0 ->
                    loadBalancerDomainToKotlin(args0)
                })
            })
        })

    /**
     * A list of the IDs of each droplet to be attached to the Load Balancer.
     */
    public val dropletIds: Output>
        get() = javaResource.dropletIds().applyValue({ args0 -> args0.map({ args0 -> args0 }) })

    /**
     * The name of a Droplet tag corresponding to Droplets to be assigned to the Load Balancer.
     */
    public val dropletTag: Output?
        get() = javaResource.dropletTag().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * A boolean value indicating whether HTTP keepalive connections are maintained to target Droplets. Default value is `false`.
     */
    public val enableBackendKeepalive: Output?
        get() = javaResource.enableBackendKeepalive().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * A boolean value indicating whether PROXY
     * Protocol should be used to pass information from connecting client requests to
     * the backend service. Default value is `false`.
     */
    public val enableProxyProtocol: Output?
        get() = javaResource.enableProxyProtocol().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * A block containing rules for allowing/denying traffic to the Load Balancer. The `firewall` block is documented below. Only 1 firewall is allowed.
     */
    public val firewall: Output
        get() = javaResource.firewall().applyValue({ args0 ->
            args0.let({ args0 ->
                loadBalancerFirewallToKotlin(args0)
            })
        })

    /**
     * A list of `forwarding_rule` to be assigned to the
     * Load Balancer. The `forwarding_rule` block is documented below.
     */
    public val forwardingRules: Output>?
        get() = javaResource.forwardingRules().applyValue({ args0 ->
            args0.map({ args0 ->
                args0.map({ args0 ->
                    args0.let({ args0 ->
                        loadBalancerForwardingRuleToKotlin(args0)
                    })
                })
            }).orElse(null)
        })

    /**
     * A block containing `glb_settings` required to define target rules for a Global Load Balancer. The `glb_settings` block is documented below.
     * **NOTE**: this is a closed beta feature and not available for public use.
     */
    public val glbSettings: Output
        get() = javaResource.glbSettings().applyValue({ args0 ->
            args0.let({ args0 ->
                loadBalancerGlbSettingsToKotlin(args0)
            })
        })

    /**
     * A `healthcheck` block to be assigned to the
     * Load Balancer. The `healthcheck` block is documented below. Only 1 healthcheck is allowed.
     */
    public val healthcheck: Output
        get() = javaResource.healthcheck().applyValue({ args0 ->
            args0.let({ args0 ->
                loadBalancerHealthcheckToKotlin(args0)
            })
        })

    /**
     * Specifies the idle timeout for HTTPS connections on the load balancer in seconds.
     */
    public val httpIdleTimeoutSeconds: Output
        get() = javaResource.httpIdleTimeoutSeconds().applyValue({ args0 -> args0 })

    /**
     * The ip of the Load Balancer
     */
    public val ip: Output
        get() = javaResource.ip().applyValue({ args0 -> args0 })

    /**
     * The uniform resource name for the Load Balancer
     */
    public val loadBalancerUrn: Output
        get() = javaResource.loadBalancerUrn().applyValue({ args0 -> args0 })

    /**
     * The Load Balancer name
     */
    public val name: Output
        get() = javaResource.name().applyValue({ args0 -> args0 })

    /**
     * The type of network the Load Balancer is accessible from. It must be either of `INTERNAL` or `EXTERNAL`. Defaults to `EXTERNAL`.
     * **NOTE**: non-`EXTERNAL` type may be part of closed beta feature and not available for public use.
     */
    public val network: Output?
        get() = javaResource.network().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })

    /**
     * The ID of the project that the load balancer is associated with. If no ID is provided at creation, the load balancer associates with the user's default project.
     */
    public val projectId: Output
        get() = javaResource.projectId().applyValue({ args0 -> args0 })

    /**
     * A boolean value indicating whether
     * HTTP requests to the Load Balancer on port 80 will be redirected to HTTPS on port 443.
     * Default value is `false`.
     */
    public val redirectHttpToHttps: Output?
        get() = javaResource.redirectHttpToHttps().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * The region to start in
     */
    public val region: Output?
        get() = javaResource.region().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })

    /**
     * The size of the Load Balancer. It must be either `lb-small`, `lb-medium`, or `lb-large`. Defaults to `lb-small`. Only one of `size` or `size_unit` may be provided.
     */
    public val size: Output?
        get() = javaResource.size().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })

    /**
     * The size of the Load Balancer. It must be in the range (1, 100). Defaults to `1`. Only one of `size` or `size_unit` may be provided.
     */
    public val sizeUnit: Output
        get() = javaResource.sizeUnit().applyValue({ args0 -> args0 })

    public val status: Output
        get() = javaResource.status().applyValue({ args0 -> args0 })

    /**
     * A `sticky_sessions` block to be assigned to the
     * Load Balancer. The `sticky_sessions` block is documented below. Only 1 sticky_sessions block is allowed.
     */
    public val stickySessions: Output
        get() = javaResource.stickySessions().applyValue({ args0 ->
            args0.let({ args0 ->
                loadBalancerStickySessionsToKotlin(args0)
            })
        })

    /**
     * A list of Load Balancer IDs to be attached behind a Global Load Balancer.
     * **NOTE**: this is a closed beta feature and not available for public use.
     */
    public val targetLoadBalancerIds: Output>
        get() = javaResource.targetLoadBalancerIds().applyValue({ args0 -> args0.map({ args0 -> args0 }) })

    /**
     * The type of the Load Balancer. It must be either of `REGIONAL` or `GLOBAL`. Defaults to `REGIONAL`.
     * **NOTE**: non-`REGIONAL` type may be part of closed beta feature and not available for public use.
     */
    public val type: Output?
        get() = javaResource.type().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })

    /**
     * The ID of the VPC where the load balancer will be located.
     */
    public val vpcUuid: Output
        get() = javaResource.vpcUuid().applyValue({ args0 -> args0 })
}

public object LoadBalancerMapper : ResourceMapper {
    override fun supportsMappingOfType(javaResource: Resource): Boolean =
        com.pulumi.digitalocean.LoadBalancer::class == javaResource::class

    override fun map(javaResource: Resource): LoadBalancer = LoadBalancer(
        javaResource as
            com.pulumi.digitalocean.LoadBalancer,
    )
}

/**
 * @see [LoadBalancer].
 * @param name The _unique_ name of the resulting resource.
 * @param block Builder for [LoadBalancer].
 */
public suspend fun loadBalancer(
    name: String,
    block: suspend LoadBalancerResourceBuilder.() -> Unit,
): LoadBalancer {
    val builder = LoadBalancerResourceBuilder()
    builder.name(name)
    block(builder)
    return builder.build()
}

/**
 * @see [LoadBalancer].
 * @param name The _unique_ name of the resulting resource.
 */
public fun loadBalancer(name: String): LoadBalancer {
    val builder = LoadBalancerResourceBuilder()
    builder.name(name)
    return builder.build()
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy