1. Packages
  2. DigitalOcean
  3. API Docs
  4. SpacesBucketPolicy
DigitalOcean v4.22.0 published on Friday, Sep 22, 2023 by Pulumi

digitalocean.SpacesBucketPolicy

Explore with Pulumi AI

digitalocean logo
DigitalOcean v4.22.0 published on Friday, Sep 22, 2023 by Pulumi

    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`
    

    Example Usage

    Limiting access to specific IP addresses

    using System.Collections.Generic;
    using System.Linq;
    using System.Text.Json;
    using Pulumi;
    using DigitalOcean = Pulumi.DigitalOcean;
    
    return await Deployment.RunAsync(() => 
    {
        var foobarSpacesBucket = new DigitalOcean.SpacesBucket("foobarSpacesBucket", new()
        {
            Region = "nyc3",
        });
    
        var foobarSpacesBucketPolicy = new DigitalOcean.SpacesBucketPolicy("foobarSpacesBucketPolicy", new()
        {
            Region = foobarSpacesBucket.Region,
            Bucket = foobarSpacesBucket.Name,
            Policy = Output.Tuple(foobarSpacesBucket.Name, foobarSpacesBucket.Name).Apply(values =>
            {
                var foobarSpacesBucketName = values.Item1;
                var foobarSpacesBucketName1 = values.Item2;
                return JsonSerializer.Serialize(new Dictionary<string, object?>
                {
                    ["Version"] = "2012-10-17",
                    ["Statement"] = new[]
                    {
                        new Dictionary<string, object?>
                        {
                            ["Sid"] = "IPAllow",
                            ["Effect"] = "Deny",
                            ["Principal"] = "*",
                            ["Action"] = "s3:*",
                            ["Resource"] = new[]
                            {
                                $"arn:aws:s3:::{foobarSpacesBucketName}",
                                $"arn:aws:s3:::{foobarSpacesBucketName1}/*",
                            },
                            ["Condition"] = new Dictionary<string, object?>
                            {
                                ["NotIpAddress"] = new Dictionary<string, object?>
                                {
                                    ["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 {
    		foobarSpacesBucket, err := digitalocean.NewSpacesBucket(ctx, "foobarSpacesBucket", &digitalocean.SpacesBucketArgs{
    			Region: pulumi.String("nyc3"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = digitalocean.NewSpacesBucketPolicy(ctx, "foobarSpacesBucketPolicy", &digitalocean.SpacesBucketPolicyArgs{
    			Region: foobarSpacesBucket.Region,
    			Bucket: foobarSpacesBucket.Name,
    			Policy: pulumi.All(foobarSpacesBucket.Name, foobarSpacesBucket.Name).ApplyT(func(_args []interface{}) (string, error) {
    				foobarSpacesBucketName := _args[0].(string)
    				foobarSpacesBucketName1 := _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", foobarSpacesBucketName),
    								fmt.Sprintf("arn:aws:s3:::%v/*", foobarSpacesBucketName1),
    							},
    							"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
    	})
    }
    
    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 foobarSpacesBucket = new SpacesBucket("foobarSpacesBucket", SpacesBucketArgs.builder()        
                .region("nyc3")
                .build());
    
            var foobarSpacesBucketPolicy = new SpacesBucketPolicy("foobarSpacesBucketPolicy", SpacesBucketPolicyArgs.builder()        
                .region(foobarSpacesBucket.region())
                .bucket(foobarSpacesBucket.name())
                .policy(Output.tuple(foobarSpacesBucket.name(), foobarSpacesBucket.name()).applyValue(values -> {
                    var foobarSpacesBucketName = values.t1;
                    var foobarSpacesBucketName1 = 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", foobarSpacesBucketName), 
                                    String.format("arn:aws:s3:::%s/*", foobarSpacesBucketName1)
                                )),
                                jsonProperty("Condition", jsonObject(
                                    jsonProperty("NotIpAddress", jsonObject(
                                        jsonProperty("aws:SourceIp", "54.240.143.0/24")
                                    ))
                                ))
                            )))
                        ));
                }))
                .build());
    
        }
    }
    
    import pulumi
    import json
    import pulumi_digitalocean as digitalocean
    
    foobar_spaces_bucket = digitalocean.SpacesBucket("foobarSpacesBucket", region="nyc3")
    foobar_spaces_bucket_policy = digitalocean.SpacesBucketPolicy("foobarSpacesBucketPolicy",
        region=foobar_spaces_bucket.region,
        bucket=foobar_spaces_bucket.name,
        policy=pulumi.Output.all(foobar_spaces_bucket.name, foobar_spaces_bucket.name).apply(lambda foobarSpacesBucketName, foobarSpacesBucketName1: json.dumps({
            "Version": "2012-10-17",
            "Statement": [{
                "Sid": "IPAllow",
                "Effect": "Deny",
                "Principal": "*",
                "Action": "s3:*",
                "Resource": [
                    f"arn:aws:s3:::{foobar_spaces_bucket_name}",
                    f"arn:aws:s3:::{foobar_spaces_bucket_name1}/*",
                ],
                "Condition": {
                    "NotIpAddress": {
                        "aws:SourceIp": "54.240.143.0/24",
                    },
                },
            }],
        })))
    
    import * as pulumi from "@pulumi/pulumi";
    import * as digitalocean from "@pulumi/digitalocean";
    
    const foobarSpacesBucket = new digitalocean.SpacesBucket("foobarSpacesBucket", {region: "nyc3"});
    const foobarSpacesBucketPolicy = new digitalocean.SpacesBucketPolicy("foobarSpacesBucketPolicy", {
        region: foobarSpacesBucket.region,
        bucket: foobarSpacesBucket.name,
        policy: pulumi.all([foobarSpacesBucket.name, foobarSpacesBucket.name]).apply(([foobarSpacesBucketName, foobarSpacesBucketName1]) => JSON.stringify({
            Version: "2012-10-17",
            Statement: [{
                Sid: "IPAllow",
                Effect: "Deny",
                Principal: "*",
                Action: "s3:*",
                Resource: [
                    `arn:aws:s3:::${foobarSpacesBucketName}`,
                    `arn:aws:s3:::${foobarSpacesBucketName1}/*`,
                ],
                Condition: {
                    NotIpAddress: {
                        "aws:SourceIp": "54.240.143.0/24",
                    },
                },
            }],
        })),
    });
    
    resources:
      foobarSpacesBucket:
        type: digitalocean:SpacesBucket
        properties:
          region: nyc3
      foobarSpacesBucketPolicy:
        type: digitalocean:SpacesBucketPolicy
        properties:
          region: ${foobarSpacesBucket.region}
          bucket: ${foobarSpacesBucket.name}
          policy:
            fn::toJSON:
              Version: 2012-10-17
              Statement:
                - Sid: IPAllow
                  Effect: Deny
                  Principal: '*'
                  Action: s3:*
                  Resource:
                    - arn:aws:s3:::${foobarSpacesBucket.name}
                    - arn:aws:s3:::${foobarSpacesBucket.name}/*
                  Condition:
                    NotIpAddress:
                      aws:SourceIp: 54.240.143.0/24
    

    Create SpacesBucketPolicy Resource

    new SpacesBucketPolicy(name: string, args: SpacesBucketPolicyArgs, opts?: CustomResourceOptions);
    @overload
    def SpacesBucketPolicy(resource_name: str,
                           opts: Optional[ResourceOptions] = None,
                           bucket: Optional[str] = None,
                           policy: Optional[str] = None,
                           region: Optional[str] = None)
    @overload
    def SpacesBucketPolicy(resource_name: str,
                           args: SpacesBucketPolicyArgs,
                           opts: Optional[ResourceOptions] = 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.
    
    
    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.

    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

    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.

    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.22.0 published on Friday, Sep 22, 2023 by Pulumi