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

com.pulumi.azure.policy.kotlin.PolicySetDefinition.kt Maven / Gradle / Ivy

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

package com.pulumi.azure.policy.kotlin

import com.pulumi.azure.policy.kotlin.outputs.PolicySetDefinitionPolicyDefinitionGroup
import com.pulumi.azure.policy.kotlin.outputs.PolicySetDefinitionPolicyDefinitionReference
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
import kotlin.collections.List
import com.pulumi.azure.policy.kotlin.outputs.PolicySetDefinitionPolicyDefinitionGroup.Companion.toKotlin as policySetDefinitionPolicyDefinitionGroupToKotlin
import com.pulumi.azure.policy.kotlin.outputs.PolicySetDefinitionPolicyDefinitionReference.Companion.toKotlin as policySetDefinitionPolicyDefinitionReferenceToKotlin

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

    public var args: PolicySetDefinitionArgs = PolicySetDefinitionArgs()

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

/**
 * Manages a policy set definition.
 * > **NOTE:**  Policy set definitions (also known as policy initiatives) do not take effect until they are assigned to a scope using a Policy Set Assignment.
 * ## Example Usage
 * 
 * ```typescript
 * import * as pulumi from "@pulumi/pulumi";
 * import * as azure from "@pulumi/azure";
 * const example = new azure.policy.PolicySetDefinition("example", {
 *     name: "testPolicySet",
 *     policyType: "Custom",
 *     displayName: "Test Policy Set",
 *     parameters: `    {
 *         "allowedLocations": {
 *             "type": "Array",
 *             "metadata": {
 *                 "description": "The list of allowed locations for resources.",
 *                 "displayName": "Allowed locations",
 *                 "strongType": "location"
 *             }
 *         }
 *     }
 * `,
 *     policyDefinitionReferences: [{
 *         policyDefinitionId: "/providers/Microsoft.Authorization/policyDefinitions/e765b5de-1225-4ba3-bd56-1ac6695af988",
 *         parameterValues: `    {
 *       "listOfAllowedLocations": {"value": "[parameters('allowedLocations')]"}
 *     }
 * `,
 *     }],
 * });
 * ```
 * ```python
 * import pulumi
 * import pulumi_azure as azure
 * example = azure.policy.PolicySetDefinition("example",
 *     name="testPolicySet",
 *     policy_type="Custom",
 *     display_name="Test Policy Set",
 *     parameters="""    {
 *         "allowedLocations": {
 *             "type": "Array",
 *             "metadata": {
 *                 "description": "The list of allowed locations for resources.",
 *                 "displayName": "Allowed locations",
 *                 "strongType": "location"
 *             }
 *         }
 *     }
 * """,
 *     policy_definition_references=[{
 *         "policy_definition_id": "/providers/Microsoft.Authorization/policyDefinitions/e765b5de-1225-4ba3-bd56-1ac6695af988",
 *         "parameter_values": """    {
 *       "listOfAllowedLocations": {"value": "[parameters('allowedLocations')]"}
 *     }
 * """,
 *     }])
 * ```
 * ```csharp
 * using System.Collections.Generic;
 * using System.Linq;
 * using Pulumi;
 * using Azure = Pulumi.Azure;
 * return await Deployment.RunAsync(() =>
 * {
 *     var example = new Azure.Policy.PolicySetDefinition("example", new()
 *     {
 *         Name = "testPolicySet",
 *         PolicyType = "Custom",
 *         DisplayName = "Test Policy Set",
 *         Parameters = @"    {
 *         ""allowedLocations"": {
 *             ""type"": ""Array"",
 *             ""metadata"": {
 *                 ""description"": ""The list of allowed locations for resources."",
 *                 ""displayName"": ""Allowed locations"",
 *                 ""strongType"": ""location""
 *             }
 *         }
 *     }
 * ",
 *         PolicyDefinitionReferences = new[]
 *         {
 *             new Azure.Policy.Inputs.PolicySetDefinitionPolicyDefinitionReferenceArgs
 *             {
 *                 PolicyDefinitionId = "/providers/Microsoft.Authorization/policyDefinitions/e765b5de-1225-4ba3-bd56-1ac6695af988",
 *                 ParameterValues = @"    {
 *       ""listOfAllowedLocations"": {""value"": ""[parameters('allowedLocations')]""}
 *     }
 * ",
 *             },
 *         },
 *     });
 * });
 * ```
 * ```go
 * package main
 * import (
 * 	"github.com/pulumi/pulumi-azure/sdk/v5/go/azure/policy"
 * 	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
 * )
 * func main() {
 * 	pulumi.Run(func(ctx *pulumi.Context) error {
 * 		_, err := policy.NewPolicySetDefinition(ctx, "example", &policy.PolicySetDefinitionArgs{
 * 			Name:        pulumi.String("testPolicySet"),
 * 			PolicyType:  pulumi.String("Custom"),
 * 			DisplayName: pulumi.String("Test Policy Set"),
 * 			Parameters: pulumi.String(`    {
 *         "allowedLocations": {
 *             "type": "Array",
 *             "metadata": {
 *                 "description": "The list of allowed locations for resources.",
 *                 "displayName": "Allowed locations",
 *                 "strongType": "location"
 *             }
 *         }
 *     }
 * `),
 * 			PolicyDefinitionReferences: policy.PolicySetDefinitionPolicyDefinitionReferenceArray{
 * 				&policy.PolicySetDefinitionPolicyDefinitionReferenceArgs{
 * 					PolicyDefinitionId: pulumi.String("/providers/Microsoft.Authorization/policyDefinitions/e765b5de-1225-4ba3-bd56-1ac6695af988"),
 * 					ParameterValues:    pulumi.String("    {\n      \"listOfAllowedLocations\": {\"value\": \"[parameters('allowedLocations')]\"}\n    }\n"),
 * 				},
 * 			},
 * 		})
 * 		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.azure.policy.PolicySetDefinition;
 * import com.pulumi.azure.policy.PolicySetDefinitionArgs;
 * import com.pulumi.azure.policy.inputs.PolicySetDefinitionPolicyDefinitionReferenceArgs;
 * 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 example = new PolicySetDefinition("example", PolicySetDefinitionArgs.builder()
 *             .name("testPolicySet")
 *             .policyType("Custom")
 *             .displayName("Test Policy Set")
 *             .parameters("""
 *     {
 *         "allowedLocations": {
 *             "type": "Array",
 *             "metadata": {
 *                 "description": "The list of allowed locations for resources.",
 *                 "displayName": "Allowed locations",
 *                 "strongType": "location"
 *             }
 *         }
 *     }
 *             """)
 *             .policyDefinitionReferences(PolicySetDefinitionPolicyDefinitionReferenceArgs.builder()
 *                 .policyDefinitionId("/providers/Microsoft.Authorization/policyDefinitions/e765b5de-1225-4ba3-bd56-1ac6695af988")
 *                 .parameterValues("""
 *     {
 *       "listOfAllowedLocations": {"value": "[parameters('allowedLocations')]"}
 *     }
 *                 """)
 *                 .build())
 *             .build());
 *     }
 * }
 * ```
 * ```yaml
 * resources:
 *   example:
 *     type: azure:policy:PolicySetDefinition
 *     properties:
 *       name: testPolicySet
 *       policyType: Custom
 *       displayName: Test Policy Set
 *       parameters: |2
 *             {
 *                 "allowedLocations": {
 *                     "type": "Array",
 *                     "metadata": {
 *                         "description": "The list of allowed locations for resources.",
 *                         "displayName": "Allowed locations",
 *                         "strongType": "location"
 *                     }
 *                 }
 *             }
 *       policyDefinitionReferences:
 *         - policyDefinitionId: /providers/Microsoft.Authorization/policyDefinitions/e765b5de-1225-4ba3-bd56-1ac6695af988
 *           parameterValues: |2
 *                 {
 *                   "listOfAllowedLocations": {"value": "[parameters('allowedLocations')]"}
 *                 }
 * ```
 * 
 * ## Import
 * Policy Set Definitions can be imported using the `resource id`, e.g.
 * ```sh
 * $ pulumi import azure:policy/policySetDefinition:PolicySetDefinition example /subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/policySetDefinitions/testPolicySet
 * ```
 * or
 * ```sh
 * $ pulumi import azure:policy/policySetDefinition:PolicySetDefinition example /providers/Microsoft.Management/managementGroups/my-mgmt-group-id/providers/Microsoft.Authorization/policySetDefinitions/testPolicySet
 * ```
 */
