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

com.pulumi.cloudflare.kotlin.Healthcheck.kt Maven / Gradle / Ivy

Go to download

Build cloud applications and infrastructure by combining the safety and reliability of infrastructure as code with the power of the Kotlin programming language.

There is a newer version: 5.40.0.0
Show newest version
@file:Suppress("NAME_SHADOWING", "DEPRECATION")

package com.pulumi.cloudflare.kotlin

import com.pulumi.cloudflare.kotlin.outputs.HealthcheckHeader
import com.pulumi.cloudflare.kotlin.outputs.HealthcheckHeader.Companion.toKotlin
import com.pulumi.core.Output
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.Int
import kotlin.String
import kotlin.Suppress
import kotlin.Unit
import kotlin.collections.List

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

    public var args: HealthcheckArgs = HealthcheckArgs()

    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 HealthcheckArgsBuilder.() -> Unit) {
        val builder = HealthcheckArgsBuilder()
        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(): Healthcheck {
        val builtJavaResource = com.pulumi.cloudflare.Healthcheck(
            this.name,
            this.args.toJava(),
            this.opts.toJava(),
        )
        return Healthcheck(builtJavaResource)
    }
}

/**
 * Standalone Health Checks provide a way to monitor origin servers
 * without needing a Cloudflare Load Balancer.
 * ## Example Usage
 * 
 * ```typescript
 * import * as pulumi from "@pulumi/pulumi";
 * import * as cloudflare from "@pulumi/cloudflare";
 * // HTTPS Healthcheck
 * const httpHealthCheck = new cloudflare.Healthcheck("http_health_check", {
 *     zoneId: cloudflareZoneId,
 *     name: "http-health-check",
 *     description: "example http health check",
 *     address: "example.com",
 *     suspended: false,
 *     checkRegions: [
 *         "WEU",
 *         "EEU",
 *     ],
 *     type: "HTTPS",
 *     port: 443,
 *     method: "GET",
 *     path: "/health",
 *     expectedBody: "alive",
 *     expectedCodes: [
 *         "2xx",
 *         "301",
 *     ],
 *     followRedirects: true,
 *     allowInsecure: false,
 *     headers: [{
 *         header: "Host",
 *         values: ["example.com"],
 *     }],
 *     timeout: 10,
 *     retries: 2,
 *     interval: 60,
 *     consecutiveFails: 3,
 *     consecutiveSuccesses: 2,
 * });
 * // TCP Healthcheck
 * const tcpHealthCheck = new cloudflare.Healthcheck("tcp_health_check", {
 *     zoneId: cloudflareZoneId,
 *     name: "tcp-health-check",
 *     description: "example tcp health check",
 *     address: "example.com",
 *     suspended: false,
 *     checkRegions: [
 *         "WEU",
 *         "EEU",
 *     ],
 *     type: "TCP",
 *     port: 22,
 *     method: "connection_established",
 *     timeout: 10,
 *     retries: 2,
 *     interval: 60,
 *     consecutiveFails: 3,
 *     consecutiveSuccesses: 2,
 * });
 * ```
 * ```python
 * import pulumi
 * import pulumi_cloudflare as cloudflare
 * # HTTPS Healthcheck
 * http_health_check = cloudflare.Healthcheck("http_health_check",
 *     zone_id=cloudflare_zone_id,
 *     name="http-health-check",
 *     description="example http health check",
 *     address="example.com",
 *     suspended=False,
 *     check_regions=[
 *         "WEU",
 *         "EEU",
 *     ],
 *     type="HTTPS",
 *     port=443,
 *     method="GET",
 *     path="/health",
 *     expected_body="alive",
 *     expected_codes=[
 *         "2xx",
 *         "301",
 *     ],
 *     follow_redirects=True,
 *     allow_insecure=False,
 *     headers=[{
 *         "header": "Host",
 *         "values": ["example.com"],
 *     }],
 *     timeout=10,
 *     retries=2,
 *     interval=60,
 *     consecutive_fails=3,
 *     consecutive_successes=2)
 * # TCP Healthcheck
 * tcp_health_check = cloudflare.Healthcheck("tcp_health_check",
 *     zone_id=cloudflare_zone_id,
 *     name="tcp-health-check",
 *     description="example tcp health check",
 *     address="example.com",
 *     suspended=False,
 *     check_regions=[
 *         "WEU",
 *         "EEU",
 *     ],
 *     type="TCP",
 *     port=22,
 *     method="connection_established",
 *     timeout=10,
 *     retries=2,
 *     interval=60,
 *     consecutive_fails=3,
 *     consecutive_successes=2)
 * ```
 * ```csharp
 * using System.Collections.Generic;
 * using System.Linq;
 * using Pulumi;
 * using Cloudflare = Pulumi.Cloudflare;
 * return await Deployment.RunAsync(() =>
 * {
 *     // HTTPS Healthcheck
 *     var httpHealthCheck = new Cloudflare.Healthcheck("http_health_check", new()
 *     {
 *         ZoneId = cloudflareZoneId,
 *         Name = "http-health-check",
 *         Description = "example http health check",
 *         Address = "example.com",
 *         Suspended = false,
 *         CheckRegions = new[]
 *         {
 *             "WEU",
 *             "EEU",
 *         },
 *         Type = "HTTPS",
 *         Port = 443,
 *         Method = "GET",
 *         Path = "/health",
 *         ExpectedBody = "alive",
 *         ExpectedCodes = new[]
 *         {
 *             "2xx",
 *             "301",
 *         },
 *         FollowRedirects = true,
 *         AllowInsecure = false,
 *         Headers = new[]
 *         {
 *             new Cloudflare.Inputs.HealthcheckHeaderArgs
 *             {
 *                 Header = "Host",
 *                 Values = new[]
 *                 {
 *                     "example.com",
 *                 },
 *             },
 *         },
 *         Timeout = 10,
 *         Retries = 2,
 *         Interval = 60,
 *         ConsecutiveFails = 3,
 *         ConsecutiveSuccesses = 2,
 *     });
 *     // TCP Healthcheck
 *     var tcpHealthCheck = new Cloudflare.Healthcheck("tcp_health_check", new()
 *     {
 *         ZoneId = cloudflareZoneId,
 *         Name = "tcp-health-check",
 *         Description = "example tcp health check",
 *         Address = "example.com",
 *         Suspended = false,
 *         CheckRegions = new[]
 *         {
 *             "WEU",
 *             "EEU",
 *         },
 *         Type = "TCP",
 *         Port = 22,
 *         Method = "connection_established",
 *         Timeout = 10,
 *         Retries = 2,
 *         Interval = 60,
 *         ConsecutiveFails = 3,
 *         ConsecutiveSuccesses = 2,
 *     });
 * });
 * ```
 * ```go
 * package main
 * import (
 * 	"github.com/pulumi/pulumi-cloudflare/sdk/v5/go/cloudflare"
 * 	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
 * )
 * func main() {
 * 	pulumi.Run(func(ctx *pulumi.Context) error {
 * 		// HTTPS Healthcheck
 * 		_, err := cloudflare.NewHealthcheck(ctx, "http_health_check", &cloudflare.HealthcheckArgs{
 * 			ZoneId:      pulumi.Any(cloudflareZoneId),
 * 			Name:        pulumi.String("http-health-check"),
 * 			Description: pulumi.String("example http health check"),
 * 			Address:     pulumi.String("example.com"),
 * 			Suspended:   pulumi.Bool(false),
 * 			CheckRegions: pulumi.StringArray{
 * 				pulumi.String("WEU"),
 * 				pulumi.String("EEU"),
 * 			},
 * 			Type:         pulumi.String("HTTPS"),
 * 			Port:         pulumi.Int(443),
 * 			Method:       pulumi.String("GET"),
 * 			Path:         pulumi.String("/health"),
 * 			ExpectedBody: pulumi.String("alive"),
 * 			ExpectedCodes: pulumi.StringArray{
 * 				pulumi.String("2xx"),
 * 				pulumi.String("301"),
 * 			},
 * 			FollowRedirects: pulumi.Bool(true),
 * 			AllowInsecure:   pulumi.Bool(false),
 * 			Headers: cloudflare.HealthcheckHeaderArray{
 * 				&cloudflare.HealthcheckHeaderArgs{
 * 					Header: pulumi.String("Host"),
 * 					Values: pulumi.StringArray{
 * 						pulumi.String("example.com"),
 * 					},
 * 				},
 * 			},
 * 			Timeout:              pulumi.Int(10),
 * 			Retries:              pulumi.Int(2),
 * 			Interval:             pulumi.Int(60),
 * 			ConsecutiveFails:     pulumi.Int(3),
 * 			ConsecutiveSuccesses: pulumi.Int(2),
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		// TCP Healthcheck
 * 		_, err = cloudflare.NewHealthcheck(ctx, "tcp_health_check", &cloudflare.HealthcheckArgs{
 * 			ZoneId:      pulumi.Any(cloudflareZoneId),
 * 			Name:        pulumi.String("tcp-health-check"),
 * 			Description: pulumi.String("example tcp health check"),
 * 			Address:     pulumi.String("example.com"),
 * 			Suspended:   pulumi.Bool(false),
 * 			CheckRegions: pulumi.StringArray{
 * 				pulumi.String("WEU"),
 * 				pulumi.String("EEU"),
 * 			},
 * 			Type:                 pulumi.String("TCP"),
 * 			Port:                 pulumi.Int(22),
 * 			Method:               pulumi.String("connection_established"),
 * 			Timeout:              pulumi.Int(10),
 * 			Retries:              pulumi.Int(2),
 * 			Interval:             pulumi.Int(60),
 * 			ConsecutiveFails:     pulumi.Int(3),
 * 			ConsecutiveSuccesses: pulumi.Int(2),
 * 		})
 * 		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.cloudflare.Healthcheck;
 * import com.pulumi.cloudflare.HealthcheckArgs;
 * import com.pulumi.cloudflare.inputs.HealthcheckHeaderArgs;
 * 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) {
 *         // HTTPS Healthcheck
 *         var httpHealthCheck = new Healthcheck("httpHealthCheck", HealthcheckArgs.builder()
 *             .zoneId(cloudflareZoneId)
 *             .name("http-health-check")
 *             .description("example http health check")
 *             .address("example.com")
 *             .suspended(false)
 *             .checkRegions(
 *                 "WEU",
 *                 "EEU")
 *             .type("HTTPS")
 *             .port(443)
 *             .method("GET")
 *             .path("/health")
 *             .expectedBody("alive")
 *             .expectedCodes(
 *                 "2xx",
 *                 "301")
 *             .followRedirects(true)
 *             .allowInsecure(false)
 *             .headers(HealthcheckHeaderArgs.builder()
 *                 .header("Host")
 *                 .values("example.com")
 *                 .build())
 *             .timeout(10)
 *             .retries(2)
 *             .interval(60)
 *             .consecutiveFails(3)
 *             .consecutiveSuccesses(2)
 *             .build());
 *         // TCP Healthcheck
 *         var tcpHealthCheck = new Healthcheck("tcpHealthCheck", HealthcheckArgs.builder()
 *             .zoneId(cloudflareZoneId)
 *             .name("tcp-health-check")
 *             .description("example tcp health check")
 *             .address("example.com")
 *             .suspended(false)
 *             .checkRegions(
 *                 "WEU",
 *                 "EEU")
 *             .type("TCP")
 *             .port(22)
 *             .method("connection_established")
 *             .timeout(10)
 *             .retries(2)
 *             .interval(60)
 *             .consecutiveFails(3)
 *             .consecutiveSuccesses(2)
 *             .build());
 *     }
 * }
 * ```
 * ```yaml
 * resources:
 *   # HTTPS Healthcheck
 *   httpHealthCheck:
 *     type: cloudflare:Healthcheck
 *     name: http_health_check
 *     properties:
 *       zoneId: ${cloudflareZoneId}
 *       name: http-health-check
 *       description: example http health check
 *       address: example.com
 *       suspended: false
 *       checkRegions:
 *         - WEU
 *         - EEU
 *       type: HTTPS
 *       port: 443
 *       method: GET
 *       path: /health
 *       expectedBody: alive
 *       expectedCodes:
 *         - 2xx
 *         - '301'
 *       followRedirects: true
 *       allowInsecure: false
 *       headers:
 *         - header: Host
 *           values:
 *             - example.com
 *       timeout: 10
 *       retries: 2
 *       interval: 60
 *       consecutiveFails: 3
 *       consecutiveSuccesses: 2
 *   # TCP Healthcheck
 *   tcpHealthCheck:
 *     type: cloudflare:Healthcheck
 *     name: tcp_health_check
 *     properties:
 *       zoneId: ${cloudflareZoneId}
 *       name: tcp-health-check
 *       description: example tcp health check
 *       address: example.com
 *       suspended: false
 *       checkRegions:
 *         - WEU
 *         - EEU
 *       type: TCP
 *       port: 22
 *       method: connection_established
 *       timeout: 10
 *       retries: 2
 *       interval: 60
 *       consecutiveFails: 3
 *       consecutiveSuccesses: 2
 * ```
 * 
 * ## Import
 * Use the Zone ID and Healthcheck ID to import.
 * ```sh
 * $ pulumi import cloudflare:index/healthcheck:Healthcheck example /
 * ```
 */
