1. Packages
  2. AWS
  3. API Docs
  4. secretsmanager
  5. SecretPolicy
AWS v6.54.0 published on Friday, Sep 27, 2024 by Pulumi

aws.secretsmanager.SecretPolicy

Explore with Pulumi AI

aws logo
AWS v6.54.0 published on Friday, Sep 27, 2024 by Pulumi

    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: [{
            sid: "EnableAnotherAWSAccountToReadTheSecret",
            effect: "Allow",
            principals: [{
                type: "AWS",
                identifiers: ["arn:aws:iam::123456789012:root"],
            }],
            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=[{
        "sid": "EnableAnotherAWSAccountToReadTheSecret",
        "effect": "Allow",
        "principals": [{
            "type": "AWS",
            "identifiers": ["arn:aws:iam::123456789012:root"],
        }],
        "actions": ["secretsmanager:GetSecretValue"],
        "resources": ["*"],
    }])
    example_secret_policy = aws.secretsmanager.SecretPolicy("example",
        secret_arn=example_secret.arn,
        policy=example.json)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam"
    	"github.com/pulumi/pulumi-aws/sdk/v6/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{
    				{
    					Sid:    pulumi.StringRef("EnableAnotherAWSAccountToReadTheSecret"),
    					Effect: pulumi.StringRef("Allow"),
    					Principals: []iam.GetPolicyDocumentStatementPrincipal{
    						{
    							Type: "AWS",
    							Identifiers: []string{
    								"arn:aws:iam::123456789012:root",
    							},
    						},
    					},
    					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
    	})
    }
    
    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
                {
                    Sid = "EnableAnotherAWSAccountToReadTheSecret",
                    Effect = "Allow",
                    Principals = new[]
                    {
                        new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalInputArgs
                        {
                            Type = "AWS",
                            Identifiers = new[]
                            {
                                "arn:aws:iam::123456789012:root",
                            },
                        },
                    },
                    Actions = new[]
                    {
                        "secretsmanager:GetSecretValue",
                    },
                    Resources = new[]
                    {
                        "*",
                    },
                },
            },
        });
    
        var exampleSecretPolicy = new Aws.SecretsManager.SecretPolicy("example", new()
        {
            SecretArn = exampleSecret.Arn,
            Policy = example.Apply(getPolicyDocumentResult => getPolicyDocumentResult.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.secretsmanager.SecretPolicy;
    import com.pulumi.aws.secretsmanager.SecretPolicyArgs;
    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) {
            var exampleSecret = new Secret("exampleSecret", SecretArgs.builder()
                .name("example")
                .build());
    
            final var example = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
                .statements(GetPolicyDocumentStatementArgs.builder()
                    .sid("EnableAnotherAWSAccountToReadTheSecret")
                    .effect("Allow")
                    .principals(GetPolicyDocumentStatementPrincipalArgs.builder()
                        .type("AWS")
                        .identifiers("arn:aws:iam::123456789012:root")
                        .build())
                    .actions("secretsmanager:GetSecretValue")
                    .resources("*")
                    .build())
                .build());
    
            var exampleSecretPolicy = new SecretPolicy("exampleSecretPolicy", SecretPolicyArgs.builder()
                .secretArn(exampleSecret.arn())
                .policy(example.applyValue(getPolicyDocumentResult -> getPolicyDocumentResult.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:
              - sid: EnableAnotherAWSAccountToReadTheSecret
                effect: Allow
                principals:
                  - type: AWS
                    identifiers:
                      - arn:aws:iam::123456789012:root
                actions:
                  - secretsmanager:GetSecretValue
                resources:
                  - '*'
    

    Create SecretPolicy Resource

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

    Constructor syntax

    new SecretPolicy(name: string, args: SecretPolicyArgs, opts?: CustomResourceOptions);
    @overload
    def SecretPolicy(resource_name: str,
                     args: SecretPolicyArgs,
                     opts: Optional[ResourceOptions] = None)
    
    @overload
    def SecretPolicy(resource_name: str,
                     opts: Optional[ResourceOptions] = None,
                     policy: Optional[str] = None,
                     secret_arn: Optional[str] = None,
                     block_public_policy: Optional[bool] = None)
    func NewSecretPolicy(ctx *Context, name string, args SecretPolicyArgs, opts ...ResourceOption) (*SecretPolicy, error)
    public SecretPolicy(string name, SecretPolicyArgs args, CustomResourceOptions? opts = null)
    public SecretPolicy(String name, SecretPolicyArgs args)
    public SecretPolicy(String name, SecretPolicyArgs args, CustomResourceOptions options)
    
    type: aws:secretsmanager:SecretPolicy
    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 SecretPolicyArgs
    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 SecretPolicyArgs
    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 SecretPolicyArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args SecretPolicyArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args SecretPolicyArgs
    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 secretPolicyResource = new Aws.SecretsManager.SecretPolicy("secretPolicyResource", new()
    {
        Policy = "string",
        SecretArn = "string",
        BlockPublicPolicy = false,
    });
    
    example, err := secretsmanager.NewSecretPolicy(ctx, "secretPolicyResource", &secretsmanager.SecretPolicyArgs{
    	Policy:            pulumi.String("string"),
    	SecretArn:         pulumi.String("string"),
    	BlockPublicPolicy: pulumi.Bool(false),
    })
    
    var secretPolicyResource = new SecretPolicy("secretPolicyResource", SecretPolicyArgs.builder()
        .policy("string")
        .secretArn("string")
        .blockPublicPolicy(false)
        .build());
    
    secret_policy_resource = aws.secretsmanager.SecretPolicy("secretPolicyResource",
        policy="string",
        secret_arn="string",
        block_public_policy=False)
    
    const secretPolicyResource = new aws.secretsmanager.SecretPolicy("secretPolicyResource", {
        policy: "string",
        secretArn: "string",
        blockPublicPolicy: false,
    });
    
    type: aws:secretsmanager:SecretPolicy
    properties:
        blockPublicPolicy: false
        policy: string
        secretArn: string
    

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

    Policy 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.
    SecretArn string

    Secret ARN.

    The following arguments are optional:

    BlockPublicPolicy bool
    Makes an optional API call to Zelkova to validate the Resource Policy to prevent broad access to your secret.
    Policy 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.
    SecretArn string

    Secret ARN.

    The following arguments are optional:

    BlockPublicPolicy bool
    Makes an optional API call to Zelkova to validate the Resource Policy to prevent broad access to your secret.
    policy 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.
    secretArn String

    Secret ARN.

    The following arguments are optional:

    blockPublicPolicy Boolean
    Makes an optional API call to Zelkova to validate the Resource Policy to prevent broad access to your secret.
    policy 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.
    secretArn string

    Secret ARN.

    The following arguments are optional:

    blockPublicPolicy boolean
    Makes an optional API call to Zelkova to validate the Resource Policy to prevent broad access to your secret.
    policy str
    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.
    secret_arn str

    Secret ARN.

    The following arguments are optional:

    block_public_policy bool
    Makes an optional API call to Zelkova to validate the Resource Policy to prevent broad access to your secret.
    policy 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.
    secretArn String

    Secret ARN.

    The following arguments are optional:

    blockPublicPolicy Boolean
    Makes an optional API call to Zelkova to validate the Resource Policy to prevent broad access to your secret.

    Outputs

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

    Id string
    The provider-assigned unique ID for this managed resource.
    Id string
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.
    id string
    The provider-assigned unique ID for this managed resource.
    id str
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.

    Look up Existing SecretPolicy Resource

    Get an existing SecretPolicy 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?: SecretPolicyState, opts?: CustomResourceOptions): SecretPolicy
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            block_public_policy: Optional[bool] = None,
            policy: Optional[str] = None,
            secret_arn: Optional[str] = None) -> SecretPolicy
    func GetSecretPolicy(ctx *Context, name string, id IDInput, state *SecretPolicyState, opts ...ResourceOption) (*SecretPolicy, error)
    public static SecretPolicy Get(string name, Input<string> id, SecretPolicyState? state, CustomResourceOptions? opts = null)
    public static SecretPolicy get(String name, Output<String> id, SecretPolicyState 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:
    BlockPublicPolicy bool
    Makes an optional API call to Zelkova to validate the Resource Policy to prevent broad access to your secret.
    Policy 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.
    SecretArn string

    Secret ARN.

    The following arguments are optional:

    BlockPublicPolicy bool
    Makes an optional API call to Zelkova to validate the Resource Policy to prevent broad access to your secret.
    Policy 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.
    SecretArn string

    Secret ARN.

    The following arguments are optional:

    blockPublicPolicy Boolean
    Makes an optional API call to Zelkova to validate the Resource Policy to prevent broad access to your secret.
    policy 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.
    secretArn String

    Secret ARN.

    The following arguments are optional:

    blockPublicPolicy boolean
    Makes an optional API call to Zelkova to validate the Resource Policy to prevent broad access to your secret.
    policy 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.
    secretArn string

    Secret ARN.

    The following arguments are optional:

    block_public_policy bool
    Makes an optional API call to Zelkova to validate the Resource Policy to prevent broad access to your secret.
    policy str
    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.
    secret_arn str

    Secret ARN.

    The following arguments are optional:

    blockPublicPolicy Boolean
    Makes an optional API call to Zelkova to validate the Resource Policy to prevent broad access to your secret.
    policy 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.
    secretArn String

    Secret ARN.

    The following arguments are optional:

    Import

    Using pulumi import, import aws_secretsmanager_secret_policy using the secret Amazon Resource Name (ARN). For example:

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

    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.54.0 published on Friday, Sep 27, 2024 by Pulumi