1. Packages
  2. AWS
  3. API Docs
  4. backup
  5. VaultPolicy
AWS v6.77.0 published on Wednesday, Apr 9, 2025 by Pulumi

aws.backup.VaultPolicy

Explore with Pulumi AI

Provides an AWS Backup vault policy resource.

Example Usage

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

const current = aws.getCallerIdentity({});
const exampleVault = new aws.backup.Vault("example", {name: "example"});
const example = pulumi.all([current, exampleVault.arn]).apply(([current, arn]) => aws.iam.getPolicyDocumentOutput({
    statements: [{
        effect: "Allow",
        principals: [{
            type: "AWS",
            identifiers: [current.accountId],
        }],
        actions: [
            "backup:DescribeBackupVault",
            "backup:DeleteBackupVault",
            "backup:PutBackupVaultAccessPolicy",
            "backup:DeleteBackupVaultAccessPolicy",
            "backup:GetBackupVaultAccessPolicy",
            "backup:StartBackupJob",
            "backup:GetBackupVaultNotifications",
            "backup:PutBackupVaultNotifications",
        ],
        resources: [arn],
    }],
}));
const exampleVaultPolicy = new aws.backup.VaultPolicy("example", {
    backupVaultName: exampleVault.name,
    policy: example.apply(example => example.json),
});
Copy
import pulumi
import pulumi_aws as aws

current = aws.get_caller_identity()
example_vault = aws.backup.Vault("example", name="example")
example = example_vault.arn.apply(lambda arn: aws.iam.get_policy_document_output(statements=[{
    "effect": "Allow",
    "principals": [{
        "type": "AWS",
        "identifiers": [current.account_id],
    }],
    "actions": [
        "backup:DescribeBackupVault",
        "backup:DeleteBackupVault",
        "backup:PutBackupVaultAccessPolicy",
        "backup:DeleteBackupVaultAccessPolicy",
        "backup:GetBackupVaultAccessPolicy",
        "backup:StartBackupJob",
        "backup:GetBackupVaultNotifications",
        "backup:PutBackupVaultNotifications",
    ],
    "resources": [arn],
}]))
example_vault_policy = aws.backup.VaultPolicy("example",
    backup_vault_name=example_vault.name,
    policy=example.json)
Copy
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws"
	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/backup"
	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
