HashiCorp Nomad

v0.2.1 published on Tuesday, Dec 7, 2021 by Pulumi

SentinelPolicy

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

using Pulumi;
using Nomad = Pulumi.Nomad;

class MyStack : Stack
{
    public MyStack()
    {
        var exec_only = new Nomad.SentinelPolicy("exec-only", new Nomad.SentinelPolicyArgs
        {
            Description = "Only allow jobs that are based on an exec driver.",
            EnforcementLevel = "soft-mandatory",
            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",
        });
    }

}
package main

import (
	"fmt"

	"github.com/pulumi/pulumi-nomad/sdk/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{
			Description:      pulumi.String("Only allow jobs that are based on an exec driver."),
			EnforcementLevel: pulumi.String("soft-mandatory"),
			Policy:           pulumi.String(fmt.Sprintf("%v%v%v%v%v%v%v%v%v%v%v", "main = rule { all_drivers_exec }\n", "\n", "# all_drivers_exec checks that all the drivers in use are exec\n", "all_drivers_exec = rule {\n", "    all job.task_groups as tg {\n", "        all tg.tasks as task {\n", "            task.driver is \"exec\"\n", "        }\n", "    }\n", "}\n", "\n")),
			Scope:            pulumi.String("submit-job"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
import pulumi
import pulumi_nomad as nomad

exec_only = nomad.SentinelPolicy("exec-only",
    description="Only allow jobs that are based on an exec driver.",
    enforcement_level="soft-mandatory",
    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")
import * as pulumi from "@pulumi/pulumi";
import * as nomad from "@pulumi/nomad";

const exec_only = new nomad.SentinelPolicy("exec-only", {
    description: "Only allow jobs that are based on an exec driver.",
    // allow administrators to override
    enforcementLevel: "soft-mandatory",
    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",
});

Create a SentinelPolicy Resource

new SentinelPolicy(name: string, args: SentinelPolicyArgs, opts?: CustomResourceOptions);
@overload
def SentinelPolicy(resource_name: str,
                   opts: Optional[ResourceOptions] = None,
                   description: Optional[str] = None,
                   enforcement_level: Optional[str] = None,
                   name: Optional[str] = None,
                   policy: Optional[str] = None,
                   scope: Optional[str] = None)
@overload
def SentinelPolicy(resource_name: str,
                   args: SentinelPolicyArgs,
                   opts: Optional[ResourceOptions] = None)
func NewSentinelPolicy(ctx *Context, name string, args SentinelPolicyArgs, opts ...ResourceOption) (*SentinelPolicy, error)
public SentinelPolicy(string name, SentinelPolicyArgs args, CustomResourceOptions? opts = null)
name string
The unique name of the resource.
args SentinelPolicyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name str
The unique name of the resource.
args SentinelPolicyArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args SentinelPolicyArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args SentinelPolicyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.

SentinelPolicy Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

The SentinelPolicy resource accepts the following input properties:

EnforcementLevel string
(strings: <required>) - The [enforcement level][enforcement-level] for this policy.
Policy string
(string: <required>) - The contents of the policy to register.
Scope string
(strings: <required>) - The [scope][scope] for this policy.
Description string
(string: "") - A description of the policy.
Name string
(string: <required>) - A unique name for the policy.
EnforcementLevel string
(strings: <required>) - The [enforcement level][enforcement-level] for this policy.
Policy string
(string: <required>) - The contents of the policy to register.
Scope string
(strings: <required>) - The [scope][scope] for this policy.
Description string
(string: "") - A description of the policy.
Name string
(string: <required>) - A unique name for the policy.
enforcementLevel string
(strings: <required>) - The [enforcement level][enforcement-level] for this policy.
policy string
(string: <required>) - The contents of the policy to register.
scope string
(strings: <required>) - The [scope][scope] for this policy.
description string
(string: "") - A description of the policy.
name string
(string: <required>) - A unique name for the policy.
enforcement_level str
(strings: <required>) - The [enforcement level][enforcement-level] for this policy.
policy str
(string: <required>) - The contents of the policy to register.
scope str
(strings: <required>) - The [scope][scope] for this policy.
description str
(string: "") - A description of the policy.
name str
(string: <required>) - A unique name for the policy.

Outputs

All input properties are implicitly available as output properties. Additionally, the SentinelPolicy resource produces the following output properties:

Id string
The provider-assigned unique ID for this managed resource.
Id string
The provider-assigned unique ID for this managed resource.
id string
The provider-assigned unique ID for this managed resource.
id str
The provider-assigned unique ID for this managed resource.

Look up an Existing SentinelPolicy Resource

Get an existing SentinelPolicy resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: SentinelPolicyState, opts?: CustomResourceOptions): SentinelPolicy
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        description: Optional[str] = None,
        enforcement_level: Optional[str] = None,
        name: Optional[str] = None,
        policy: Optional[str] = None,
        scope: Optional[str] = None) -> SentinelPolicy
func GetSentinelPolicy(ctx *Context, name string, id IDInput, state *SentinelPolicyState, opts ...ResourceOption) (*SentinelPolicy, error)
public static SentinelPolicy Get(string name, Input<string> id, SentinelPolicyState? state, CustomResourceOptions? opts = null)
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.

The following state arguments are supported:

Description string
(string: "") - A description of the policy.
EnforcementLevel string
(strings: <required>) - The [enforcement level][enforcement-level] for this policy.
Name string
(string: <required>) - A unique name for the policy.
Policy string
(string: <required>) - The contents of the policy to register.
Scope string
(strings: <required>) - The [scope][scope] for this policy.
Description string
(string: "") - A description of the policy.
EnforcementLevel string
(strings: <required>) - The [enforcement level][enforcement-level] for this policy.
Name string
(string: <required>) - A unique name for the policy.
Policy string
(string: <required>) - The contents of the policy to register.
Scope string
(strings: <required>) - The [scope][scope] for this policy.
description string
(string: "") - A description of the policy.
enforcementLevel string
(strings: <required>) - The [enforcement level][enforcement-level] for this policy.
name string
(string: <required>) - A unique name for the policy.
policy string
(string: <required>) - The contents of the policy to register.
scope string
(strings: <required>) - The [scope][scope] for this policy.
description str
(string: "") - A description of the policy.
enforcement_level str
(strings: <required>) - The [enforcement level][enforcement-level] for this policy.
name str
(string: <required>) - A unique name for the policy.
policy str
(string: <required>) - The contents of the policy to register.
scope str
(strings: <required>) - The [scope][scope] for this policy.

Package Details

Repository
https://github.com/pulumi/pulumi-nomad
License
Apache-2.0
Notes
This Pulumi package is based on the nomad Terraform Provider.