github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/msk/scramSecretAssociation.go (about)

     1  // Code generated by the Pulumi Terraform Bridge (tfgen) Tool DO NOT EDIT.
     2  // *** WARNING: Do not edit by hand unless you're certain you know what you are doing! ***
     3  
     4  package msk
     5  
     6  import (
     7  	"context"
     8  	"reflect"
     9  
    10  	"errors"
    11  	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/internal"
    12  	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    13  )
    14  
    15  // Associates SCRAM secrets stored in the Secrets Manager service with a Managed Streaming for Kafka (MSK) cluster.
    16  //
    17  // > **Note:** The following assumes the MSK cluster has SASL/SCRAM authentication enabled. See below for example usage or refer to the [Username/Password Authentication](https://docs.aws.amazon.com/msk/latest/developerguide/msk-password.html) section of the MSK Developer Guide for more details.
    18  //
    19  // To set up username and password authentication for a cluster, create an `secretsmanager.Secret` resource and associate
    20  // a username and password with the secret with an `secretsmanager.SecretVersion` resource. When creating a secret for the cluster,
    21  // the `name` must have the prefix `AmazonMSK_` and you must either use an existing custom AWS KMS key or create a new
    22  // custom AWS KMS key for your secret with the `kms.Key` resource. It is important to note that a policy is required for the `secretsmanager.Secret`
    23  // resource in order for Kafka to be able to read it. This policy is attached automatically when the `msk.ScramSecretAssociation` is used,
    24  // 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 `secretsmanager.SecretPolicy`
    25  // 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.
    26  //
    27  // ## Example Usage
    28  //
    29  // <!--Start PulumiCodeChooser -->
    30  // ```go
    31  // package main
    32  //
    33  // import (
    34  //
    35  //	"encoding/json"
    36  //
    37  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam"
    38  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/kms"
    39  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/msk"
    40  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/secretsmanager"
    41  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    42  //
    43  // )
    44  //
    45  //	func main() {
    46  //		pulumi.Run(func(ctx *pulumi.Context) error {
    47  //			exampleCluster, err := msk.NewCluster(ctx, "example", &msk.ClusterArgs{
    48  //				ClusterName: pulumi.String("example"),
    49  //				ClientAuthentication: &msk.ClusterClientAuthenticationArgs{
    50  //					Sasl: &msk.ClusterClientAuthenticationSaslArgs{
    51  //						Scram: pulumi.Bool(true),
    52  //					},
    53  //				},
    54  //			})
    55  //			if err != nil {
    56  //				return err
    57  //			}
    58  //			exampleKey, err := kms.NewKey(ctx, "example", &kms.KeyArgs{
    59  //				Description: pulumi.String("Example Key for MSK Cluster Scram Secret Association"),
    60  //			})
    61  //			if err != nil {
    62  //				return err
    63  //			}
    64  //			exampleSecret, err := secretsmanager.NewSecret(ctx, "example", &secretsmanager.SecretArgs{
    65  //				Name:     pulumi.String("AmazonMSK_example"),
    66  //				KmsKeyId: exampleKey.KeyId,
    67  //			})
    68  //			if err != nil {
    69  //				return err
    70  //			}
    71  //			tmpJSON0, err := json.Marshal(map[string]interface{}{
    72  //				"username": "user",
    73  //				"password": "pass",
    74  //			})
    75  //			if err != nil {
    76  //				return err
    77  //			}
    78  //			json0 := string(tmpJSON0)
    79  //			exampleSecretVersion, err := secretsmanager.NewSecretVersion(ctx, "example", &secretsmanager.SecretVersionArgs{
    80  //				SecretId:     exampleSecret.ID(),
    81  //				SecretString: pulumi.String(json0),
    82  //			})
    83  //			if err != nil {
    84  //				return err
    85  //			}
    86  //			_, err = msk.NewScramSecretAssociation(ctx, "example", &msk.ScramSecretAssociationArgs{
    87  //				ClusterArn: exampleCluster.Arn,
    88  //				SecretArnLists: pulumi.StringArray{
    89  //					exampleSecret.Arn,
    90  //				},
    91  //			}, pulumi.DependsOn([]pulumi.Resource{
    92  //				exampleSecretVersion,
    93  //			}))
    94  //			if err != nil {
    95  //				return err
    96  //			}
    97  //			example := iam.GetPolicyDocumentOutput(ctx, iam.GetPolicyDocumentOutputArgs{
    98  //				Statements: iam.GetPolicyDocumentStatementArray{
    99  //					&iam.GetPolicyDocumentStatementArgs{
   100  //						Sid:    pulumi.String("AWSKafkaResourcePolicy"),
   101  //						Effect: pulumi.String("Allow"),
   102  //						Principals: iam.GetPolicyDocumentStatementPrincipalArray{
   103  //							&iam.GetPolicyDocumentStatementPrincipalArgs{
   104  //								Type: pulumi.String("Service"),
   105  //								Identifiers: pulumi.StringArray{
   106  //									pulumi.String("kafka.amazonaws.com"),
   107  //								},
   108  //							},
   109  //						},
   110  //						Actions: pulumi.StringArray{
   111  //							pulumi.String("secretsmanager:getSecretValue"),
   112  //						},
   113  //						Resources: pulumi.StringArray{
   114  //							exampleSecret.Arn,
   115  //						},
   116  //					},
   117  //				},
   118  //			}, nil)
   119  //			_, err = secretsmanager.NewSecretPolicy(ctx, "example", &secretsmanager.SecretPolicyArgs{
   120  //				SecretArn: exampleSecret.Arn,
   121  //				Policy: example.ApplyT(func(example iam.GetPolicyDocumentResult) (*string, error) {
   122  //					return &example.Json, nil
   123  //				}).(pulumi.StringPtrOutput),
   124  //			})
   125  //			if err != nil {
   126  //				return err
   127  //			}
   128  //			return nil
   129  //		})
   130  //	}
   131  //
   132  // ```
   133  // <!--End PulumiCodeChooser -->
   134  //
   135  // ## Import
   136  //
   137  // Using `pulumi import`, import MSK SCRAM Secret Associations using the `id`. For example:
   138  //
   139  // ```sh
   140  // $ pulumi import aws:msk/scramSecretAssociation:ScramSecretAssociation example arn:aws:kafka:us-west-2:123456789012:cluster/example/279c0212-d057-4dba-9aa9-1c4e5a25bfc7-3
   141  // ```
   142  type ScramSecretAssociation struct {
   143  	pulumi.CustomResourceState
   144  
   145  	// Amazon Resource Name (ARN) of the MSK cluster.
   146  	ClusterArn pulumi.StringOutput `pulumi:"clusterArn"`
   147  	// List of AWS Secrets Manager secret ARNs.
   148  	SecretArnLists pulumi.StringArrayOutput `pulumi:"secretArnLists"`
   149  }
   150  
   151  // NewScramSecretAssociation registers a new resource with the given unique name, arguments, and options.
   152  func NewScramSecretAssociation(ctx *pulumi.Context,
   153  	name string, args *ScramSecretAssociationArgs, opts ...pulumi.ResourceOption) (*ScramSecretAssociation, error) {
   154  	if args == nil {
   155  		return nil, errors.New("missing one or more required arguments")
   156  	}
   157  
   158  	if args.ClusterArn == nil {
   159  		return nil, errors.New("invalid value for required argument 'ClusterArn'")
   160  	}
   161  	if args.SecretArnLists == nil {
   162  		return nil, errors.New("invalid value for required argument 'SecretArnLists'")
   163  	}
   164  	opts = internal.PkgResourceDefaultOpts(opts)
   165  	var resource ScramSecretAssociation
   166  	err := ctx.RegisterResource("aws:msk/scramSecretAssociation:ScramSecretAssociation", name, args, &resource, opts...)
   167  	if err != nil {
   168  		return nil, err
   169  	}
   170  	return &resource, nil
   171  }
   172  
   173  // GetScramSecretAssociation gets an existing ScramSecretAssociation resource's state with the given name, ID, and optional
   174  // state properties that are used to uniquely qualify the lookup (nil if not required).
   175  func GetScramSecretAssociation(ctx *pulumi.Context,
   176  	name string, id pulumi.IDInput, state *ScramSecretAssociationState, opts ...pulumi.ResourceOption) (*ScramSecretAssociation, error) {
   177  	var resource ScramSecretAssociation
   178  	err := ctx.ReadResource("aws:msk/scramSecretAssociation:ScramSecretAssociation", name, id, state, &resource, opts...)
   179  	if err != nil {
   180  		return nil, err
   181  	}
   182  	return &resource, nil
   183  }
   184  
   185  // Input properties used for looking up and filtering ScramSecretAssociation resources.
   186  type scramSecretAssociationState struct {
   187  	// Amazon Resource Name (ARN) of the MSK cluster.
   188  	ClusterArn *string `pulumi:"clusterArn"`
   189  	// List of AWS Secrets Manager secret ARNs.
   190  	SecretArnLists []string `pulumi:"secretArnLists"`
   191  }
   192  
   193  type ScramSecretAssociationState struct {
   194  	// Amazon Resource Name (ARN) of the MSK cluster.
   195  	ClusterArn pulumi.StringPtrInput
   196  	// List of AWS Secrets Manager secret ARNs.
   197  	SecretArnLists pulumi.StringArrayInput
   198  }
   199  
   200  func (ScramSecretAssociationState) ElementType() reflect.Type {
   201  	return reflect.TypeOf((*scramSecretAssociationState)(nil)).Elem()
   202  }
   203  
   204  type scramSecretAssociationArgs struct {
   205  	// Amazon Resource Name (ARN) of the MSK cluster.
   206  	ClusterArn string `pulumi:"clusterArn"`
   207  	// List of AWS Secrets Manager secret ARNs.
   208  	SecretArnLists []string `pulumi:"secretArnLists"`
   209  }
   210  
   211  // The set of arguments for constructing a ScramSecretAssociation resource.
   212  type ScramSecretAssociationArgs struct {
   213  	// Amazon Resource Name (ARN) of the MSK cluster.
   214  	ClusterArn pulumi.StringInput
   215  	// List of AWS Secrets Manager secret ARNs.
   216  	SecretArnLists pulumi.StringArrayInput
   217  }
   218  
   219  func (ScramSecretAssociationArgs) ElementType() reflect.Type {
   220  	return reflect.TypeOf((*scramSecretAssociationArgs)(nil)).Elem()
   221  }
   222  
   223  type ScramSecretAssociationInput interface {
   224  	pulumi.Input
   225  
   226  	ToScramSecretAssociationOutput() ScramSecretAssociationOutput
   227  	ToScramSecretAssociationOutputWithContext(ctx context.Context) ScramSecretAssociationOutput
   228  }
   229  
   230  func (*ScramSecretAssociation) ElementType() reflect.Type {
   231  	return reflect.TypeOf((**ScramSecretAssociation)(nil)).Elem()
   232  }
   233  
   234  func (i *ScramSecretAssociation) ToScramSecretAssociationOutput() ScramSecretAssociationOutput {
   235  	return i.ToScramSecretAssociationOutputWithContext(context.Background())
   236  }
   237  
   238  func (i *ScramSecretAssociation) ToScramSecretAssociationOutputWithContext(ctx context.Context) ScramSecretAssociationOutput {
   239  	return pulumi.ToOutputWithContext(ctx, i).(ScramSecretAssociationOutput)
   240  }
   241  
   242  // ScramSecretAssociationArrayInput is an input type that accepts ScramSecretAssociationArray and ScramSecretAssociationArrayOutput values.
   243  // You can construct a concrete instance of `ScramSecretAssociationArrayInput` via:
   244  //
   245  //	ScramSecretAssociationArray{ ScramSecretAssociationArgs{...} }
   246  type ScramSecretAssociationArrayInput interface {
   247  	pulumi.Input
   248  
   249  	ToScramSecretAssociationArrayOutput() ScramSecretAssociationArrayOutput
   250  	ToScramSecretAssociationArrayOutputWithContext(context.Context) ScramSecretAssociationArrayOutput
   251  }
   252  
   253  type ScramSecretAssociationArray []ScramSecretAssociationInput
   254  
   255  func (ScramSecretAssociationArray) ElementType() reflect.Type {
   256  	return reflect.TypeOf((*[]*ScramSecretAssociation)(nil)).Elem()
   257  }
   258  
   259  func (i ScramSecretAssociationArray) ToScramSecretAssociationArrayOutput() ScramSecretAssociationArrayOutput {
   260  	return i.ToScramSecretAssociationArrayOutputWithContext(context.Background())
   261  }
   262  
   263  func (i ScramSecretAssociationArray) ToScramSecretAssociationArrayOutputWithContext(ctx context.Context) ScramSecretAssociationArrayOutput {
   264  	return pulumi.ToOutputWithContext(ctx, i).(ScramSecretAssociationArrayOutput)
   265  }
   266  
   267  // ScramSecretAssociationMapInput is an input type that accepts ScramSecretAssociationMap and ScramSecretAssociationMapOutput values.
   268  // You can construct a concrete instance of `ScramSecretAssociationMapInput` via:
   269  //
   270  //	ScramSecretAssociationMap{ "key": ScramSecretAssociationArgs{...} }
   271  type ScramSecretAssociationMapInput interface {
   272  	pulumi.Input
   273  
   274  	ToScramSecretAssociationMapOutput() ScramSecretAssociationMapOutput
   275  	ToScramSecretAssociationMapOutputWithContext(context.Context) ScramSecretAssociationMapOutput
   276  }
   277  
   278  type ScramSecretAssociationMap map[string]ScramSecretAssociationInput
   279  
   280  func (ScramSecretAssociationMap) ElementType() reflect.Type {
   281  	return reflect.TypeOf((*map[string]*ScramSecretAssociation)(nil)).Elem()
   282  }
   283  
   284  func (i ScramSecretAssociationMap) ToScramSecretAssociationMapOutput() ScramSecretAssociationMapOutput {
   285  	return i.ToScramSecretAssociationMapOutputWithContext(context.Background())
   286  }
   287  
   288  func (i ScramSecretAssociationMap) ToScramSecretAssociationMapOutputWithContext(ctx context.Context) ScramSecretAssociationMapOutput {
   289  	return pulumi.ToOutputWithContext(ctx, i).(ScramSecretAssociationMapOutput)
   290  }
   291  
   292  type ScramSecretAssociationOutput struct{ *pulumi.OutputState }
   293  
   294  func (ScramSecretAssociationOutput) ElementType() reflect.Type {
   295  	return reflect.TypeOf((**ScramSecretAssociation)(nil)).Elem()
   296  }
   297  
   298  func (o ScramSecretAssociationOutput) ToScramSecretAssociationOutput() ScramSecretAssociationOutput {
   299  	return o
   300  }
   301  
   302  func (o ScramSecretAssociationOutput) ToScramSecretAssociationOutputWithContext(ctx context.Context) ScramSecretAssociationOutput {
   303  	return o
   304  }
   305  
   306  // Amazon Resource Name (ARN) of the MSK cluster.
   307  func (o ScramSecretAssociationOutput) ClusterArn() pulumi.StringOutput {
   308  	return o.ApplyT(func(v *ScramSecretAssociation) pulumi.StringOutput { return v.ClusterArn }).(pulumi.StringOutput)
   309  }
   310  
   311  // List of AWS Secrets Manager secret ARNs.
   312  func (o ScramSecretAssociationOutput) SecretArnLists() pulumi.StringArrayOutput {
   313  	return o.ApplyT(func(v *ScramSecretAssociation) pulumi.StringArrayOutput { return v.SecretArnLists }).(pulumi.StringArrayOutput)
   314  }
   315  
   316  type ScramSecretAssociationArrayOutput struct{ *pulumi.OutputState }
   317  
   318  func (ScramSecretAssociationArrayOutput) ElementType() reflect.Type {
   319  	return reflect.TypeOf((*[]*ScramSecretAssociation)(nil)).Elem()
   320  }
   321  
   322  func (o ScramSecretAssociationArrayOutput) ToScramSecretAssociationArrayOutput() ScramSecretAssociationArrayOutput {
   323  	return o
   324  }
   325  
   326  func (o ScramSecretAssociationArrayOutput) ToScramSecretAssociationArrayOutputWithContext(ctx context.Context) ScramSecretAssociationArrayOutput {
   327  	return o
   328  }
   329  
   330  func (o ScramSecretAssociationArrayOutput) Index(i pulumi.IntInput) ScramSecretAssociationOutput {
   331  	return pulumi.All(o, i).ApplyT(func(vs []interface{}) *ScramSecretAssociation {
   332  		return vs[0].([]*ScramSecretAssociation)[vs[1].(int)]
   333  	}).(ScramSecretAssociationOutput)
   334  }
   335  
   336  type ScramSecretAssociationMapOutput struct{ *pulumi.OutputState }
   337  
   338  func (ScramSecretAssociationMapOutput) ElementType() reflect.Type {
   339  	return reflect.TypeOf((*map[string]*ScramSecretAssociation)(nil)).Elem()
   340  }
   341  
   342  func (o ScramSecretAssociationMapOutput) ToScramSecretAssociationMapOutput() ScramSecretAssociationMapOutput {
   343  	return o
   344  }
   345  
   346  func (o ScramSecretAssociationMapOutput) ToScramSecretAssociationMapOutputWithContext(ctx context.Context) ScramSecretAssociationMapOutput {
   347  	return o
   348  }
   349  
   350  func (o ScramSecretAssociationMapOutput) MapIndex(k pulumi.StringInput) ScramSecretAssociationOutput {
   351  	return pulumi.All(o, k).ApplyT(func(vs []interface{}) *ScramSecretAssociation {
   352  		return vs[0].(map[string]*ScramSecretAssociation)[vs[1].(string)]
   353  	}).(ScramSecretAssociationOutput)
   354  }
   355  
   356  func init() {
   357  	pulumi.RegisterInputType(reflect.TypeOf((*ScramSecretAssociationInput)(nil)).Elem(), &ScramSecretAssociation{})
   358  	pulumi.RegisterInputType(reflect.TypeOf((*ScramSecretAssociationArrayInput)(nil)).Elem(), ScramSecretAssociationArray{})
   359  	pulumi.RegisterInputType(reflect.TypeOf((*ScramSecretAssociationMapInput)(nil)).Elem(), ScramSecretAssociationMap{})
   360  	pulumi.RegisterOutputType(ScramSecretAssociationOutput{})
   361  	pulumi.RegisterOutputType(ScramSecretAssociationArrayOutput{})
   362  	pulumi.RegisterOutputType(ScramSecretAssociationMapOutput{})
   363  }