1. Packages
  2. AWS Classic
  3. API Docs
  4. msk
  5. ClusterPolicy

Try AWS Native preview for resources not in the classic version.

AWS Classic v6.2.0 published on Monday, Sep 18, 2023 by Pulumi

aws.msk.ClusterPolicy

Explore with Pulumi AI

aws logo

Try AWS Native preview for resources not in the classic version.

AWS Classic v6.2.0 published on Monday, Sep 18, 2023 by Pulumi

    Resource for managing an AWS Managed Streaming for Kafka Cluster Policy.

    Example Usage

    Basic Usage

    using System.Collections.Generic;
    using System.Linq;
    using System.Text.Json;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var currentCallerIdentity = Aws.GetCallerIdentity.Invoke();
    
        var currentPartition = Aws.GetPartition.Invoke();
    
        var example = new Aws.Msk.ClusterPolicy("example", new()
        {
            ClusterArn = aws_msk_cluster.Example.Arn,
            Policy = Output.Tuple(currentPartition, currentCallerIdentity).Apply(values =>
            {
                var currentPartition = values.Item1;
                var currentCallerIdentity = values.Item2;
                return JsonSerializer.Serialize(new Dictionary<string, object?>
                {
                    ["Version"] = "2012-10-17",
                    ["Statement"] = new[]
                    {
                        new Dictionary<string, object?>
                        {
                            ["Sid"] = "ExampleMskClusterPolicy",
                            ["Effect"] = "Allow",
                            ["Principal"] = new Dictionary<string, object?>
                            {
                                ["AWS"] = $"arn:{currentPartition.Apply(getPartitionResult => getPartitionResult.Partition)}:iam::{currentCallerIdentity.Apply(getCallerIdentityResult => getCallerIdentityResult.AccountId)}:root",
                            },
                            ["Action"] = new[]
                            {
                                "kafka:Describe*",
                                "kafka:Get*",
                                "kafka:CreateVpcConnection",
                                "kafka:GetBootstrapBrokers",
                            },
                            ["Resource"] = aws_msk_cluster.Example.Arn,
                        },
                    },
                });
            }),
        });
    
    });
    
    package main
    
    import (
    	"encoding/json"
    	"fmt"
    
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws"
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/msk"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		currentCallerIdentity, err := aws.GetCallerIdentity(ctx, nil, nil)
    		if err != nil {
    			return err
    		}
    		currentPartition, err := aws.GetPartition(ctx, nil, nil)
    		if err != nil {
    			return err
    		}
    		tmpJSON0, err := json.Marshal(map[string]interface{}{
    			"Version": "2012-10-17",
    			"Statement": []map[string]interface{}{
    				map[string]interface{}{
    					"Sid":    "ExampleMskClusterPolicy",
    					"Effect": "Allow",
    					"Principal": map[string]interface{}{
    						"AWS": fmt.Sprintf("arn:%v:iam::%v:root", currentPartition.Partition, currentCallerIdentity.AccountId),
    					},
    					"Action": []string{
    						"kafka:Describe*",
    						"kafka:Get*",
    						"kafka:CreateVpcConnection",
    						"kafka:GetBootstrapBrokers",
    					},
    					"Resource": aws_msk_cluster.Example.Arn,
    				},
    			},
    		})
    		if err != nil {
    			return err
    		}
    		json0 := string(tmpJSON0)
    		_, err = msk.NewClusterPolicy(ctx, "example", &msk.ClusterPolicyArgs{
    			ClusterArn: pulumi.Any(aws_msk_cluster.Example.Arn),
    			Policy:     pulumi.String(json0),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.aws.AwsFunctions;
    import com.pulumi.aws.inputs.GetCallerIdentityArgs;
    import com.pulumi.aws.inputs.GetPartitionArgs;
    import com.pulumi.aws.msk.ClusterPolicy;
    import com.pulumi.aws.msk.ClusterPolicyArgs;
    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) {
            final var currentCallerIdentity = AwsFunctions.getCallerIdentity();
    
            final var currentPartition = AwsFunctions.getPartition();
    
            var example = new ClusterPolicy("example", ClusterPolicyArgs.builder()        
                .clusterArn(aws_msk_cluster.example().arn())
                .policy(serializeJson(
                    jsonObject(
                        jsonProperty("Version", "2012-10-17"),
                        jsonProperty("Statement", jsonArray(jsonObject(
                            jsonProperty("Sid", "ExampleMskClusterPolicy"),
                            jsonProperty("Effect", "Allow"),
                            jsonProperty("Principal", jsonObject(
                                jsonProperty("AWS", String.format("arn:%s:iam::%s:root", currentPartition.applyValue(getPartitionResult -> getPartitionResult.partition()),currentCallerIdentity.applyValue(getCallerIdentityResult -> getCallerIdentityResult.accountId())))
                            )),
                            jsonProperty("Action", jsonArray(
                                "kafka:Describe*", 
                                "kafka:Get*", 
                                "kafka:CreateVpcConnection", 
                                "kafka:GetBootstrapBrokers"
                            )),
                            jsonProperty("Resource", aws_msk_cluster.example().arn())
                        )))
                    )))
                .build());
    
        }
    }
    
    import pulumi
    import json
    import pulumi_aws as aws
    
    current_caller_identity = aws.get_caller_identity()
    current_partition = aws.get_partition()
    example = aws.msk.ClusterPolicy("example",
        cluster_arn=aws_msk_cluster["example"]["arn"],
        policy=json.dumps({
            "Version": "2012-10-17",
            "Statement": [{
                "Sid": "ExampleMskClusterPolicy",
                "Effect": "Allow",
                "Principal": {
                    "AWS": f"arn:{current_partition.partition}:iam::{current_caller_identity.account_id}:root",
                },
                "Action": [
                    "kafka:Describe*",
                    "kafka:Get*",
                    "kafka:CreateVpcConnection",
                    "kafka:GetBootstrapBrokers",
                ],
                "Resource": aws_msk_cluster["example"]["arn"],
            }],
        }))
    
    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    const currentCallerIdentity = aws.getCallerIdentity({});
    const currentPartition = aws.getPartition({});
    const example = new aws.msk.ClusterPolicy("example", {
        clusterArn: aws_msk_cluster.example.arn,
        policy: Promise.all([currentPartition, currentCallerIdentity]).then(([currentPartition, currentCallerIdentity]) => JSON.stringify({
            Version: "2012-10-17",
            Statement: [{
                Sid: "ExampleMskClusterPolicy",
                Effect: "Allow",
                Principal: {
                    AWS: `arn:${currentPartition.partition}:iam::${currentCallerIdentity.accountId}:root`,
                },
                Action: [
                    "kafka:Describe*",
                    "kafka:Get*",
                    "kafka:CreateVpcConnection",
                    "kafka:GetBootstrapBrokers",
                ],
                Resource: aws_msk_cluster.example.arn,
            }],
        })),
    });
    
    resources:
      example:
        type: aws:msk:ClusterPolicy
        properties:
          clusterArn: ${aws_msk_cluster.example.arn}
          policy:
            fn::toJSON:
              Version: 2012-10-17
              Statement:
                - Sid: ExampleMskClusterPolicy
                  Effect: Allow
                  Principal:
                    AWS: arn:${currentPartition.partition}:iam::${currentCallerIdentity.accountId}:root
                  Action:
                    - kafka:Describe*
                    - kafka:Get*
                    - kafka:CreateVpcConnection
                    - kafka:GetBootstrapBrokers
                  Resource: ${aws_msk_cluster.example.arn}
    variables:
      currentCallerIdentity:
        fn::invoke:
          Function: aws:getCallerIdentity
          Arguments: {}
      currentPartition:
        fn::invoke:
          Function: aws:getPartition
          Arguments: {}
    

    Create ClusterPolicy Resource

    new ClusterPolicy(name: string, args: ClusterPolicyArgs, opts?: CustomResourceOptions);
    @overload
    def ClusterPolicy(resource_name: str,
                      opts: Optional[ResourceOptions] = None,
                      cluster_arn: Optional[str] = None,
                      policy: Optional[str] = None)
    @overload
    def ClusterPolicy(resource_name: str,
                      args: ClusterPolicyArgs,
                      opts: Optional[ResourceOptions] = None)
    func NewClusterPolicy(ctx *Context, name string, args ClusterPolicyArgs, opts ...ResourceOption) (*ClusterPolicy, error)
    public ClusterPolicy(string name, ClusterPolicyArgs args, CustomResourceOptions? opts = null)
    public ClusterPolicy(String name, ClusterPolicyArgs args)
    public ClusterPolicy(String name, ClusterPolicyArgs args, CustomResourceOptions options)
    
    type: aws:msk:ClusterPolicy
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    
    name string
    The unique name of the resource.
    args ClusterPolicyArgs
    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 ClusterPolicyArgs
    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 ClusterPolicyArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args ClusterPolicyArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args ClusterPolicyArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

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

    ClusterArn string

    The Amazon Resource Name (ARN) that uniquely identifies the cluster.

    Policy string

    Resource policy for cluster.

    ClusterArn string

    The Amazon Resource Name (ARN) that uniquely identifies the cluster.

    Policy string

    Resource policy for cluster.

    clusterArn String

    The Amazon Resource Name (ARN) that uniquely identifies the cluster.

    policy String

    Resource policy for cluster.

    clusterArn string

    The Amazon Resource Name (ARN) that uniquely identifies the cluster.

    policy string

    Resource policy for cluster.

    cluster_arn str

    The Amazon Resource Name (ARN) that uniquely identifies the cluster.

    policy str

    Resource policy for cluster.

    clusterArn String

    The Amazon Resource Name (ARN) that uniquely identifies the cluster.

    policy String

    Resource policy for cluster.

    Outputs

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

    CurrentVersion string
    Id string

    The provider-assigned unique ID for this managed resource.

    CurrentVersion string
    Id string

    The provider-assigned unique ID for this managed resource.

    currentVersion String
    id String

    The provider-assigned unique ID for this managed resource.

    currentVersion string
    id string

    The provider-assigned unique ID for this managed resource.

    current_version str
    id str

    The provider-assigned unique ID for this managed resource.

    currentVersion String
    id String

    The provider-assigned unique ID for this managed resource.

    Look up Existing ClusterPolicy Resource

    Get an existing ClusterPolicy 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?: ClusterPolicyState, opts?: CustomResourceOptions): ClusterPolicy
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            cluster_arn: Optional[str] = None,
            current_version: Optional[str] = None,
            policy: Optional[str] = None) -> ClusterPolicy
    func GetClusterPolicy(ctx *Context, name string, id IDInput, state *ClusterPolicyState, opts ...ResourceOption) (*ClusterPolicy, error)
    public static ClusterPolicy Get(string name, Input<string> id, ClusterPolicyState? state, CustomResourceOptions? opts = null)
    public static ClusterPolicy get(String name, Output<String> id, ClusterPolicyState 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:
    ClusterArn string

    The Amazon Resource Name (ARN) that uniquely identifies the cluster.

    CurrentVersion string
    Policy string

    Resource policy for cluster.

    ClusterArn string

    The Amazon Resource Name (ARN) that uniquely identifies the cluster.

    CurrentVersion string
    Policy string

    Resource policy for cluster.

    clusterArn String

    The Amazon Resource Name (ARN) that uniquely identifies the cluster.

    currentVersion String
    policy String

    Resource policy for cluster.

    clusterArn string

    The Amazon Resource Name (ARN) that uniquely identifies the cluster.

    currentVersion string
    policy string

    Resource policy for cluster.

    cluster_arn str

    The Amazon Resource Name (ARN) that uniquely identifies the cluster.

    current_version str
    policy str

    Resource policy for cluster.

    clusterArn String

    The Amazon Resource Name (ARN) that uniquely identifies the cluster.

    currentVersion String
    policy String

    Resource policy for cluster.

    Import

    In TODO v1.5.0 and later, use an import block to import Managed Streaming for Kafka Cluster Policy using the `cluster_arn. For exampleterraform import {

    to = aws_msk_cluster_policy.example

    id = “arn:aws:kafka:us-west-2:123456789012:cluster/example/279c0212-d057-4dba-9aa9-1c4e5a25bfc7-3” } Using TODO import, import Managed Streaming for Kafka Cluster Policy using the cluster_arn. For exampleconsole % TODO import aws_msk_cluster_policy.example arn:aws:kafka:us-west-2:123456789012:cluster/example/279c0212-d057-4dba-9aa9-1c4e5a25bfc7-3

    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

    Try AWS Native preview for resources not in the classic version.

    AWS Classic v6.2.0 published on Monday, Sep 18, 2023 by Pulumi