public class Healthcheck internal constructor(
    override val javaResource: com.pulumi.cloudflare.Healthcheck,
) : KotlinCustomResource(javaResource, HealthcheckMapper) {
    /**
     * The hostname or IP address of the origin server to run health checks on.
     */
    public val address: Output
        get() = javaResource.address().applyValue({ args0 -> args0 })

    /**
     * Do not validate the certificate when the health check uses HTTPS. Defaults to `false`.
     */
    public val allowInsecure: Output?
        get() = javaResource.allowInsecure().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * A list of regions from which to run health checks. If not set, Cloudflare will pick a default region. Available values: `WNAM`, `ENAM`, `WEU`, `EEU`, `NSAM`, `SSAM`, `OC`, `ME`, `NAF`, `SAF`, `IN`, `SEAS`, `NEAS`, `ALL_REGIONS`.
     */
    public val checkRegions: Output>
        get() = javaResource.checkRegions().applyValue({ args0 -> args0.map({ args0 -> args0 }) })

    /**
     * The number of consecutive fails required from a health check before changing the health to unhealthy. Defaults to `1`.
     */
    public val consecutiveFails: Output?
        get() = javaResource.consecutiveFails().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * The number of consecutive successes required from a health check before changing the health to healthy. Defaults to `1`.
     */
    public val consecutiveSuccesses: Output?
        get() = javaResource.consecutiveSuccesses().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * Creation time.
     */
    public val createdOn: Output
        get() = javaResource.createdOn().applyValue({ args0 -> args0 })

    /**
     * A human-readable description of the health check.
     */
    public val description: Output?
        get() = javaResource.description().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * A case-insensitive sub-string to look for in the response body. If this string is not found the origin will be marked as unhealthy.
     */
    public val expectedBody: Output?
        get() = javaResource.expectedBody().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * The expected HTTP response codes (e.g. '200') or code ranges (e.g. '2xx' for all codes starting with 2) of the health check.
     */
    public val expectedCodes: Output>?
        get() = javaResource.expectedCodes().applyValue({ args0 ->
            args0.map({ args0 ->
                args0.map({ args0 -> args0 })
            }).orElse(null)
        })

    /**
     * Follow redirects if the origin returns a 3xx status code. Defaults to `false`.
     */
    public val followRedirects: Output?
        get() = javaResource.followRedirects().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * The HTTP request headers to send in the health check. It is recommended you set a Host header by default. The User-Agent header cannot be overridden.
     */
    public val headers: Output>?
        get() = javaResource.headers().applyValue({ args0 ->
            args0.map({ args0 ->
                args0.map({ args0 ->
                    args0.let({ args0 -> toKotlin(args0) })
                })
            }).orElse(null)
        })

    /**
     * The interval between each health check. Shorter intervals may give quicker notifications if the origin status changes, but will increase the load on the origin as we check from multiple locations. Defaults to `60`.
     */
    public val interval: Output?
        get() = javaResource.interval().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })

    /**
     * The HTTP method to use for the health check. Available values: `connection_established`, `GET`, `HEAD`.
     */
    public val method: Output
        get() = javaResource.method().applyValue({ args0 -> args0 })

    /**
     * Last modified time.
     */
    public val modifiedOn: Output
        get() = javaResource.modifiedOn().applyValue({ args0 -> args0 })

    /**
     * A short name to identify the health check. Only alphanumeric characters, hyphens, and underscores are allowed.
     */
    public val name: Output
        get() = javaResource.name().applyValue({ args0 -> args0 })

    /**
     * The endpoint path to health check against. Defaults to `/`.
     */
    public val path: Output?
        get() = javaResource.path().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })

    /**
     * Port number to connect to for the health check. Defaults to `80`.
     */
    public val port: Output?
        get() = javaResource.port().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })

    /**
     * The number of retries to attempt in case of a timeout before marking the origin as unhealthy. Retries are attempted immediately. Defaults to `2`.
     */
    public val retries: Output?
        get() = javaResource.retries().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })

    /**
     * If suspended, no health checks are sent to the origin. Defaults to `false`.
     */
    public val suspended: Output?
        get() = javaResource.suspended().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })

    /**
     * The timeout (in seconds) before marking the health check as failed. Defaults to `5`.
     */
    public val timeout: Output?
        get() = javaResource.timeout().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })

    /**
     * The protocol to use for the health check. Available values: `TCP`, `HTTP`, `HTTPS`.
     */
    public val type: Output
        get() = javaResource.type().applyValue({ args0 -> args0 })

    /**
     * The zone identifier to target for the resource. **Modifying this attribute will force creation of a new resource.**
     */
    public val zoneId: Output
        get() = javaResource.zoneId().applyValue({ args0 -> args0 })
}

public object HealthcheckMapper : ResourceMapper {
    override fun supportsMappingOfType(javaResource: Resource): Boolean =
        com.pulumi.cloudflare.Healthcheck::class == javaResource::class

    override fun map(javaResource: Resource): Healthcheck = Healthcheck(
        javaResource as
            com.pulumi.cloudflare.Healthcheck,
    )
}

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy