ScramSecretAssociation class
Associates SCRAM secrets stored in the Secrets Manager service with a Managed Streaming for Kafka (MSK) cluster.
> This resource takes exclusive ownership over SCRAM secrets associated with a cluster. This includes removal of SCRAM secrets which are not explicitly configured. To prevent persistent drift, ensure any aws.msk.SingleScramSecretAssociation resources managed alongside this resource are included in the secretArnList argument.
> Note: The following assumes the MSK cluster has SASL/SCRAM authentication enabled. See below for example usage or refer to the Username/Password Authentication section of the MSK Developer Guide for more details.
To set up username and password authentication for a cluster, create an aws.secretsmanager.Secret resource and associate
a username and password with the secret with an aws.secretsmanager.SecretVersion resource. When creating a secret for the cluster,
the name must have the prefix AmazonMSK_ and you must either use an existing custom AWS KMS key or create a new
custom AWS KMS key for your secret with the aws.kms.Key resource. It is important to note that a policy is required for the aws.secretsmanager.Secret
resource in order for Kafka to be able to read it. This policy is attached automatically when the aws.msk.ScramSecretAssociation is used,
however, this policy will not be in the state and as such, will present a diff on plan/apply. For that reason, you must use the aws.secretsmanager.SecretPolicy
resource](/docs/providers/aws/r/secretsmanager_secret_policy.html) as shown below in order to ensure that the state is in a clean state after the creation of secret and the association to the cluster.
Example Usage
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const exampleCluster = new aws.msk.Cluster("example", {
clientAuthentication: {
sasl: {
scram: true,
},
},
clusterName: "example",
});
const exampleKey = new aws.kms.Key("example", {description: "Example Key for MSK Cluster Scram Secret Association"});
const exampleSecret = new aws.secretsmanager.Secret("example", {
name: "AmazonMSK_example",
kmsKeyId: exampleKey.keyId,
});
const exampleSecretVersion = new aws.secretsmanager.SecretVersion("example", {
secretId: exampleSecret.id,
secretString: JSON.stringify({
username: "user",
password: "pass",
}),
});
const exampleScramSecretAssociation = new aws.msk.ScramSecretAssociation("example", {
clusterArn: exampleCluster.arn,
secretArnLists: [exampleSecret.arn],
}, {
dependsOn: [exampleSecretVersion],
});
const example = aws.iam.getPolicyDocumentOutput({
statements: [{
principals: [{
type: "Service",
identifiers: ["kafka.amazonaws.com"],
}],
sid: "AWSKafkaResourcePolicy",
effect: "Allow",
actions: ["secretsmanager:getSecretValue"],
resources: [exampleSecret.arn],
}],
});
const exampleSecretPolicy = new aws.secretsmanager.SecretPolicy("example", {
secretArn: exampleSecret.arn,
policy: example.json,
});
import pulumi
import json
import pulumi_aws as aws
example_cluster = aws.msk.Cluster("example",
client_authentication={
"sasl": {
"scram": True,
},
},
cluster_name="example")
example_key = aws.kms.Key("example", description="Example Key for MSK Cluster Scram Secret Association")
example_secret = aws.secretsmanager.Secret("example",
name="AmazonMSK_example",
kms_key_id=example_key.key_id)
example_secret_version = aws.secretsmanager.SecretVersion("example",
secret_id=example_secret.id,
secret_string=json.dumps({
"username": "user",
"password": "pass",
}))
example_scram_secret_association = aws.msk.ScramSecretAssociation("example",
cluster_arn=example_cluster.arn,
secret_arn_lists=[example_secret.arn],
opts = pulumi.ResourceOptions(depends_on=[example_secret_version]))
example = aws.iam.get_policy_document_output(statements=[{
"principals": [{
"type": "Service",
"identifiers": ["kafka.amazonaws.com"],
}],
"sid": "AWSKafkaResourcePolicy",
"effect": "Allow",
"actions": ["secretsmanager:getSecretValue"],
"resources": [example_secret.arn],
}])
example_secret_policy = aws.secretsmanager.SecretPolicy("example",
secret_arn=example_secret.arn,
policy=example.json)
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var exampleCluster = new Aws.Msk.Cluster("example", new()
{
ClientAuthentication = new Aws.Msk.Inputs.ClusterClientAuthenticationArgs
{
Sasl = new Aws.Msk.Inputs.ClusterClientAuthenticationSaslArgs
{
Scram = true,
},
},
ClusterName = "example",
});
var exampleKey = new Aws.Kms.Key("example", new()
{
Description = "Example Key for MSK Cluster Scram Secret Association",
});
var exampleSecret = new Aws.SecretsManager.Secret("example", new()
{
Name = "AmazonMSK_example",
KmsKeyId = exampleKey.KeyId,
});
var exampleSecretVersion = new Aws.SecretsManager.SecretVersion("example", new()
{
SecretId = exampleSecret.Id,
SecretString = JsonSerializer.Serialize(new Dictionary<string, object?>
{
["username"] = "user",
["password"] = "pass",
}),
});
var exampleScramSecretAssociation = new Aws.Msk.ScramSecretAssociation("example", new()
{
ClusterArn = exampleCluster.Arn,
SecretArnLists = new[]
{
exampleSecret.Arn,
},
}, new CustomResourceOptions
{
DependsOn =
{
exampleSecretVersion,
},
});
var example = Aws.Iam.GetPolicyDocument.Invoke(new()
{
Statements = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementInputArgs
{
Principals = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalInputArgs
{
Type = "Service",
Identifiers = new[]
{
"kafka.amazonaws.com",
},
},
},
Sid = "AWSKafkaResourcePolicy",
Effect = "Allow",
Actions = new[]
{
"secretsmanager:getSecretValue",
},
Resources = new[]
{
exampleSecret.Arn,
},
},
},
});
var exampleSecretPolicy = new Aws.SecretsManager.SecretPolicy("example", new()
{
SecretArn = exampleSecret.Arn,
Policy = example.Apply(getPolicyDocumentResult => getPolicyDocumentResult.Json),
});
});
package main
import (
"encoding/json"
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/iam"
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/kms"
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/msk"
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/secretsmanager"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
exampleCluster, err := msk.NewCluster(ctx, "example", &msk.ClusterArgs{
ClientAuthentication: &msk.ClusterClientAuthenticationArgs{
Sasl: &msk.ClusterClientAuthenticationSaslArgs{
Scram: pulumi.Bool(true),
},
},
ClusterName: pulumi.String("example"),
})
if err != nil {
return err
}
exampleKey, err := kms.NewKey(ctx, "example", &kms.KeyArgs{
Description: pulumi.String("Example Key for MSK Cluster Scram Secret Association"),
})
if err != nil {
return err
}
exampleSecret, err := secretsmanager.NewSecret(ctx, "example", &secretsmanager.SecretArgs{
Name: pulumi.String("AmazonMSK_example"),
KmsKeyId: exampleKey.KeyId,
})
if err != nil {
return err
}
tmpJSON0, err := json.Marshal(map[string]string{
"username": "user",
"password": "pass",
})
if err != nil {
return err
}
json0 := string(tmpJSON0)
exampleSecretVersion, err := secretsmanager.NewSecretVersion(ctx, "example", &secretsmanager.SecretVersionArgs{
SecretId: exampleSecret.ID().ToIDOutput().ToStringOutput(),
SecretString: pulumi.String(json0),
})
if err != nil {
return err
}
_, err = msk.NewScramSecretAssociation(ctx, "example", &msk.ScramSecretAssociationArgs{
ClusterArn: exampleCluster.Arn,
SecretArnLists: pulumi.StringArray{
exampleSecret.Arn,
},
}, pulumi.DependsOn([]pulumi.Resource{
exampleSecretVersion,
}))
if err != nil {
return err
}
example := iam.GetPolicyDocumentOutput(ctx, iam.GetPolicyDocumentOutputArgs{
Statements: iam.GetPolicyDocumentStatementArray{
&iam.GetPolicyDocumentStatementArgs{
Principals: iam.GetPolicyDocumentStatementPrincipalArray{
&iam.GetPolicyDocumentStatementPrincipalArgs{
Type: pulumi.String("Service"),
Identifiers: pulumi.StringArray{
pulumi.String("kafka.amazonaws.com"),
},
},
},
Sid: pulumi.String("AWSKafkaResourcePolicy"),
Effect: pulumi.String("Allow"),
Actions: pulumi.StringArray{
pulumi.String("secretsmanager:getSecretValue"),
},
Resources: pulumi.StringArray{
exampleSecret.Arn,
},
},
},
}, nil)
_, err = secretsmanager.NewSecretPolicy(ctx, "example", &secretsmanager.SecretPolicyArgs{
SecretArn: exampleSecret.Arn,
Policy: example.Json(),
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
}
}
data "aws_iam_getpolicydocument" "example" {
statements {
principals {
type = "Service"
identifiers = ["kafka.amazonaws.com"]
}
sid = "AWSKafkaResourcePolicy"
effect = "Allow"
actions = ["secretsmanager:getSecretValue"]
resources = [aws_secretsmanager_secret.example.arn]
}
}
resource "aws_msk_scramsecretassociation" "example" {
depends_on = [aws_secretsmanager_secretversion.example]
cluster_arn = aws_msk_cluster.example.arn
secret_arn_lists = [aws_secretsmanager_secret.example.arn]
}
resource "aws_msk_cluster" "example" {
client_authentication = {
sasl = {
scram = true
}
}
cluster_name = "example"
}
resource "aws_secretsmanager_secret" "example" {
name = "AmazonMSK_example"
kms_key_id = aws_kms_key.example.key_id
}
resource "aws_kms_key" "example" {
description = "Example Key for MSK Cluster Scram Secret Association"
}
resource "aws_secretsmanager_secretversion" "example" {
secret_id = aws_secretsmanager_secret.example.id
secret_string = jsonencode({
"username" = "user"
"password" = "pass"
})
}
resource "aws_secretsmanager_secretpolicy" "example" {
secret_arn = aws_secretsmanager_secret.example.arn
policy = data.aws_iam_getpolicydocument.example.json
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.msk.Cluster;
import com.pulumi.aws.msk.ClusterArgs;
import com.pulumi.aws.msk.inputs.ClusterClientAuthenticationArgs;
import com.pulumi.aws.msk.inputs.ClusterClientAuthenticationSaslArgs;
import com.pulumi.aws.kms.Key;
import com.pulumi.aws.kms.KeyArgs;
import com.pulumi.aws.secretsmanager.Secret;
import com.pulumi.aws.secretsmanager.SecretArgs;
import com.pulumi.aws.secretsmanager.SecretVersion;
import com.pulumi.aws.secretsmanager.SecretVersionArgs;
import com.pulumi.aws.msk.ScramSecretAssociation;
import com.pulumi.aws.msk.ScramSecretAssociationArgs;
import com.pulumi.aws.iam.IamFunctions;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentArgs;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentStatementArgs;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentStatementPrincipalArgs;
import com.pulumi.aws.secretsmanager.SecretPolicy;
import com.pulumi.aws.secretsmanager.SecretPolicyArgs;
import static com.pulumi.codegen.internal.Serialization.*;
import com.pulumi.resources.CustomResourceOptions;
import java.util.ArrayList;
import java.util.Arrays;
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 exampleCluster = new Cluster("exampleCluster", ClusterArgs.builder()
.clientAuthentication(ClusterClientAuthenticationArgs.builder()
.sasl(ClusterClientAuthenticationSaslArgs.builder()
.scram(true)
.build())
.build())
.clusterName("example")
.build());
var exampleKey = new Key("exampleKey", KeyArgs.builder()
.description("Example Key for MSK Cluster Scram Secret Association")
.build());
var exampleSecret = new Secret("exampleSecret", SecretArgs.builder()
.name("AmazonMSK_example")
.kmsKeyId(exampleKey.keyId())
.build());
var exampleSecretVersion = new SecretVersion("exampleSecretVersion", SecretVersionArgs.builder()
.secretId(exampleSecret.id())
.secretString(serializeJson(
jsonObject(
jsonProperty("username", "user"),
jsonProperty("password", "pass")
)))
.build());
var exampleScramSecretAssociation = new ScramSecretAssociation("exampleScramSecretAssociation", ScramSecretAssociationArgs.builder()
.clusterArn(exampleCluster.arn())
.secretArnLists(exampleSecret.arn())
.build(), CustomResourceOptions.builder()
.dependsOn(exampleSecretVersion)
.build());
final var example = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
.statements(GetPolicyDocumentStatementArgs.builder()
.principals(GetPolicyDocumentStatementPrincipalArgs.builder()
.type("Service")
.identifiers("kafka.amazonaws.com")
.build())
.sid("AWSKafkaResourcePolicy")
.effect("Allow")
.actions("secretsmanager:getSecretValue")
.resources(exampleSecret.arn())
.build())
.build());
var exampleSecretPolicy = new SecretPolicy("exampleSecretPolicy", SecretPolicyArgs.builder()
.secretArn(exampleSecret.arn())
.policy(example.applyValue(_example -> _example.json()))
.build());
}
}
resources:
exampleScramSecretAssociation:
type: aws:msk:ScramSecretAssociation
name: example
properties:
clusterArn: ${exampleCluster.arn}
secretArnLists:
- ${exampleSecret.arn}
options:
dependsOn:
- ${exampleSecretVersion}
exampleCluster:
type: aws:msk:Cluster
name: example
properties:
clientAuthentication:
sasl:
scram: true
clusterName: example
exampleSecret:
type: aws:secretsmanager:Secret
name: example
properties:
name: AmazonMSK_example
kmsKeyId: ${exampleKey.keyId}
exampleKey:
type: aws:kms:Key
name: example
properties:
description: Example Key for MSK Cluster Scram Secret Association
exampleSecretVersion:
type: aws:secretsmanager:SecretVersion
name: example
properties:
secretId: ${exampleSecret.id}
secretString:
fn::toJSON:
username: user
password: pass
exampleSecretPolicy:
type: aws:secretsmanager:SecretPolicy
name: example
properties:
secretArn: ${exampleSecret.arn}
policy: ${example.json}
variables:
example:
fn::invoke:
function: aws:iam:getPolicyDocument
arguments:
statements:
- principals:
- type: Service
identifiers:
- kafka.amazonaws.com
sid: AWSKafkaResourcePolicy
effect: Allow
actions:
- secretsmanager:getSecretValue
resources:
- ${exampleSecret.arn}
Import
Using pulumi import, import MSK SCRAM Secret Associations using the id. For example:
$ pulumi import aws:msk/scramSecretAssociation:ScramSecretAssociation example arn:aws:kafka:us-west-2:123456789012:cluster/example/279c0212-d057-4dba-9aa9-1c4e5a25bfc7-3
Constructors
- ScramSecretAssociation(String name, {ScramSecretAssociationArgs? args, CustomResourceOptions? options})
-
Creates a new ScramSecretAssociation.
nameThe Pulumi resource name.argsArguments used to configure this ScramSecretAssociation. The set of arguments for ScramSecretAssociation.optionsResource options controlling this resource's behavior. - ScramSecretAssociation.reference(String urn)
- Creates a typed reference to an existing ScramSecretAssociation resource.
Properties
-
childResources
→ Set<
Resource> -
finalinherited
-
clusterArn
↔ Output<
String> -
ARN of the MSK cluster.
latefinal
-
completionSources
↔ Map<
String, IOutputCompletionSource> -
latefinalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
-
id
↔ Output<
String> -
getter/setter pairinherited
- isCustom → bool
-
Returns whether this resource is provider-managed.
no setterinherited
- isProtected → bool
-
Returns whether this resource is protected from deletion.
no setterinherited
- isRemote → bool
-
Whether this resource is registered as remote.
no setterinherited
- isResourceReference → bool
-
Whether this instance represents a resource value returned over RPC.
finalinherited
-
region
↔ Output<
String> -
Region where this resource will be managed. Defaults to the Region set in the provider configuration.
latefinal
-
resourceTransforms
→ List<
ResourceTransform> -
Inherited/explicit async transforms.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
secretArnLists
↔ Output<
List< String> > -
List of AWS Secrets Manager secret ARNs.
latefinal
-
transformations
→ List<
ResourceTransformation> -
Inherited/explicit legacy transformations.
no setterinherited
-
urn
↔ Output<
String> -
latefinalinherited
Methods
-
failId(
Object error) → void -
Completes this resource ID with an error when registration fails.
inherited
-
failOutputs(
Object error) → void -
Completes all output properties with
error.inherited -
failUrn(
Object error) → void -
Completes this resource URN with an error when registration fails.
inherited
-
getProvider(
String moduleMember) → ProviderResource? -
Returns provider for
moduleMember's package, if configured.inherited -
getResourceName(
) → String -
Returns this resource's logical name.
inherited
-
getResourceType(
) → String -
Returns this resource's Pulumi type token.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerOutput<
T> (String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output< T> -
Registers a dynamic output property for this resource.
inherited
-
resolveId(
String? value, {required bool isKnown}) → void -
Resolves the provider-assigned ID for this resource.
inherited
-
resolveOutputs(
Struct outputs) → void -
Resolves all output properties from a monitor response payload.
inherited
-
resolveUrn(
String value) → void -
Resolves this resource's URN once assigned by the engine.
inherited
-
serializeProperties(
Map< String, dynamic> properties) → Future<Struct> -
Serializes resource properties for RPC transmission.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
get(
String name, Input< String> id, {ScramSecretAssociationState? state, CustomResourceOptions? options}) → ScramSecretAssociation -
Gets an existing ScramSecretAssociation resource's state with the given
nameandid.