1. Packages
  2. AWS
  3. API Docs
  4. msk
  5. ClusterPolicy
AWS v6.64.0 published on Friday, Dec 6, 2024 by Pulumi

aws.msk.ClusterPolicy

Explore with Pulumi AI

aws logo
AWS v6.64.0 published on Friday, Dec 6, 2024 by Pulumi

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

    Example Usage

    Basic Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    const current = aws.getCallerIdentity({});
    const currentGetPartition = aws.getPartition({});
    const example = new aws.msk.ClusterPolicy("example", {
        clusterArn: exampleAwsMskCluster.arn,
        policy: JSON.stringify({
            Version: "2012-10-17",
            Statement: [{
                Sid: "ExampleMskClusterPolicy",
                Effect: "Allow",
                Principal: {
                    AWS: Promise.all([currentGetPartition, current]).then(([currentGetPartition, current]) => `arn:${currentGetPartition.partition}:iam::${current.accountId}:root`),
                },
                Action: [
                    "kafka:Describe*",
                    "kafka:Get*",
                    "kafka:CreateVpcConnection",
                    "kafka:GetBootstrapBrokers",
                ],
                Resource: exampleAwsMskCluster.arn,
            }],
        }),
    });
    
    import pulumi
    import json
    import pulumi_aws as aws
    
    current = aws.get_caller_identity()
    current_get_partition = aws.get_partition()
    example = aws.msk.ClusterPolicy("example",
        cluster_arn=example_aws_msk_cluster["arn"],
        policy=json.dumps({
            "Version": "2012-10-17",
            "Statement": [{
                "Sid": "ExampleMskClusterPolicy",
                "Effect": "Allow",
                "Principal": {
                    "AWS": f"arn:{current_get_partition.partition}:iam::{current.account_id}:root",
                },
                "Action": [
                    "kafka:Describe*",
                    "kafka:Get*",
                    "kafka:CreateVpcConnection",
                    "kafka:GetBootstrapBrokers",
                ],
                "Resource": example_aws_msk_cluster["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 {
    		current, err := aws.GetCallerIdentity(ctx, &aws.GetCallerIdentityArgs{}, nil)
    		if err != nil {
    			return err
    		}
    		currentGetPartition, err := aws.GetPartition(ctx, &aws.GetPartitionArgs{}, 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", currentGetPartition.Partition, current.AccountId),
    					},
    					"Action": []string{
    						"kafka:Describe*",
    						"kafka:Get*",
    						"kafka:CreateVpcConnection",
    						"kafka:GetBootstrapBrokers",
    					},
    					"Resource": exampleAwsMskCluster.Arn,
    				},
    			},
    		})
    		if err != nil {
    			return err
    		}
    		json0 := string(tmpJSON0)
    		_, err = msk.NewClusterPolicy(ctx, "example", &msk.ClusterPolicyArgs{
    			ClusterArn: pulumi.Any(exampleAwsMskCluster.Arn),
    			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 current = Aws.GetCallerIdentity.Invoke();
    
        var currentGetPartition = Aws.GetPartition.Invoke();
    
        var example = new Aws.Msk.ClusterPolicy("example", new()
        {
            ClusterArn = exampleAwsMskCluster.Arn,
            Policy = 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"] = Output.Tuple(currentGetPartition, current).Apply(values =>
                            {
                                var currentGetPartition = values.Item1;
                                var current = values.Item2;
                                return $"arn:{currentGetPartition.Apply(getPartitionResult => getPartitionResult.Partition)}:iam::{current.Apply(getCallerIdentityResult => getCallerIdentityResult.AccountId)}:root";
                            }),
                        },
                        ["Action"] = new[]
                        {
                            "kafka:Describe*",
                            "kafka:Get*",
                            "kafka:CreateVpcConnection",
                            "kafka:GetBootstrapBrokers",
                        },
                        ["Resource"] = exampleAwsMskCluster.Arn,
                    },
                },
            }),
        });
    
    });
    
    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 current = AwsFunctions.getCallerIdentity();
    
            final var currentGetPartition = AwsFunctions.getPartition();
    
            var example = new ClusterPolicy("example", ClusterPolicyArgs.builder()
                .clusterArn(exampleAwsMskCluster.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", currentGetPartition.applyValue(getPartitionResult -> getPartitionResult.partition()),current.applyValue(getCallerIdentityResult -> getCallerIdentityResult.accountId())))
                            )),
                            jsonProperty("Action", jsonArray(
                                "kafka:Describe*", 
                                "kafka:Get*", 
                                "kafka:CreateVpcConnection", 
                                "kafka:GetBootstrapBrokers"
                            )),
                            jsonProperty("Resource", exampleAwsMskCluster.arn())
                        )))
                    )))
                .build());
    
        }
    }
    
    resources:
      example:
        type: aws:msk:ClusterPolicy
        properties:
          clusterArn: ${exampleAwsMskCluster.arn}
          policy:
            fn::toJSON:
              Version: 2012-10-17
              Statement:
                - Sid: ExampleMskClusterPolicy
                  Effect: Allow
                  Principal:
                    AWS: arn:${currentGetPartition.partition}:iam::${current.accountId}:root
                  Action:
                    - kafka:Describe*
                    - kafka:Get*
                    - kafka:CreateVpcConnection
                    - kafka:GetBootstrapBrokers
                  Resource: ${exampleAwsMskCluster.arn}
    variables:
      current:
        fn::invoke:
          Function: aws:getCallerIdentity
          Arguments: {}
      currentGetPartition:
        fn::invoke:
          Function: aws:getPartition
          Arguments: {}
    

    Create ClusterPolicy Resource

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

    Constructor syntax

    new ClusterPolicy(name: string, args: ClusterPolicyArgs, opts?: CustomResourceOptions);
    @overload
    def ClusterPolicy(resource_name: str,
                      args: ClusterPolicyArgs,
                      opts: Optional[ResourceOptions] = None)
    
    @overload
    def ClusterPolicy(resource_name: str,
                      opts: Optional[ResourceOptions] = None,
                      cluster_arn: Optional[str] = None,
                      policy: Optional[str] = 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.
    
    

    Parameters

    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.

    Constructor example

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

    var clusterPolicyResource = new Aws.Msk.ClusterPolicy("clusterPolicyResource", new()
    {
        ClusterArn = "string",
        Policy = "string",
    });
    
    example, err := msk.NewClusterPolicy(ctx, "clusterPolicyResource", &msk.ClusterPolicyArgs{
    	ClusterArn: pulumi.String("string"),
    	Policy:     pulumi.String("string"),
    })
    
    var clusterPolicyResource = new ClusterPolicy("clusterPolicyResource", ClusterPolicyArgs.builder()
        .clusterArn("string")
        .policy("string")
        .build());
    
    cluster_policy_resource = aws.msk.ClusterPolicy("clusterPolicyResource",
        cluster_arn="string",
        policy="string")
    
    const clusterPolicyResource = new aws.msk.ClusterPolicy("clusterPolicyResource", {
        clusterArn: "string",
        policy: "string",
    });
    
    type: aws:msk:ClusterPolicy
    properties:
        clusterArn: string
        policy: string
    

    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

    In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

    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

    Using pulumi import, import Managed Streaming for Kafka Cluster Policy using the cluster_arn. For example:

    $ pulumi import aws:msk/clusterPolicy:ClusterPolicy example arn:aws:kafka:us-west-2:123456789012:cluster/example/279c0212-d057-4dba-9aa9-1c4e5a25bfc7-3
    

    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.64.0 published on Friday, Dec 6, 2024 by Pulumi