AWS Classic

Pulumi Official
Package maintained by Pulumi
v5.10.0 published on Monday, Jul 11, 2022 by Pulumi

SecretPolicy

Provides a resource to manage AWS Secrets Manager secret policy.

Example Usage

Basic

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var exampleSecret = new Aws.SecretsManager.Secret("exampleSecret", new Aws.SecretsManager.SecretArgs
        {
        });
        var exampleSecretPolicy = new Aws.SecretsManager.SecretPolicy("exampleSecretPolicy", new Aws.SecretsManager.SecretPolicyArgs
        {
            SecretArn = exampleSecret.Arn,
            Policy = @"{
  ""Version"": ""2012-10-17"",
  ""Statement"": [
	{
	  ""Sid"": ""EnableAnotherAWSAccountToReadTheSecret"",
	  ""Effect"": ""Allow"",
	  ""Principal"": {
		""AWS"": ""arn:aws:iam::123456789012:root""
	  },
	  ""Action"": ""secretsmanager:GetSecretValue"",
	  ""Resource"": ""*""
	}
  ]
}
",
        });
    }

}
package main

import (
	"fmt"

	"github.com/pulumi/pulumi-aws/sdk/v5/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, "exampleSecret", nil)
		if err != nil {
			return err
		}
		_, err = secretsmanager.NewSecretPolicy(ctx, "exampleSecretPolicy", &secretsmanager.SecretPolicyArgs{
			SecretArn: exampleSecret.Arn,
			Policy: pulumi.String(fmt.Sprintf("%v%v%v%v%v%v%v%v%v%v%v%v%v%v", "{\n", "  \"Version\": \"2012-10-17\",\n", "  \"Statement\": [\n", "	{\n", "	  \"Sid\": \"EnableAnotherAWSAccountToReadTheSecret\",\n", "	  \"Effect\": \"Allow\",\n", "	  \"Principal\": {\n", "		\"AWS\": \"arn:aws:iam::123456789012:root\"\n", "	  },\n", "	  \"Action\": \"secretsmanager:GetSecretValue\",\n", "	  \"Resource\": \"*\"\n", "	}\n", "  ]\n", "}\n")),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
package generated_program;

import java.util.*;
import java.io.*;
import java.nio.*;
import com.pulumi.*;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var exampleSecret = new Secret("exampleSecret");

        var exampleSecretPolicy = new SecretPolicy("exampleSecretPolicy", SecretPolicyArgs.builder()        
            .secretArn(exampleSecret.arn())
            .policy("""
{
  "Version": "2012-10-17",
  "Statement": [
	{
	  "Sid": "EnableAnotherAWSAccountToReadTheSecret",
	  "Effect": "Allow",
	  "Principal": {
		"AWS": "arn:aws:iam::123456789012:root"
	  },
	  "Action": "secretsmanager:GetSecretValue",
	  "Resource": "*"
	}
  ]
}
            """)
            .build());

    }
}
import pulumi
import pulumi_aws as aws

example_secret = aws.secretsmanager.Secret("exampleSecret")
example_secret_policy = aws.secretsmanager.SecretPolicy("exampleSecretPolicy",
    secret_arn=example_secret.arn,
    policy="""{
  "Version": "2012-10-17",
  "Statement": [
	{
	  "Sid": "EnableAnotherAWSAccountToReadTheSecret",
	  "Effect": "Allow",
	  "Principal": {
		"AWS": "arn:aws:iam::123456789012:root"
	  },
	  "Action": "secretsmanager:GetSecretValue",
	  "Resource": "*"
	}
  ]
}
""")
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const exampleSecret = new aws.secretsmanager.Secret("exampleSecret", {});
const exampleSecretPolicy = new aws.secretsmanager.SecretPolicy("exampleSecretPolicy", {
    secretArn: exampleSecret.arn,
    policy: `{
  "Version": "2012-10-17",
  "Statement": [
	{
	  "Sid": "EnableAnotherAWSAccountToReadTheSecret",
	  "Effect": "Allow",
	  "Principal": {
		"AWS": "arn:aws:iam::123456789012:root"
	  },
	  "Action": "secretsmanager:GetSecretValue",
	  "Resource": "*"
	}
  ]
}
`,
});
resources:
  exampleSecret:
    type: aws:secretsmanager:Secret
  exampleSecretPolicy:
    type: aws:secretsmanager:SecretPolicy
    properties:
      secretArn: ${exampleSecret.arn}
      policy: |
        {
          "Version": "2012-10-17",
          "Statement": [
        	{
        	  "Sid": "EnableAnotherAWSAccountToReadTheSecret",
        	  "Effect": "Allow",
        	  "Principal": {
        		"AWS": "arn:aws:iam::123456789012:root"
        	  },
        	  "Action": "secretsmanager:GetSecretValue",
        	  "Resource": "*"
        	}
          ]
        }        

Create a SecretPolicy Resource

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

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.

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.

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.

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.

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.

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.

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.

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 an 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.

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.

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.

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.

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.

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.

Import

aws_secretsmanager_secret_policy can be imported by using the secret Amazon Resource Name (ARN), e.g.,

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

Package Details

Repository
https://github.com/pulumi/pulumi-aws
License
Apache-2.0
Notes

This Pulumi package is based on the aws Terraform Provider.