current, err := aws.GetCallerIdentity(ctx, &aws.GetCallerIdentityArgs{
}, nil);
if err != nil {
return err
}
exampleVault, err := backup.NewVault(ctx, "example", &backup.VaultArgs{
Name: pulumi.String("example"),
})
if err != nil {
return err
}
example := exampleVault.Arn.ApplyT(func(arn string) (iam.GetPolicyDocumentResult, error) {
return iam.GetPolicyDocumentResult(interface{}(iam.GetPolicyDocumentOutput(ctx, iam.GetPolicyDocumentOutputArgs{
Statements: []iam.GetPolicyDocumentStatement{
{
Effect: "Allow",
Principals: []iam.GetPolicyDocumentStatementPrincipal{
{
Type: "AWS",
Identifiers: interface{}{
current.AccountId,
},
},
},
Actions: []string{
"backup:DescribeBackupVault",
"backup:DeleteBackupVault",
"backup:PutBackupVaultAccessPolicy",
"backup:DeleteBackupVaultAccessPolicy",
"backup:GetBackupVaultAccessPolicy",
"backup:StartBackupJob",
"backup:GetBackupVaultNotifications",
"backup:PutBackupVaultNotifications",
},
Resources: []string{
arn,
},
},
},
}, nil))), nil
}).(iam.GetPolicyDocumentResultOutput)
_, err = backup.NewVaultPolicy(ctx, "example", &backup.VaultPolicyArgs{
BackupVaultName: exampleVault.Name,
Policy: pulumi.String(example.ApplyT(func(example iam.GetPolicyDocumentResult) (*string, error) {
return &example.Json, nil
}).(pulumi.StringPtrOutput)),
})
if err != nil {
return err
}
return nil
})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() => 
{
    var current = Aws.GetCallerIdentity.Invoke();

    var exampleVault = new Aws.Backup.Vault("example", new()
    {
        Name = "example",
    });

    var example = Aws.Iam.GetPolicyDocument.Invoke(new()
    {
        Statements = new[]
        {
            new Aws.Iam.Inputs.GetPolicyDocumentStatementInputArgs
            {
                Effect = "Allow",
                Principals = new[]
                {
                    new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalInputArgs
                    {
                        Type = "AWS",
                        Identifiers = new[]
                        {
                            current.Apply(getCallerIdentityResult => getCallerIdentityResult.AccountId),
                        },
                    },
                },
                Actions = new[]
                {
                    "backup:DescribeBackupVault",
                    "backup:DeleteBackupVault",
                    "backup:PutBackupVaultAccessPolicy",
                    "backup:DeleteBackupVaultAccessPolicy",
                    "backup:GetBackupVaultAccessPolicy",
                    "backup:StartBackupJob",
                    "backup:GetBackupVaultNotifications",
                    "backup:PutBackupVaultNotifications",
                },
                Resources = new[]
                {
                    exampleVault.Arn,
                },
            },
        },
    });

    var exampleVaultPolicy = new Aws.Backup.VaultPolicy("example", new()
    {
        BackupVaultName = exampleVault.Name,
        Policy = example.Apply(getPolicyDocumentResult => getPolicyDocumentResult.Json),
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.AwsFunctions;
import com.pulumi.aws.inputs.GetCallerIdentityArgs;
import com.pulumi.aws.backup.Vault;
import com.pulumi.aws.backup.VaultArgs;
import com.pulumi.aws.iam.IamFunctions;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentArgs;
import com.pulumi.aws.backup.VaultPolicy;
import com.pulumi.aws.backup.VaultPolicyArgs;
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) {
        final var current = AwsFunctions.getCallerIdentity(GetCallerIdentityArgs.builder()
            .build());

        var exampleVault = new Vault("exampleVault", VaultArgs.builder()
            .name("example")
            .build());

        final var example = exampleVault.arn().applyValue(_arn -> IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
            .statements(GetPolicyDocumentStatementArgs.builder()
                .effect("Allow")
                .principals(GetPolicyDocumentStatementPrincipalArgs.builder()
                    .type("AWS")
                    .identifiers(current.accountId())
                    .build())
                .actions(                
                    "backup:DescribeBackupVault",
                    "backup:DeleteBackupVault",
                    "backup:PutBackupVaultAccessPolicy",
                    "backup:DeleteBackupVaultAccessPolicy",
                    "backup:GetBackupVaultAccessPolicy",
                    "backup:StartBackupJob",
                    "backup:GetBackupVaultNotifications",
                    "backup:PutBackupVaultNotifications")
                .resources(_arn)
                .build())
            .build()));

        var exampleVaultPolicy = new VaultPolicy("exampleVaultPolicy", VaultPolicyArgs.builder()
            .backupVaultName(exampleVault.name())
            .policy(example.applyValue(_example -> _example.json()))
            .build());

    }
}
Copy
resources:
  exampleVault:
    type: aws:backup:Vault
    name: example
    properties:
      name: example
  exampleVaultPolicy:
    type: aws:backup:VaultPolicy
    name: example
    properties:
      backupVaultName: ${exampleVault.name}
      policy: ${example.json}
variables:
  current:
    fn::invoke:
      function: aws:getCallerIdentity
      arguments: {}
  example:
    fn::invoke:
      function: aws:iam:getPolicyDocument
      arguments:
        statements:
          - effect: Allow
            principals:
              - type: AWS
                identifiers:
                  - ${current.accountId}
            actions:
              - backup:DescribeBackupVault
              - backup:DeleteBackupVault
              - backup:PutBackupVaultAccessPolicy
              - backup:DeleteBackupVaultAccessPolicy
              - backup:GetBackupVaultAccessPolicy
              - backup:StartBackupJob
              - backup:GetBackupVaultNotifications
              - backup:PutBackupVaultNotifications
            resources:
              - ${exampleVault.arn}
Copy

Create VaultPolicy Resource

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

Constructor syntax

new VaultPolicy(name: string, args: VaultPolicyArgs, opts?: CustomResourceOptions);
@overload
def VaultPolicy(resource_name: str,
                args: VaultPolicyArgs,
                opts: Optional[ResourceOptions] = None)

@overload
def VaultPolicy(resource_name: str,
                opts: Optional[ResourceOptions] = None,
                backup_vault_name: Optional[str] = None,
                policy: Optional[str] = None)
func NewVaultPolicy(ctx *Context, name string, args VaultPolicyArgs, opts ...ResourceOption) (*VaultPolicy, error)
public VaultPolicy(string name, VaultPolicyArgs args, CustomResourceOptions? opts = null)
public VaultPolicy(String name, VaultPolicyArgs args)
public VaultPolicy(String name, VaultPolicyArgs args, CustomResourceOptions options)
type: aws:backup:VaultPolicy
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. VaultPolicyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. VaultPolicyArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. VaultPolicyArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. VaultPolicyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. VaultPolicyArgs
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 vaultPolicyResource = new Aws.Backup.VaultPolicy("vaultPolicyResource", new()
{
    BackupVaultName = "string",
    Policy = "string",
});
Copy
example, err := backup.NewVaultPolicy(ctx, "vaultPolicyResource", &backup.VaultPolicyArgs{
	BackupVaultName: pulumi.String("string"),
	Policy:          pulumi.String("string"),
})
Copy
var vaultPolicyResource = new VaultPolicy("vaultPolicyResource", VaultPolicyArgs.builder()
    .backupVaultName("string")
    .policy("string")
    .build());
Copy
vault_policy_resource = aws.backup.VaultPolicy("vaultPolicyResource",
    backup_vault_name="string",
    policy="string")
Copy
const vaultPolicyResource = new aws.backup.VaultPolicy("vaultPolicyResource", {
    backupVaultName: "string",
    policy: "string",
});
Copy
type: aws:backup:VaultPolicy
properties:
    backupVaultName: string
    policy: string
Copy

VaultPolicy Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

The VaultPolicy resource accepts the following input properties:

BackupVaultName
This property is required.
Changes to this property will trigger replacement.
string
Name of the backup vault to add policy for.
Policy This property is required. string
The backup vault access policy document in JSON format.
BackupVaultName
This property is required.
Changes to this property will trigger replacement.
string
Name of the backup vault to add policy for.
Policy This property is required. string
The backup vault access policy document in JSON format.
backupVaultName
This property is required.
Changes to this property will trigger replacement.
String
Name of the backup vault to add policy for.
policy This property is required. String
The backup vault access policy document in JSON format.
backupVaultName
This property is required.
Changes to this property will trigger replacement.
string
Name of the backup vault to add policy for.
policy This property is required. string
The backup vault access policy document in JSON format.
backup_vault_name
This property is required.
Changes to this property will trigger replacement.
str
Name of the backup vault to add policy for.
policy This property is required. str
The backup vault access policy document in JSON format.
backupVaultName
This property is required.
Changes to this property will trigger replacement.
String
Name of the backup vault to add policy for.
policy This property is required. String
The backup vault access policy document in JSON format.

Outputs

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

BackupVaultArn string
The ARN of the vault.
Id string
The provider-assigned unique ID for this managed resource.
BackupVaultArn string
The ARN of the vault.
Id string
The provider-assigned unique ID for this managed resource.
backupVaultArn String
The ARN of the vault.
id String
The provider-assigned unique ID for this managed resource.
backupVaultArn string
The ARN of the vault.
id string
The provider-assigned unique ID for this managed resource.
backup_vault_arn str
The ARN of the vault.
id str
The provider-assigned unique ID for this managed resource.
backupVaultArn String
The ARN of the vault.
id String
The provider-assigned unique ID for this managed resource.

Look up Existing VaultPolicy Resource

Get an existing VaultPolicy 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?: VaultPolicyState, opts?: CustomResourceOptions): VaultPolicy
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        backup_vault_arn: Optional[str] = None,
        backup_vault_name: Optional[str] = None,
        policy: Optional[str] = None) -> VaultPolicy
func GetVaultPolicy(ctx *Context, name string, id IDInput, state *VaultPolicyState, opts ...ResourceOption) (*VaultPolicy, error)
public static VaultPolicy Get(string name, Input<string> id, VaultPolicyState? state, CustomResourceOptions? opts = null)
public static VaultPolicy get(String name, Output<String> id, VaultPolicyState state, CustomResourceOptions options)
resources:  _:    type: aws:backup:VaultPolicy    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
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:
BackupVaultArn string
The ARN of the vault.
BackupVaultName Changes to this property will trigger replacement. string
Name of the backup vault to add policy for.
Policy string
The backup vault access policy document in JSON format.
BackupVaultArn string
The ARN of the vault.
BackupVaultName Changes to this property will trigger replacement. string
Name of the backup vault to add policy for.
Policy string
The backup vault access policy document in JSON format.
backupVaultArn String
The ARN of the vault.
backupVaultName Changes to this property will trigger replacement. String
Name of the backup vault to add policy for.
policy String
The backup vault access policy document in JSON format.
backupVaultArn string
The ARN of the vault.
backupVaultName Changes to this property will trigger replacement. string
Name of the backup vault to add policy for.
policy string
The backup vault access policy document in JSON format.
backup_vault_arn str
The ARN of the vault.
backup_vault_name Changes to this property will trigger replacement. str
Name of the backup vault to add policy for.
policy str
The backup vault access policy document in JSON format.
backupVaultArn String
The ARN of the vault.
backupVaultName Changes to this property will trigger replacement. String
Name of the backup vault to add policy for.
policy String
The backup vault access policy document in JSON format.

Import

Using pulumi import, import Backup vault policy using the name. For example:

$ pulumi import aws:backup/vaultPolicy:VaultPolicy test TestVault
Copy

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.