1. Packages
  2. Alibaba Cloud Provider
  3. API Docs
  4. oss
  5. BucketPolicy
Alibaba Cloud v3.68.0 published on Monday, Dec 2, 2024 by Pulumi

alicloud.oss.BucketPolicy

Explore with Pulumi AI

alicloud logo
Alibaba Cloud v3.68.0 published on Monday, Dec 2, 2024 by Pulumi

    Provides a OSS Bucket Policy resource. Authorization policy of a bucket.

    For information about OSS Bucket Policy and how to use it, see What is Bucket Policy.

    NOTE: Available since v1.220.0.

    Example Usage

    Basic Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as alicloud from "@pulumi/alicloud";
    import * as random from "@pulumi/random";
    
    const config = new pulumi.Config();
    const name = config.get("name") || "terraform-example";
    const _default = new random.index.Integer("default", {
        min: 10000,
        max: 99999,
    });
    const createBucket = new alicloud.oss.Bucket("CreateBucket", {
        storageClass: "Standard",
        bucket: `${name}-${_default.result}`,
    });
    const defaultBucketPolicy = new alicloud.oss.BucketPolicy("default", {
        policy: JSON.stringify({
            Version: "1",
            Statement: [{
                Action: [
                    "oss:PutObject",
                    "oss:GetObject",
                ],
                Effect: "Deny",
                Principal: ["1234567890"],
                Resource: ["acs:oss:*:1234567890:*/*"],
            }],
        }),
        bucket: createBucket.bucket,
    }, {
        dependsOn: [createBucket],
    });
    
    import pulumi
    import json
    import pulumi_alicloud as alicloud
    import pulumi_random as random
    
    config = pulumi.Config()
    name = config.get("name")
    if name is None:
        name = "terraform-example"
    default = random.index.Integer("default",
        min=10000,
        max=99999)
    create_bucket = alicloud.oss.Bucket("CreateBucket",
        storage_class="Standard",
        bucket=f"{name}-{default['result']}")
    default_bucket_policy = alicloud.oss.BucketPolicy("default",
        policy=json.dumps({
            "Version": "1",
            "Statement": [{
                "Action": [
                    "oss:PutObject",
                    "oss:GetObject",
                ],
                "Effect": "Deny",
                "Principal": ["1234567890"],
                "Resource": ["acs:oss:*:1234567890:*/*"],
            }],
        }),
        bucket=create_bucket.bucket,
        opts = pulumi.ResourceOptions(depends_on=[create_bucket]))
    
    package main
    
    import (
    	"encoding/json"
    	"fmt"
    
    	"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/oss"
    	"github.com/pulumi/pulumi-random/sdk/v4/go/random"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		cfg := config.New(ctx, "")
    		name := "terraform-example"
    		if param := cfg.Get("name"); param != "" {
    			name = param
    		}
    		_, err := random.NewInteger(ctx, "default", &random.IntegerArgs{
    			Min: 10000,
    			Max: 99999,
    		})
    		if err != nil {
    			return err
    		}
    		createBucket, err := oss.NewBucket(ctx, "CreateBucket", &oss.BucketArgs{
    			StorageClass: pulumi.String("Standard"),
    			Bucket:       pulumi.Sprintf("%v-%v", name, _default.Result),
    		})
    		if err != nil {
    			return err
    		}
    		tmpJSON0, err := json.Marshal(map[string]interface{}{
    			"Version": "1",
    			"Statement": []map[string]interface{}{
    				map[string]interface{}{
    					"Action": []string{
    						"oss:PutObject",
    						"oss:GetObject",
    					},
    					"Effect": "Deny",
    					"Principal": []string{
    						"1234567890",
    					},
    					"Resource": []string{
    						"acs:oss:*:1234567890:*/*",
    					},
    				},
    			},
    		})
    		if err != nil {
    			return err
    		}
    		json0 := string(tmpJSON0)
    		_, err = oss.NewBucketPolicy(ctx, "default", &oss.BucketPolicyArgs{
    			Policy: pulumi.String(json0),
    			Bucket: createBucket.Bucket,
    		}, pulumi.DependsOn([]pulumi.Resource{
    			createBucket,
    		}))
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using System.Text.Json;
    using Pulumi;
    using AliCloud = Pulumi.AliCloud;
    using Random = Pulumi.Random;
    
    return await Deployment.RunAsync(() => 
    {
        var config = new Config();
        var name = config.Get("name") ?? "terraform-example";
        var @default = new Random.Index.Integer("default", new()
        {
            Min = 10000,
            Max = 99999,
        });
    
        var createBucket = new AliCloud.Oss.Bucket("CreateBucket", new()
        {
            StorageClass = "Standard",
            BucketName = $"{name}-{@default.Result}",
        });
    
        var defaultBucketPolicy = new AliCloud.Oss.BucketPolicy("default", new()
        {
            Policy = JsonSerializer.Serialize(new Dictionary<string, object?>
            {
                ["Version"] = "1",
                ["Statement"] = new[]
                {
                    new Dictionary<string, object?>
                    {
                        ["Action"] = new[]
                        {
                            "oss:PutObject",
                            "oss:GetObject",
                        },
                        ["Effect"] = "Deny",
                        ["Principal"] = new[]
                        {
                            "1234567890",
                        },
                        ["Resource"] = new[]
                        {
                            "acs:oss:*:1234567890:*/*",
                        },
                    },
                },
            }),
            Bucket = createBucket.BucketName,
        }, new CustomResourceOptions
        {
            DependsOn =
            {
                createBucket,
            },
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.random.integer;
    import com.pulumi.random.IntegerArgs;
    import com.pulumi.alicloud.oss.Bucket;
    import com.pulumi.alicloud.oss.BucketArgs;
    import com.pulumi.alicloud.oss.BucketPolicy;
    import com.pulumi.alicloud.oss.BucketPolicyArgs;
    import static com.pulumi.codegen.internal.Serialization.*;
    import com.pulumi.resources.CustomResourceOptions;
    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 config = ctx.config();
            final var name = config.get("name").orElse("terraform-example");
            var default_ = new Integer("default", IntegerArgs.builder()
                .min(10000)
                .max(99999)
                .build());
    
            var createBucket = new Bucket("createBucket", BucketArgs.builder()
                .storageClass("Standard")
                .bucket(String.format("%s-%s", name,default_.result()))
                .build());
    
            var defaultBucketPolicy = new BucketPolicy("defaultBucketPolicy", BucketPolicyArgs.builder()
                .policy(serializeJson(
                    jsonObject(
                        jsonProperty("Version", "1"),
                        jsonProperty("Statement", jsonArray(jsonObject(
                            jsonProperty("Action", jsonArray(
                                "oss:PutObject", 
                                "oss:GetObject"
                            )),
                            jsonProperty("Effect", "Deny"),
                            jsonProperty("Principal", jsonArray("1234567890")),
                            jsonProperty("Resource", jsonArray("acs:oss:*:1234567890:*/*"))
                        )))
                    )))
                .bucket(createBucket.bucket())
                .build(), CustomResourceOptions.builder()
                    .dependsOn(createBucket)
                    .build());
    
        }
    }
    
    configuration:
      name:
        type: string
        default: terraform-example
    resources:
      default:
        type: random:integer
        properties:
          min: 10000
          max: 99999
      createBucket:
        type: alicloud:oss:Bucket
        name: CreateBucket
        properties:
          storageClass: Standard
          bucket: ${name}-${default.result}
      defaultBucketPolicy:
        type: alicloud:oss:BucketPolicy
        name: default
        properties:
          policy:
            fn::toJSON:
              Version: '1'
              Statement:
                - Action:
                    - oss:PutObject
                    - oss:GetObject
                  Effect: Deny
                  Principal:
                    - '1234567890'
                  Resource:
                    - acs:oss:*:1234567890:*/*
          bucket: ${createBucket.bucket}
        options:
          dependson:
            - ${createBucket}
    

    Create BucketPolicy Resource

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

    Constructor syntax

    new BucketPolicy(name: string, args: BucketPolicyArgs, opts?: CustomResourceOptions);
    @overload
    def BucketPolicy(resource_name: str,
                     args: BucketPolicyArgs,
                     opts: Optional[ResourceOptions] = None)
    
    @overload
    def BucketPolicy(resource_name: str,
                     opts: Optional[ResourceOptions] = None,
                     bucket: Optional[str] = None,
                     policy: Optional[str] = None)
    func NewBucketPolicy(ctx *Context, name string, args BucketPolicyArgs, opts ...ResourceOption) (*BucketPolicy, error)
    public BucketPolicy(string name, BucketPolicyArgs args, CustomResourceOptions? opts = null)
    public BucketPolicy(String name, BucketPolicyArgs args)
    public BucketPolicy(String name, BucketPolicyArgs args, CustomResourceOptions options)
    
    type: alicloud:oss:BucketPolicy
    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 BucketPolicyArgs
    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 BucketPolicyArgs
    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 BucketPolicyArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args BucketPolicyArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args BucketPolicyArgs
    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 bucketPolicyResource = new AliCloud.Oss.BucketPolicy("bucketPolicyResource", new()
    {
        Bucket = "string",
        Policy = "string",
    });
    
    example, err := oss.NewBucketPolicy(ctx, "bucketPolicyResource", &oss.BucketPolicyArgs{
    	Bucket: pulumi.String("string"),
    	Policy: pulumi.String("string"),
    })
    
    var bucketPolicyResource = new BucketPolicy("bucketPolicyResource", BucketPolicyArgs.builder()
        .bucket("string")
        .policy("string")
        .build());
    
    bucket_policy_resource = alicloud.oss.BucketPolicy("bucketPolicyResource",
        bucket="string",
        policy="string")
    
    const bucketPolicyResource = new alicloud.oss.BucketPolicy("bucketPolicyResource", {
        bucket: "string",
        policy: "string",
    });
    
    type: alicloud:oss:BucketPolicy
    properties:
        bucket: string
        policy: string
    

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

    Bucket string
    The name of the Bucket.
    Policy string
    Json-formatted authorization policies for buckets.
    Bucket string
    The name of the Bucket.
    Policy string
    Json-formatted authorization policies for buckets.
    bucket String
    The name of the Bucket.
    policy String
    Json-formatted authorization policies for buckets.
    bucket string
    The name of the Bucket.
    policy string
    Json-formatted authorization policies for buckets.
    bucket str
    The name of the Bucket.
    policy str
    Json-formatted authorization policies for buckets.
    bucket String
    The name of the Bucket.
    policy String
    Json-formatted authorization policies for buckets.

    Outputs

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

    Get an existing BucketPolicy 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?: BucketPolicyState, opts?: CustomResourceOptions): BucketPolicy
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            bucket: Optional[str] = None,
            policy: Optional[str] = None) -> BucketPolicy
    func GetBucketPolicy(ctx *Context, name string, id IDInput, state *BucketPolicyState, opts ...ResourceOption) (*BucketPolicy, error)
    public static BucketPolicy Get(string name, Input<string> id, BucketPolicyState? state, CustomResourceOptions? opts = null)
    public static BucketPolicy get(String name, Output<String> id, BucketPolicyState 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.
    Policy string
    Json-formatted authorization policies for buckets.
    Bucket string
    The name of the Bucket.
    Policy string
    Json-formatted authorization policies for buckets.
    bucket String
    The name of the Bucket.
    policy String
    Json-formatted authorization policies for buckets.
    bucket string
    The name of the Bucket.
    policy string
    Json-formatted authorization policies for buckets.
    bucket str
    The name of the Bucket.
    policy str
    Json-formatted authorization policies for buckets.
    bucket String
    The name of the Bucket.
    policy String
    Json-formatted authorization policies for buckets.

    Import

    OSS Bucket Policy can be imported using the id, e.g.

    $ pulumi import alicloud:oss/bucketPolicy:BucketPolicy example <id>
    

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

    Package Details

    Repository
    Alibaba Cloud pulumi/pulumi-alicloud
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the alicloud Terraform Provider.
    alicloud logo
    Alibaba Cloud v3.68.0 published on Monday, Dec 2, 2024 by Pulumi