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

com.pulumi.nomad.kotlin.SentinelPolicy.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: 2.4.0.0
Show newest version
@file:Suppress("NAME_SHADOWING", "DEPRECATION")

package com.pulumi.nomad.kotlin

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.String
import kotlin.Suppress
import kotlin.Unit

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

    public var args: SentinelPolicyArgs = SentinelPolicyArgs()

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

/**
 * Manages a Sentinel policy registered in Nomad.
 * > **Enterprise Only!** This API endpoint and functionality only exists in
 *    Nomad Enterprise. This is not present in the open source version of Nomad.
 * ## Example Usage
 * 
 * ```typescript
 * import * as pulumi from "@pulumi/pulumi";
 * import * as nomad from "@pulumi/nomad";
 * const exec_only = new nomad.SentinelPolicy("exec-only", {
 *     name: "exec-only",
 *     description: "Only allow jobs that are based on an exec driver.",
 *     policy: `main = rule { all_drivers_exec }
 * # all_drivers_exec checks that all the drivers in use are exec
 * all_drivers_exec = rule {
 *     all job.task_groups as tg {
 *         all tg.tasks as task {
 *             task.driver is "exec"
 *         }
 *     }
 * }
 * `,
 *     scope: "submit-job",
 *     enforcementLevel: "soft-mandatory",
 * });
 * ```
 * ```python
 * import pulumi
 * import pulumi_nomad as nomad
 * exec_only = nomad.SentinelPolicy("exec-only",
 *     name="exec-only",
 *     description="Only allow jobs that are based on an exec driver.",
 *     policy="""main = rule { all_drivers_exec }
 * # all_drivers_exec checks that all the drivers in use are exec
 * all_drivers_exec = rule {
 *     all job.task_groups as tg {
 *         all tg.tasks as task {
 *             task.driver is "exec"
 *         }
 *     }
 * }
 * """,
 *     scope="submit-job",
 *     enforcement_level="soft-mandatory")
 * ```
 * ```csharp
 * using System.Collections.Generic;
 * using System.Linq;
 * using Pulumi;
 * using Nomad = Pulumi.Nomad;
 * return await Deployment.RunAsync(() =>
 * {
 *     var exec_only = new Nomad.SentinelPolicy("exec-only", new()
 *     {
 *         Name = "exec-only",
 *         Description = "Only allow jobs that are based on an exec driver.",
 *         Policy = @"main = rule { all_drivers_exec }
 * # all_drivers_exec checks that all the drivers in use are exec
 * all_drivers_exec = rule {
 *     all job.task_groups as tg {
 *         all tg.tasks as task {
 *             task.driver is ""exec""
 *         }
 *     }
 * }
 * ",
 *         Scope = "submit-job",
 *         EnforcementLevel = "soft-mandatory",
 *     });
 * });
 * ```
 * ```go
 * package main
 * import (
 * 	"github.com/pulumi/pulumi-nomad/sdk/v2/go/nomad"
 * 	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
 * )
 * func main() {
 * 	pulumi.Run(func(ctx *pulumi.Context) error {
 * 		_, err := nomad.NewSentinelPolicy(ctx, "exec-only", &nomad.SentinelPolicyArgs{
 * 			Name:        pulumi.String("exec-only"),
 * 			Description: pulumi.String("Only allow jobs that are based on an exec driver."),
 * 			Policy: pulumi.String(`main = rule { all_drivers_exec }
 * # all_drivers_exec checks that all the drivers in use are exec
 * all_drivers_exec = rule {
 *     all job.task_groups as tg {
 *         all tg.tasks as task {
 *             task.driver is "exec"
 *         }
 *     }
 * }
 * `),
 * 			Scope:            pulumi.String("submit-job"),
 * 			EnforcementLevel: pulumi.String("soft-mandatory"),
 * 		})
 * 		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.nomad.SentinelPolicy;
 * import com.pulumi.nomad.SentinelPolicyArgs;
 * 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 exec_only = new SentinelPolicy("exec-only", SentinelPolicyArgs.builder()
 *             .name("exec-only")
 *             .description("Only allow jobs that are based on an exec driver.")
 *             .policy("""
 * main = rule { all_drivers_exec }
 * # all_drivers_exec checks that all the drivers in use are exec
 * all_drivers_exec = rule {
 *     all job.task_groups as tg {
 *         all tg.tasks as task {
 *             task.driver is "exec"
 *         }
 *     }
 * }
 *             """)
 *             .scope("submit-job")
 *             .enforcementLevel("soft-mandatory")
 *             .build());
 *     }
 * }
 * ```
 * ```yaml
 * resources:
 *   exec-only:
 *     type: nomad:SentinelPolicy
 *     properties:
 *       name: exec-only
 *       description: Only allow jobs that are based on an exec driver.
 *       policy: |
 *         main = rule { all_drivers_exec }
 *         # all_drivers_exec checks that all the drivers in use are exec
 *         all_drivers_exec = rule {
 *             all job.task_groups as tg {
 *                 all tg.tasks as task {
 *                     task.driver is "exec"
 *                 }
 *             }
 *         }
 *       scope: submit-job
 *       enforcementLevel: soft-mandatory
 * ```
 * 
 */
public class SentinelPolicy internal constructor(
    override val javaResource: com.pulumi.nomad.SentinelPolicy,
) : KotlinCustomResource(javaResource, SentinelPolicyMapper) {
    /**
     * `(string: "")` - A description of the policy.
     * [scope]: https://www.nomadproject.io/guides/sentinel-policy.html#policy-scope
     * [enforcement-level]: https://www.nomadproject.io/guides/sentinel-policy.html#enforcement-level
     */
    public val description: Output?
        get() = javaResource.description().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * `(strings: )` - The [enforcement level][enforcement-level]
     * for this policy.
     */
    public val enforcementLevel: Output
        get() = javaResource.enforcementLevel().applyValue({ args0 -> args0 })

    /**
     * `(string: )` - A unique name for the policy.
     */
    public val name: Output
        get() = javaResource.name().applyValue({ args0 -> args0 })

    /**
     * `(string: )` - The contents of the policy to register.
     */
    public val policy: Output
        get() = javaResource.policy().applyValue({ args0 -> args0 })

    /**
     * `(strings: )` - The [scope][scope] for this policy.
     */
    public val scope: Output
        get() = javaResource.scope().applyValue({ args0 -> args0 })
}

public object SentinelPolicyMapper : ResourceMapper {
    override fun supportsMappingOfType(javaResource: Resource): Boolean =
        com.pulumi.nomad.SentinelPolicy::class == javaResource::class

    override fun map(javaResource: Resource): SentinelPolicy = SentinelPolicy(
        javaResource as
            com.pulumi.nomad.SentinelPolicy,
    )
}

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy