SecretPolicy class

Provides a resource to manage AWS Secrets Manager secret policy.

Example Usage

Basic

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const exampleSecret = new aws.secretsmanager.Secret("example", {name: "example"});
const example = aws.iam.getPolicyDocument({
    statements: [{
        principals: [{
            type: "AWS",
            identifiers: ["arn:aws:iam::123456789012:root"],
        }],
        sid: "EnableAnotherAWSAccountToReadTheSecret",
        effect: "Allow",
        actions: ["secretsmanager:GetSecretValue"],
        resources: ["*"],
    }],
});
const exampleSecretPolicy = new aws.secretsmanager.SecretPolicy("example", {
    secretArn: exampleSecret.arn,
    policy: example.then(example => example.json),
});
import pulumi
import pulumi_aws as aws

example_secret = aws.secretsmanager.Secret("example", name="example")
example = aws.iam.get_policy_document(statements=[{
    "principals": [{
        "type": "AWS",
        "identifiers": ["arn:aws:iam::123456789012:root"],
    }],
    "sid": "EnableAnotherAWSAccountToReadTheSecret",
    "effect": "Allow",
    "actions": ["secretsmanager:GetSecretValue"],
    "resources": ["*"],
}])
example_secret_policy = aws.secretsmanager.SecretPolicy("example",
    secret_arn=example_secret.arn,
    policy=example.json)
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() =>
{
    var exampleSecret = new Aws.SecretsManager.Secret("example", new()
    {
        Name = "example",
    });

    var example = Aws.Iam.GetPolicyDocument.Invoke(new()
    {
        Statements = new[]
        {
            new Aws.Iam.Inputs.GetPolicyDocumentStatementInputArgs
            {
                Principals = new[]
                {
                    new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalInputArgs
                    {
                        Type = "AWS",
                        Identifiers = new[]
                        {
                            "arn:aws:iam::123456789012:root",
                        },
                    },
                },
                Sid = "EnableAnotherAWSAccountToReadTheSecret",
                Effect = "Allow",
                Actions = new[]
                {
                    "secretsmanager:GetSecretValue",
                },
                Resources = new[]
                {
                    "*",
                },
            },
        },
    });

    var exampleSecretPolicy = new Aws.SecretsManager.SecretPolicy("example", new()
    {
        SecretArn = exampleSecret.Arn,
        Policy = example.Apply(getPolicyDocumentResult => getPolicyDocumentResult.Json),
    });

});
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/iam"
	"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 {
		exampleSecret, err := secretsmanager.NewSecret(ctx, "example", &secretsmanager.SecretArgs{
			Name: pulumi.String("example"),
		})
		if err != nil {
			return err
		}
		example, err := iam.GetPolicyDocument(ctx, &iam.GetPolicyDocumentArgs{
			Statements: []iam.GetPolicyDocumentStatement{
				{
					Principals: []iam.GetPolicyDocumentStatementPrincipal{
						{
							Type: "AWS",
							Identifiers: []string{
								"arn:aws:iam::123456789012:root",
							},
						},
					},
					Sid:    pulumi.StringRef("EnableAnotherAWSAccountToReadTheSecret"),
					Effect: pulumi.StringRef("Allow"),
					Actions: []string{
						"secretsmanager:GetSecretValue",
					},
					Resources: []string{
						"*",
					},
				},
			},
		}, nil)
		if err != nil {
			return err
		}
		_, err = secretsmanager.NewSecretPolicy(ctx, "example", &secretsmanager.SecretPolicyArgs{
			SecretArn: exampleSecret.Arn,
			Policy:    pulumi.String(example.Json),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    aws = {
      source = "pulumi/aws"
    }
  }
}

data "aws_iam_getpolicydocument" "example" {
  statements {
    principals {
      type        = "AWS"
      identifiers = ["arn:aws:iam::123456789012:root"]
    }
    sid       = "EnableAnotherAWSAccountToReadTheSecret"
    effect    = "Allow"
    actions   = ["secretsmanager:GetSecretValue"]
    resources = ["*"]
  }
}

resource "aws_secretsmanager_secret" "example" {
  name = "example"
}
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.secretsmanager.Secret;
import com.pulumi.aws.secretsmanager.SecretArgs;
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 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 exampleSecret = new Secret("exampleSecret", SecretArgs.builder()
            .name("example")
            .build());

        final var example = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
            .statements(GetPolicyDocumentStatementArgs.builder()
                .principals(GetPolicyDocumentStatementPrincipalArgs.builder()
                    .type("AWS")
                    .identifiers("arn:aws:iam::123456789012:root")
                    .build())
                .sid("EnableAnotherAWSAccountToReadTheSecret")
                .effect("Allow")
                .actions("secretsmanager:GetSecretValue")
                .resources("*")
                .build())
            .build());

        var exampleSecretPolicy = new SecretPolicy("exampleSecretPolicy", SecretPolicyArgs.builder()
            .secretArn(exampleSecret.arn())
            .policy(example.json())
            .build());

    }
}
resources:
  exampleSecret:
    type: aws:secretsmanager:Secret
    name: example
    properties:
      name: example
  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: AWS
                identifiers:
                  - arn:aws:iam::123456789012:root
            sid: EnableAnotherAWSAccountToReadTheSecret
            effect: Allow
            actions:
              - secretsmanager:GetSecretValue
            resources:
              - '*'

Import

Identity Schema

Required

  • secretArn (String) ARN of the Secrets Manager secret.

Using pulumi import, import aws.secretsmanager.SecretPolicy using the secret ARN. For example:

$ pulumi import aws:secretsmanager/secretPolicy:SecretPolicy example arn:aws:secretsmanager:us-east-1:123456789012:secret:example-123456

Constructors

SecretPolicy(String name, {SecretPolicyArgs? args, CustomResourceOptions? options})
Creates a new SecretPolicy. name The Pulumi resource name. args Arguments used to configure this SecretPolicy. The set of arguments for SecretPolicy. options Resource options controlling this resource's behavior.
SecretPolicy.reference(String urn)
Creates a typed reference to an existing SecretPolicy resource.

Properties

blockPublicPolicy ↔ Output<bool?>
Makes an optional API call to Zelkova to validate the Resource Policy to prevent broad access to your secret.
latefinal
childResources → Set<Resource>
finalinherited
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
policy ↔ Output<String>
Valid JSON document representing a resource policy. Unlike aws.secretsmanager.Secret, where policy can be set to "{}" to delete the policy, "{}" is not a valid policy since policy is required.
latefinal
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
secretArn ↔ Output<String>
Secret ARN.
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, {SecretPolicyState? state, CustomResourceOptions? options}) → SecretPolicy
Gets an existing SecretPolicy resource's state with the given name and id.