1. Packages
  2. AWS
  3. API Docs
  4. kms
  5. KeyPolicy
AWS v6.54.2 published on Wednesday, Oct 2, 2024 by Pulumi

aws.kms.KeyPolicy

Explore with Pulumi AI

aws logo
AWS v6.54.2 published on Wednesday, Oct 2, 2024 by Pulumi

    Attaches a policy to a KMS Key.

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    const example = new aws.kms.Key("example", {description: "example"});
    const exampleKeyPolicy = new aws.kms.KeyPolicy("example", {
        keyId: example.id,
        policy: JSON.stringify({
            Id: "example",
            Statement: [{
                Action: "kms:*",
                Effect: "Allow",
                Principal: {
                    AWS: "*",
                },
                Resource: "*",
                Sid: "Enable IAM User Permissions",
            }],
            Version: "2012-10-17",
        }),
    });
    
    import pulumi
    import json
    import pulumi_aws as aws
    
    example = aws.kms.Key("example", description="example")
    example_key_policy = aws.kms.KeyPolicy("example",
        key_id=example.id,
        policy=json.dumps({
            "Id": "example",
            "Statement": [{
                "Action": "kms:*",
                "Effect": "Allow",
                "Principal": {
                    "AWS": "*",
                },
                "Resource": "*",
                "Sid": "Enable IAM User Permissions",
            }],
            "Version": "2012-10-17",
        }))
    
    package main
    
    import (
    	"encoding/json"
    
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/kms"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		example, err := kms.NewKey(ctx, "example", &kms.KeyArgs{
    			Description: pulumi.String("example"),
    		})
    		if err != nil {
    			return err
    		}
    		tmpJSON0, err := json.Marshal(map[string]interface{}{
    			"Id": "example",
    			"Statement": []map[string]interface{}{
    				map[string]interface{}{
    					"Action": "kms:*",
    					"Effect": "Allow",
    					"Principal": map[string]interface{}{
    						"AWS": "*",
    					},
    					"Resource": "*",
    					"Sid":      "Enable IAM User Permissions",
    				},
    			},
    			"Version": "2012-10-17",
    		})
    		if err != nil {
    			return err
    		}
    		json0 := string(tmpJSON0)
    		_, err = kms.NewKeyPolicy(ctx, "example", &kms.KeyPolicyArgs{
    			KeyId:  example.ID(),
    			Policy: pulumi.String(json0),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using System.Text.Json;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var example = new Aws.Kms.Key("example", new()
        {
            Description = "example",
        });
    
        var exampleKeyPolicy = new Aws.Kms.KeyPolicy("example", new()
        {
            KeyId = example.Id,
            Policy = JsonSerializer.Serialize(new Dictionary<string, object?>
            {
                ["Id"] = "example",
                ["Statement"] = new[]
                {
                    new Dictionary<string, object?>
                    {
                        ["Action"] = "kms:*",
                        ["Effect"] = "Allow",
                        ["Principal"] = new Dictionary<string, object?>
                        {
                            ["AWS"] = "*",
                        },
                        ["Resource"] = "*",
                        ["Sid"] = "Enable IAM User Permissions",
                    },
                },
                ["Version"] = "2012-10-17",
            }),
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.aws.kms.Key;
    import com.pulumi.aws.kms.KeyArgs;
    import com.pulumi.aws.kms.KeyPolicy;
    import com.pulumi.aws.kms.KeyPolicyArgs;
    import static com.pulumi.codegen.internal.Serialization.*;
    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 Key("example", KeyArgs.builder()
                .description("example")
                .build());
    
            var exampleKeyPolicy = new KeyPolicy("exampleKeyPolicy", KeyPolicyArgs.builder()
                .keyId(example.id())
                .policy(serializeJson(
                    jsonObject(
                        jsonProperty("Id", "example"),
                        jsonProperty("Statement", jsonArray(jsonObject(
                            jsonProperty("Action", "kms:*"),
                            jsonProperty("Effect", "Allow"),
                            jsonProperty("Principal", jsonObject(
                                jsonProperty("AWS", "*")
                            )),
                            jsonProperty("Resource", "*"),
                            jsonProperty("Sid", "Enable IAM User Permissions")
                        ))),
                        jsonProperty("Version", "2012-10-17")
                    )))
                .build());
    
        }
    }
    
    resources:
      example:
        type: aws:kms:Key
        properties:
          description: example
      exampleKeyPolicy:
        type: aws:kms:KeyPolicy
        name: example
        properties:
          keyId: ${example.id}
          policy:
            fn::toJSON:
              Id: example
              Statement:
                - Action: kms:*
                  Effect: Allow
                  Principal:
                    AWS: '*'
                  Resource: '*'
                  Sid: Enable IAM User Permissions
              Version: 2012-10-17
    

    Create KeyPolicy Resource

    Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

    Constructor syntax

    new KeyPolicy(name: string, args: KeyPolicyArgs, opts?: CustomResourceOptions);
    @overload
    def KeyPolicy(resource_name: str,
                  args: KeyPolicyArgs,
                  opts: Optional[ResourceOptions] = None)
    
    @overload
    def KeyPolicy(resource_name: str,
                  opts: Optional[ResourceOptions] = None,
                  key_id: Optional[str] = None,
                  policy: Optional[str] = None,
                  bypass_policy_lockout_safety_check: Optional[bool] = None)
    func NewKeyPolicy(ctx *Context, name string, args KeyPolicyArgs, opts ...ResourceOption) (*KeyPolicy, error)
    public KeyPolicy(string name, KeyPolicyArgs args, CustomResourceOptions? opts = null)
    public KeyPolicy(String name, KeyPolicyArgs args)
    public KeyPolicy(String name, KeyPolicyArgs args, CustomResourceOptions options)
    
    type: aws:kms:KeyPolicy
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    

    Parameters

    name string
    The unique name of the resource.
    args KeyPolicyArgs
    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 KeyPolicyArgs
    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 KeyPolicyArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args KeyPolicyArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args KeyPolicyArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    Constructor example

    The following reference example uses placeholder values for all input properties.

    var keyPolicyResource = new Aws.Kms.KeyPolicy("keyPolicyResource", new()
    {
        KeyId = "string",
        Policy = "string",
        BypassPolicyLockoutSafetyCheck = false,
    });
    
    example, err := kms.NewKeyPolicy(ctx, "keyPolicyResource", &kms.KeyPolicyArgs{
    	KeyId:                          pulumi.String("string"),
    	Policy:                         pulumi.String("string"),
    	BypassPolicyLockoutSafetyCheck: pulumi.Bool(false),
    })
    
    var keyPolicyResource = new KeyPolicy("keyPolicyResource", KeyPolicyArgs.builder()
        .keyId("string")
        .policy("string")
        .bypassPolicyLockoutSafetyCheck(false)
        .build());
    
    key_policy_resource = aws.kms.KeyPolicy("keyPolicyResource",
        key_id="string",
        policy="string",
        bypass_policy_lockout_safety_check=False)
    
    const keyPolicyResource = new aws.kms.KeyPolicy("keyPolicyResource", {
        keyId: "string",
        policy: "string",
        bypassPolicyLockoutSafetyCheck: false,
    });
    
    type: aws:kms:KeyPolicy
    properties:
        bypassPolicyLockoutSafetyCheck: false
        keyId: string
        policy: string
    

    KeyPolicy 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 KeyPolicy resource accepts the following input properties:

    KeyId string
    The ID of the KMS Key to attach the policy.
    Policy string

    A valid policy JSON document. Although this is a key policy, not an IAM policy, an aws.iam.getPolicyDocument, in the form that designates a principal, can be used. For more information about building policy documents, see the AWS IAM Policy Document Guide.

    NOTE: Note: All KMS keys must have a key policy. If a key policy is not specified, or this resource is destroyed, AWS gives the KMS key a default key policy that gives all principals in the owning account unlimited access to all KMS operations for the key. This default key policy effectively delegates all access control to IAM policies and KMS grants.

    BypassPolicyLockoutSafetyCheck bool
    A flag to indicate whether to bypass the key policy lockout safety check. Setting this value to true increases the risk that the KMS key becomes unmanageable. Do not set this value to true indiscriminately. If this value is set, and the resource is destroyed, a warning will be shown, and the resource will be removed from state. For more information, refer to the scenario in the Default Key Policy section in the AWS Key Management Service Developer Guide.
    KeyId string
    The ID of the KMS Key to attach the policy.
    Policy string

    A valid policy JSON document. Although this is a key policy, not an IAM policy, an aws.iam.getPolicyDocument, in the form that designates a principal, can be used. For more information about building policy documents, see the AWS IAM Policy Document Guide.

    NOTE: Note: All KMS keys must have a key policy. If a key policy is not specified, or this resource is destroyed, AWS gives the KMS key a default key policy that gives all principals in the owning account unlimited access to all KMS operations for the key. This default key policy effectively delegates all access control to IAM policies and KMS grants.

    BypassPolicyLockoutSafetyCheck bool
    A flag to indicate whether to bypass the key policy lockout safety check. Setting this value to true increases the risk that the KMS key becomes unmanageable. Do not set this value to true indiscriminately. If this value is set, and the resource is destroyed, a warning will be shown, and the resource will be removed from state. For more information, refer to the scenario in the Default Key Policy section in the AWS Key Management Service Developer Guide.
    keyId String
    The ID of the KMS Key to attach the policy.
    policy String

    A valid policy JSON document. Although this is a key policy, not an IAM policy, an aws.iam.getPolicyDocument, in the form that designates a principal, can be used. For more information about building policy documents, see the AWS IAM Policy Document Guide.

    NOTE: Note: All KMS keys must have a key policy. If a key policy is not specified, or this resource is destroyed, AWS gives the KMS key a default key policy that gives all principals in the owning account unlimited access to all KMS operations for the key. This default key policy effectively delegates all access control to IAM policies and KMS grants.

    bypassPolicyLockoutSafetyCheck Boolean
    A flag to indicate whether to bypass the key policy lockout safety check. Setting this value to true increases the risk that the KMS key becomes unmanageable. Do not set this value to true indiscriminately. If this value is set, and the resource is destroyed, a warning will be shown, and the resource will be removed from state. For more information, refer to the scenario in the Default Key Policy section in the AWS Key Management Service Developer Guide.
    keyId string
    The ID of the KMS Key to attach the policy.
    policy string

    A valid policy JSON document. Although this is a key policy, not an IAM policy, an aws.iam.getPolicyDocument, in the form that designates a principal, can be used. For more information about building policy documents, see the AWS IAM Policy Document Guide.

    NOTE: Note: All KMS keys must have a key policy. If a key policy is not specified, or this resource is destroyed, AWS gives the KMS key a default key policy that gives all principals in the owning account unlimited access to all KMS operations for the key. This default key policy effectively delegates all access control to IAM policies and KMS grants.

    bypassPolicyLockoutSafetyCheck boolean
    A flag to indicate whether to bypass the key policy lockout safety check. Setting this value to true increases the risk that the KMS key becomes unmanageable. Do not set this value to true indiscriminately. If this value is set, and the resource is destroyed, a warning will be shown, and the resource will be removed from state. For more information, refer to the scenario in the Default Key Policy section in the AWS Key Management Service Developer Guide.
    key_id str
    The ID of the KMS Key to attach the policy.
    policy str

    A valid policy JSON document. Although this is a key policy, not an IAM policy, an aws.iam.getPolicyDocument, in the form that designates a principal, can be used. For more information about building policy documents, see the AWS IAM Policy Document Guide.

    NOTE: Note: All KMS keys must have a key policy. If a key policy is not specified, or this resource is destroyed, AWS gives the KMS key a default key policy that gives all principals in the owning account unlimited access to all KMS operations for the key. This default key policy effectively delegates all access control to IAM policies and KMS grants.

    bypass_policy_lockout_safety_check bool
    A flag to indicate whether to bypass the key policy lockout safety check. Setting this value to true increases the risk that the KMS key becomes unmanageable. Do not set this value to true indiscriminately. If this value is set, and the resource is destroyed, a warning will be shown, and the resource will be removed from state. For more information, refer to the scenario in the Default Key Policy section in the AWS Key Management Service Developer Guide.
    keyId String
    The ID of the KMS Key to attach the policy.
    policy String

    A valid policy JSON document. Although this is a key policy, not an IAM policy, an aws.iam.getPolicyDocument, in the form that designates a principal, can be used. For more information about building policy documents, see the AWS IAM Policy Document Guide.

    NOTE: Note: All KMS keys must have a key policy. If a key policy is not specified, or this resource is destroyed, AWS gives the KMS key a default key policy that gives all principals in the owning account unlimited access to all KMS operations for the key. This default key policy effectively delegates all access control to IAM policies and KMS grants.

    bypassPolicyLockoutSafetyCheck Boolean
    A flag to indicate whether to bypass the key policy lockout safety check. Setting this value to true increases the risk that the KMS key becomes unmanageable. Do not set this value to true indiscriminately. If this value is set, and the resource is destroyed, a warning will be shown, and the resource will be removed from state. For more information, refer to the scenario in the Default Key Policy section in the AWS Key Management Service Developer Guide.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the KeyPolicy 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 string
    The provider-assigned unique ID for this managed resource.
    id str
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.

    Look up Existing KeyPolicy Resource

    Get an existing KeyPolicy 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?: KeyPolicyState, opts?: CustomResourceOptions): KeyPolicy
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            bypass_policy_lockout_safety_check: Optional[bool] = None,
            key_id: Optional[str] = None,
            policy: Optional[str] = None) -> KeyPolicy
    func GetKeyPolicy(ctx *Context, name string, id IDInput, state *KeyPolicyState, opts ...ResourceOption) (*KeyPolicy, error)
    public static KeyPolicy Get(string name, Input<string> id, KeyPolicyState? state, CustomResourceOptions? opts = null)
    public static KeyPolicy get(String name, Output<String> id, KeyPolicyState state, CustomResourceOptions options)
    Resource lookup is not supported in YAML
    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.
    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:
    BypassPolicyLockoutSafetyCheck bool
    A flag to indicate whether to bypass the key policy lockout safety check. Setting this value to true increases the risk that the KMS key becomes unmanageable. Do not set this value to true indiscriminately. If this value is set, and the resource is destroyed, a warning will be shown, and the resource will be removed from state. For more information, refer to the scenario in the Default Key Policy section in the AWS Key Management Service Developer Guide.
    KeyId string
    The ID of the KMS Key to attach the policy.
    Policy string

    A valid policy JSON document. Although this is a key policy, not an IAM policy, an aws.iam.getPolicyDocument, in the form that designates a principal, can be used. For more information about building policy documents, see the AWS IAM Policy Document Guide.

    NOTE: Note: All KMS keys must have a key policy. If a key policy is not specified, or this resource is destroyed, AWS gives the KMS key a default key policy that gives all principals in the owning account unlimited access to all KMS operations for the key. This default key policy effectively delegates all access control to IAM policies and KMS grants.

    BypassPolicyLockoutSafetyCheck bool
    A flag to indicate whether to bypass the key policy lockout safety check. Setting this value to true increases the risk that the KMS key becomes unmanageable. Do not set this value to true indiscriminately. If this value is set, and the resource is destroyed, a warning will be shown, and the resource will be removed from state. For more information, refer to the scenario in the Default Key Policy section in the AWS Key Management Service Developer Guide.
    KeyId string
    The ID of the KMS Key to attach the policy.
    Policy string

    A valid policy JSON document. Although this is a key policy, not an IAM policy, an aws.iam.getPolicyDocument, in the form that designates a principal, can be used. For more information about building policy documents, see the AWS IAM Policy Document Guide.

    NOTE: Note: All KMS keys must have a key policy. If a key policy is not specified, or this resource is destroyed, AWS gives the KMS key a default key policy that gives all principals in the owning account unlimited access to all KMS operations for the key. This default key policy effectively delegates all access control to IAM policies and KMS grants.

    bypassPolicyLockoutSafetyCheck Boolean
    A flag to indicate whether to bypass the key policy lockout safety check. Setting this value to true increases the risk that the KMS key becomes unmanageable. Do not set this value to true indiscriminately. If this value is set, and the resource is destroyed, a warning will be shown, and the resource will be removed from state. For more information, refer to the scenario in the Default Key Policy section in the AWS Key Management Service Developer Guide.
    keyId String
    The ID of the KMS Key to attach the policy.
    policy String

    A valid policy JSON document. Although this is a key policy, not an IAM policy, an aws.iam.getPolicyDocument, in the form that designates a principal, can be used. For more information about building policy documents, see the AWS IAM Policy Document Guide.

    NOTE: Note: All KMS keys must have a key policy. If a key policy is not specified, or this resource is destroyed, AWS gives the KMS key a default key policy that gives all principals in the owning account unlimited access to all KMS operations for the key. This default key policy effectively delegates all access control to IAM policies and KMS grants.

    bypassPolicyLockoutSafetyCheck boolean
    A flag to indicate whether to bypass the key policy lockout safety check. Setting this value to true increases the risk that the KMS key becomes unmanageable. Do not set this value to true indiscriminately. If this value is set, and the resource is destroyed, a warning will be shown, and the resource will be removed from state. For more information, refer to the scenario in the Default Key Policy section in the AWS Key Management Service Developer Guide.
    keyId string
    The ID of the KMS Key to attach the policy.
    policy string

    A valid policy JSON document. Although this is a key policy, not an IAM policy, an aws.iam.getPolicyDocument, in the form that designates a principal, can be used. For more information about building policy documents, see the AWS IAM Policy Document Guide.

    NOTE: Note: All KMS keys must have a key policy. If a key policy is not specified, or this resource is destroyed, AWS gives the KMS key a default key policy that gives all principals in the owning account unlimited access to all KMS operations for the key. This default key policy effectively delegates all access control to IAM policies and KMS grants.

    bypass_policy_lockout_safety_check bool
    A flag to indicate whether to bypass the key policy lockout safety check. Setting this value to true increases the risk that the KMS key becomes unmanageable. Do not set this value to true indiscriminately. If this value is set, and the resource is destroyed, a warning will be shown, and the resource will be removed from state. For more information, refer to the scenario in the Default Key Policy section in the AWS Key Management Service Developer Guide.
    key_id str
    The ID of the KMS Key to attach the policy.
    policy str

    A valid policy JSON document. Although this is a key policy, not an IAM policy, an aws.iam.getPolicyDocument, in the form that designates a principal, can be used. For more information about building policy documents, see the AWS IAM Policy Document Guide.

    NOTE: Note: All KMS keys must have a key policy. If a key policy is not specified, or this resource is destroyed, AWS gives the KMS key a default key policy that gives all principals in the owning account unlimited access to all KMS operations for the key. This default key policy effectively delegates all access control to IAM policies and KMS grants.

    bypassPolicyLockoutSafetyCheck Boolean
    A flag to indicate whether to bypass the key policy lockout safety check. Setting this value to true increases the risk that the KMS key becomes unmanageable. Do not set this value to true indiscriminately. If this value is set, and the resource is destroyed, a warning will be shown, and the resource will be removed from state. For more information, refer to the scenario in the Default Key Policy section in the AWS Key Management Service Developer Guide.
    keyId String
    The ID of the KMS Key to attach the policy.
    policy String

    A valid policy JSON document. Although this is a key policy, not an IAM policy, an aws.iam.getPolicyDocument, in the form that designates a principal, can be used. For more information about building policy documents, see the AWS IAM Policy Document Guide.

    NOTE: Note: All KMS keys must have a key policy. If a key policy is not specified, or this resource is destroyed, AWS gives the KMS key a default key policy that gives all principals in the owning account unlimited access to all KMS operations for the key. This default key policy effectively delegates all access control to IAM policies and KMS grants.

    Import

    Using pulumi import, import KMS Key Policies using the key_id. For example:

    $ pulumi import aws:kms/keyPolicy:KeyPolicy a 1234abcd-12ab-34cd-56ef-1234567890ab
    

    To learn more about importing existing cloud resources, see Importing resources.

    Package Details

    Repository
    AWS Classic pulumi/pulumi-aws
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the aws Terraform Provider.
    aws logo
    AWS v6.54.2 published on Wednesday, Oct 2, 2024 by Pulumi