public class PolicySetDefinition internal constructor(
    override val javaResource: com.pulumi.azure.policy.PolicySetDefinition,
) : KotlinCustomResource(javaResource, PolicySetDefinitionMapper) {
    /**
     * The description of the policy set definition.
     */
    public val description: Output?
        get() = javaResource.description().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * The display name of the policy set definition.
     */
    public val displayName: Output
        get() = javaResource.displayName().applyValue({ args0 -> args0 })

    /**
     * The id of the Management Group where this policy set definition should be defined. Changing this forces a new resource to be created.
     */
    public val managementGroupId: Output?
        get() = javaResource.managementGroupId().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * The metadata for the policy set definition. This is a JSON object representing additional metadata that should be stored with the policy definition.
     */
    public val metadata: Output
        get() = javaResource.metadata().applyValue({ args0 -> args0 })

    /**
     * The name of the policy set definition. Changing this forces a new resource to be created.
     */
    public val name: Output
        get() = javaResource.name().applyValue({ args0 -> args0 })

    /**
     * Parameters for the policy set definition. This field is a JSON object that allows you to parameterize your policy definition.
     */
    public val parameters: Output?
        get() = javaResource.parameters().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * One or more `policy_definition_group` blocks as defined below.
     */
    public val policyDefinitionGroups: Output>?
        get() = javaResource.policyDefinitionGroups().applyValue({ args0 ->
            args0.map({ args0 ->
                args0.map({ args0 ->
                    args0.let({ args0 ->
                        policySetDefinitionPolicyDefinitionGroupToKotlin(args0)
                    })
                })
            }).orElse(null)
        })

    /**
     * One or more `policy_definition_reference` blocks as defined below.
     */
    public val policyDefinitionReferences: Output>
        get() = javaResource.policyDefinitionReferences().applyValue({ args0 ->
            args0.map({ args0 ->
                args0.let({ args0 -> policySetDefinitionPolicyDefinitionReferenceToKotlin(args0) })
            })
        })

    /**
     * The policy set type. Possible values are `BuiltIn`, `Custom`, `NotSpecified` and `Static`. Changing this forces a new resource to be created.
     */
    public val policyType: Output
        get() = javaResource.policyType().applyValue({ args0 -> args0 })
}

public object PolicySetDefinitionMapper : ResourceMapper {
    override fun supportsMappingOfType(javaResource: Resource): Boolean =
        com.pulumi.azure.policy.PolicySetDefinition::class == javaResource::class

    override fun map(javaResource: Resource): PolicySetDefinition = PolicySetDefinition(
        javaResource
            as com.pulumi.azure.policy.PolicySetDefinition,
    )
}

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy