1. Packages
  2. Digitalocean Provider
  3. API Docs
  4. SpacesBucketPolicy
DigitalOcean v4.36.0 published on Wednesday, Dec 4, 2024 by Pulumi

digitalocean.SpacesBucketPolicy

Explore with Pulumi AI

digitalocean logo
DigitalOcean v4.36.0 published on Wednesday, Dec 4, 2024 by Pulumi

    Example Usage

    Limiting access to specific IP addresses

    import * as pulumi from "@pulumi/pulumi";
    import * as digitalocean from "@pulumi/digitalocean";
    
    const foobar = new digitalocean.SpacesBucket("foobar", {
        name: "foobar",
        region: digitalocean.Region.NYC3,
    });
    const foobarSpacesBucketPolicy = new digitalocean.SpacesBucketPolicy("foobar", {
        region: foobar.region,
        bucket: foobar.name,
        policy: pulumi.jsonStringify({
            Version: "2012-10-17",
            Statement: [{
                Sid: "IPAllow",
                Effect: "Deny",
                Principal: "*",
                Action: "s3:*",
                Resource: [
                    pulumi.interpolate`arn:aws:s3:::${foobar.name}`,
                    pulumi.interpolate`arn:aws:s3:::${foobar.name}/*`,
                ],
                Condition: {
                    NotIpAddress: {
                        "aws:SourceIp": "54.240.143.0/24",
                    },
                },
            }],
        }),
    });
    
    import pulumi
    import json
    import pulumi_digitalocean as digitalocean
    
    foobar = digitalocean.SpacesBucket("foobar",
        name="foobar",
        region=digitalocean.Region.NYC3)
    foobar_spaces_bucket_policy = digitalocean.SpacesBucketPolicy("foobar",
        region=foobar.region,
        bucket=foobar.name,
        policy=pulumi.Output.json_dumps({
            "Version": "2012-10-17",
            "Statement": [{
                "Sid": "IPAllow",
                "Effect": "Deny",
                "Principal": "*",
                "Action": "s3:*",
                "Resource": [
                    foobar.name.apply(lambda name: f"arn:aws:s3:::{name}"),
                    foobar.name.apply(lambda name: f"arn:aws:s3:::{name}/*"),
                ],
                "Condition": {
                    "NotIpAddress": {
                        "aws:SourceIp": "54.240.143.0/24",
                    },
                },
            }],
        }))
    
    package main
    
    import (
    	"encoding/json"
    	"fmt"
    
    	"github.com/pulumi/pulumi-digitalocean/sdk/v4/go/digitalocean"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		foobar, err := digitalocean.NewSpacesBucket(ctx, "foobar", &digitalocean.SpacesBucketArgs{
    			Name:   pulumi.String("foobar"),
    			Region: pulumi.String(digitalocean.RegionNYC3),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = digitalocean.NewSpacesBucketPolicy(ctx, "foobar", &digitalocean.SpacesBucketPolicyArgs{
    			Region: foobar.Region,
    			Bucket: foobar.Name,
    			Policy: pulumi.All(foobar.Name, foobar.Name).ApplyT(func(_args []interface{}) (string, error) {
    				foobarName := _args[0].(string)
    				foobarName1 := _args[1].(string)
    				var _zero string
    				tmpJSON0, err := json.Marshal(map[string]interface{}{
    					"Version": "2012-10-17",
    					"Statement": []map[string]interface{}{
    						map[string]interface{}{
    							"Sid":       "IPAllow",
    							"Effect":    "Deny",
    							"Principal": "*",
    							"Action":    "s3:*",
    							"Resource": []string{
    								fmt.Sprintf("arn:aws:s3:::%v", foobarName),
    								fmt.Sprintf("arn:aws:s3:::%v/*", foobarName1),
    							},
    							"Condition": map[string]interface{}{
    								"NotIpAddress": map[string]interface{}{
    									"aws:SourceIp": "54.240.143.0/24",
    								},
    							},
    						},
    					},
    				})
    				if err != nil {
    					return _zero, err
    				}
    				json0 := string(tmpJSON0)
    				return json0, nil
    			}).(pulumi.StringOutput),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using System.Text.Json;
    using Pulumi;
    using DigitalOcean = Pulumi.DigitalOcean;
    
    return await Deployment.RunAsync(() => 
    {
        var foobar = new DigitalOcean.SpacesBucket("foobar", new()
        {
            Name = "foobar",
            Region = DigitalOcean.Region.NYC3,
        });
    
        var foobarSpacesBucketPolicy = new DigitalOcean.SpacesBucketPolicy("foobar", new()
        {
            Region = foobar.Region,
            Bucket = foobar.Name,
            Policy = Output.JsonSerialize(Output.Create(new Dictionary<string, object?>
            {
                ["Version"] = "2012-10-17",
                ["Statement"] = new[]
                {
                    new Dictionary<string, object?>
                    {
                        ["Sid"] = "IPAllow",
                        ["Effect"] = "Deny",
                        ["Principal"] = "*",
                        ["Action"] = "s3:*",
                        ["Resource"] = new[]
                        {
                            foobar.Name.Apply(name => $"arn:aws:s3:::{name}"),
                            foobar.Name.Apply(name => $"arn:aws:s3:::{name}/*"),
                        },
                        ["Condition"] = new Dictionary<string, object?>
                        {
                            ["NotIpAddress"] = new Dictionary<string, object?>
                            {
                                ["aws:SourceIp"] = "54.240.143.0/24",
                            },
                        },
                    },
                },
            })),
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.digitalocean.SpacesBucket;
    import com.pulumi.digitalocean.SpacesBucketArgs;
    import com.pulumi.digitalocean.SpacesBucketPolicy;
    import com.pulumi.digitalocean.SpacesBucketPolicyArgs;
    import static com.pulumi.codegen.internal.Serialization.*;
    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 foobar = new SpacesBucket("foobar", SpacesBucketArgs.builder()
                .name("foobar")
                .region("nyc3")
                .build());
    
            var foobarSpacesBucketPolicy = new SpacesBucketPolicy("foobarSpacesBucketPolicy", SpacesBucketPolicyArgs.builder()
                .region(foobar.region())
                .bucket(foobar.name())
                .policy(Output.tuple(foobar.name(), foobar.name()).applyValue(values -> {
                    var foobarName = values.t1;
                    var foobarName1 = values.t2;
                    return serializeJson(
                        jsonObject(
                            jsonProperty("Version", "2012-10-17"),
                            jsonProperty("Statement", jsonArray(jsonObject(
                                jsonProperty("Sid", "IPAllow"),
                                jsonProperty("Effect", "Deny"),
                                jsonProperty("Principal", "*"),
                                jsonProperty("Action", "s3:*"),
                                jsonProperty("Resource", jsonArray(
                                    String.format("arn:aws:s3:::%s", foobarName), 
                                    String.format("arn:aws:s3:::%s/*", foobarName1)
                                )),
                                jsonProperty("Condition", jsonObject(
                                    jsonProperty("NotIpAddress", jsonObject(
                                        jsonProperty("aws:SourceIp", "54.240.143.0/24")
                                    ))
                                ))
                            )))
                        ));
                }))
                .build());
    
        }
    }
    
    resources:
      foobar:
        type: digitalocean:SpacesBucket
        properties:
          name: foobar
          region: nyc3
      foobarSpacesBucketPolicy:
        type: digitalocean:SpacesBucketPolicy
        name: foobar
        properties:
          region: ${foobar.region}
          bucket: ${foobar.name}
          policy:
            fn::toJSON:
              Version: 2012-10-17
              Statement:
                - Sid: IPAllow
                  Effect: Deny
                  Principal: '*'
                  Action: s3:*
                  Resource:
                    - arn:aws:s3:::${foobar.name}
                    - arn:aws:s3:::${foobar.name}/*
                  Condition:
                    NotIpAddress:
                      aws:SourceIp: 54.240.143.0/24
    

    !> Warning: Before using this policy, replace the 54.240.143.0/24 IP address range in this example with an appropriate value for your use case. Otherwise, you will lose the ability to access your bucket.

    Create SpacesBucketPolicy Resource

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

    Constructor syntax

    new SpacesBucketPolicy(name: string, args: SpacesBucketPolicyArgs, opts?: CustomResourceOptions);
    @overload
    def SpacesBucketPolicy(resource_name: str,
                           args: SpacesBucketPolicyArgs,
                           opts: Optional[ResourceOptions] = None)
    
    @overload
    def SpacesBucketPolicy(resource_name: str,
                           opts: Optional[ResourceOptions] = None,
                           bucket: Optional[str] = None,
                           policy: Optional[str] = None,
                           region: Optional[str] = None)
    func NewSpacesBucketPolicy(ctx *Context, name string, args SpacesBucketPolicyArgs, opts ...ResourceOption) (*SpacesBucketPolicy, error)
    public SpacesBucketPolicy(string name, SpacesBucketPolicyArgs args, CustomResourceOptions? opts = null)
    public SpacesBucketPolicy(String name, SpacesBucketPolicyArgs args)
    public SpacesBucketPolicy(String name, SpacesBucketPolicyArgs args, CustomResourceOptions options)
    
    type: digitalocean:SpacesBucketPolicy
    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 SpacesBucketPolicyArgs
    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 SpacesBucketPolicyArgs
    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 SpacesBucketPolicyArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args SpacesBucketPolicyArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args SpacesBucketPolicyArgs
    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 spacesBucketPolicyResource = new DigitalOcean.SpacesBucketPolicy("spacesBucketPolicyResource", new()
    {
        Bucket = "string",
        Policy = "string",
        Region = "string",
    });
    
    example, err := digitalocean.NewSpacesBucketPolicy(ctx, "spacesBucketPolicyResource", &digitalocean.SpacesBucketPolicyArgs{
    	Bucket: pulumi.String("string"),
    	Policy: pulumi.String("string"),
    	Region: pulumi.String("string"),
    })
    
    var spacesBucketPolicyResource = new SpacesBucketPolicy("spacesBucketPolicyResource", SpacesBucketPolicyArgs.builder()
        .bucket("string")
        .policy("string")
        .region("string")
        .build());
    
    spaces_bucket_policy_resource = digitalocean.SpacesBucketPolicy("spacesBucketPolicyResource",
        bucket="string",
        policy="string",
        region="string")
    
    const spacesBucketPolicyResource = new digitalocean.SpacesBucketPolicy("spacesBucketPolicyResource", {
        bucket: "string",
        policy: "string",
        region: "string",
    });
    
    type: digitalocean:SpacesBucketPolicy
    properties:
        bucket: string
        policy: string
        region: string
    

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

    Bucket string
    The name of the bucket to which to apply the policy.
    Policy string
    The text of the policy.
    Region string
    The region where the bucket resides.
    Bucket string
    The name of the bucket to which to apply the policy.
    Policy string
    The text of the policy.
    Region string
    The region where the bucket resides.
    bucket String
    The name of the bucket to which to apply the policy.
    policy String
    The text of the policy.
    region String
    The region where the bucket resides.
    bucket string
    The name of the bucket to which to apply the policy.
    policy string
    The text of the policy.
    region string
    The region where the bucket resides.
    bucket str
    The name of the bucket to which to apply the policy.
    policy str
    The text of the policy.
    region str
    The region where the bucket resides.
    bucket String
    The name of the bucket to which to apply the policy.
    policy String
    The text of the policy.
    region String
    The region where the bucket resides.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the SpacesBucketPolicy 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 SpacesBucketPolicy Resource

    Get an existing SpacesBucketPolicy 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?: SpacesBucketPolicyState, opts?: CustomResourceOptions): SpacesBucketPolicy
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            bucket: Optional[str] = None,
            policy: Optional[str] = None,
            region: Optional[str] = None) -> SpacesBucketPolicy
    func GetSpacesBucketPolicy(ctx *Context, name string, id IDInput, state *SpacesBucketPolicyState, opts ...ResourceOption) (*SpacesBucketPolicy, error)
    public static SpacesBucketPolicy Get(string name, Input<string> id, SpacesBucketPolicyState? state, CustomResourceOptions? opts = null)
    public static SpacesBucketPolicy get(String name, Output<String> id, SpacesBucketPolicyState 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:
    Bucket string
    The name of the bucket to which to apply the policy.
    Policy string
    The text of the policy.
    Region string
    The region where the bucket resides.
    Bucket string
    The name of the bucket to which to apply the policy.
    Policy string
    The text of the policy.
    Region string
    The region where the bucket resides.
    bucket String
    The name of the bucket to which to apply the policy.
    policy String
    The text of the policy.
    region String
    The region where the bucket resides.
    bucket string
    The name of the bucket to which to apply the policy.
    policy string
    The text of the policy.
    region string
    The region where the bucket resides.
    bucket str
    The name of the bucket to which to apply the policy.
    policy str
    The text of the policy.
    region str
    The region where the bucket resides.
    bucket String
    The name of the bucket to which to apply the policy.
    policy String
    The text of the policy.
    region String
    The region where the bucket resides.

    Import

    Bucket policies can be imported using the region and bucket attributes (delimited by a comma):

    $ pulumi import digitalocean:index/spacesBucketPolicy:SpacesBucketPolicy foobar `region`,`bucket`
    

    To learn more about importing existing cloud resources, see Importing resources.

    Package Details

    Repository
    DigitalOcean pulumi/pulumi-digitalocean
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the digitalocean Terraform Provider.
    digitalocean logo
    DigitalOcean v4.36.0 published on Wednesday, Dec 4, 2024 by Pulumi