1. Packages
  2. Alibaba Cloud
  3. API Docs
  4. oss
  5. BucketCors
Alibaba Cloud v3.55.1 published on Tuesday, May 14, 2024 by Pulumi

alicloud.oss.BucketCors

Explore with Pulumi AI

alicloud logo
Alibaba Cloud v3.55.1 published on Tuesday, May 14, 2024 by Pulumi

    Provides a OSS Bucket Cors resource. Cross-Origin Resource Sharing (CORS) allows web applications to access resources in other regions.

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

    NOTE: Available since v1.223.0.

    Example Usage

    Basic Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as alicloud from "@pulumi/alicloud";
    
    const config = new pulumi.Config();
    const name = config.get("name") || "terraform-example";
    const createBucket = new alicloud.oss.Bucket("CreateBucket", {
        storageClass: "Standard",
        bucket: name,
    });
    const _default = new alicloud.oss.BucketCors("default", {
        bucket: createBucket.bucket,
        responseVary: true,
        corsRules: [{
            allowedMethods: ["GET"],
            allowedOrigins: ["*"],
            allowedHeaders: [
                "x-oss-test",
                "x-oss-abc",
            ],
            exposeHeaders: ["x-oss-request-id"],
            maxAgeSeconds: 1000,
        }],
    });
    
    import pulumi
    import pulumi_alicloud as alicloud
    
    config = pulumi.Config()
    name = config.get("name")
    if name is None:
        name = "terraform-example"
    create_bucket = alicloud.oss.Bucket("CreateBucket",
        storage_class="Standard",
        bucket=name)
    default = alicloud.oss.BucketCors("default",
        bucket=create_bucket.bucket,
        response_vary=True,
        cors_rules=[alicloud.oss.BucketCorsCorsRuleArgs(
            allowed_methods=["GET"],
            allowed_origins=["*"],
            allowed_headers=[
                "x-oss-test",
                "x-oss-abc",
            ],
            expose_headers=["x-oss-request-id"],
            max_age_seconds=1000,
        )])
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/oss"
    	"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
    		}
    		createBucket, err := oss.NewBucket(ctx, "CreateBucket", &oss.BucketArgs{
    			StorageClass: pulumi.String("Standard"),
    			Bucket:       pulumi.String(name),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = oss.NewBucketCors(ctx, "default", &oss.BucketCorsArgs{
    			Bucket:       createBucket.Bucket,
    			ResponseVary: pulumi.Bool(true),
    			CorsRules: oss.BucketCorsCorsRuleArray{
    				&oss.BucketCorsCorsRuleArgs{
    					AllowedMethods: pulumi.StringArray{
    						pulumi.String("GET"),
    					},
    					AllowedOrigins: pulumi.StringArray{
    						pulumi.String("*"),
    					},
    					AllowedHeaders: pulumi.StringArray{
    						pulumi.String("x-oss-test"),
    						pulumi.String("x-oss-abc"),
    					},
    					ExposeHeaders: pulumi.StringArray{
    						pulumi.String("x-oss-request-id"),
    					},
    					MaxAgeSeconds: pulumi.Int(1000),
    				},
    			},
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using AliCloud = Pulumi.AliCloud;
    
    return await Deployment.RunAsync(() => 
    {
        var config = new Config();
        var name = config.Get("name") ?? "terraform-example";
        var createBucket = new AliCloud.Oss.Bucket("CreateBucket", new()
        {
            StorageClass = "Standard",
            BucketName = name,
        });
    
        var @default = new AliCloud.Oss.BucketCors("default", new()
        {
            Bucket = createBucket.BucketName,
            ResponseVary = true,
            CorsRules = new[]
            {
                new AliCloud.Oss.Inputs.BucketCorsCorsRuleArgs
                {
                    AllowedMethods = new[]
                    {
                        "GET",
                    },
                    AllowedOrigins = new[]
                    {
                        "*",
                    },
                    AllowedHeaders = new[]
                    {
                        "x-oss-test",
                        "x-oss-abc",
                    },
                    ExposeHeaders = new[]
                    {
                        "x-oss-request-id",
                    },
                    MaxAgeSeconds = 1000,
                },
            },
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.alicloud.oss.Bucket;
    import com.pulumi.alicloud.oss.BucketArgs;
    import com.pulumi.alicloud.oss.BucketCors;
    import com.pulumi.alicloud.oss.BucketCorsArgs;
    import com.pulumi.alicloud.oss.inputs.BucketCorsCorsRuleArgs;
    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 createBucket = new Bucket("createBucket", BucketArgs.builder()        
                .storageClass("Standard")
                .bucket(name)
                .build());
    
            var default_ = new BucketCors("default", BucketCorsArgs.builder()        
                .bucket(createBucket.bucket())
                .responseVary(true)
                .corsRules(BucketCorsCorsRuleArgs.builder()
                    .allowedMethods("GET")
                    .allowedOrigins("*")
                    .allowedHeaders(                
                        "x-oss-test",
                        "x-oss-abc")
                    .exposeHeaders("x-oss-request-id")
                    .maxAgeSeconds("1000")
                    .build())
                .build());
    
        }
    }
    
    configuration:
      name:
        type: string
        default: terraform-example
    resources:
      createBucket:
        type: alicloud:oss:Bucket
        name: CreateBucket
        properties:
          storageClass: Standard
          bucket: ${name}
      default:
        type: alicloud:oss:BucketCors
        properties:
          bucket: ${createBucket.bucket}
          responseVary: true
          corsRules:
            - allowedMethods:
                - GET
              allowedOrigins:
                - '*'
              allowedHeaders:
                - x-oss-test
                - x-oss-abc
              exposeHeaders:
                - x-oss-request-id
              maxAgeSeconds: '1000'
    

    Create BucketCors Resource

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

    Constructor syntax

    new BucketCors(name: string, args: BucketCorsArgs, opts?: CustomResourceOptions);
    @overload
    def BucketCors(resource_name: str,
                   args: BucketCorsArgs,
                   opts: Optional[ResourceOptions] = None)
    
    @overload
    def BucketCors(resource_name: str,
                   opts: Optional[ResourceOptions] = None,
                   bucket: Optional[str] = None,
                   cors_rules: Optional[Sequence[BucketCorsCorsRuleArgs]] = None,
                   response_vary: Optional[bool] = None)
    func NewBucketCors(ctx *Context, name string, args BucketCorsArgs, opts ...ResourceOption) (*BucketCors, error)
    public BucketCors(string name, BucketCorsArgs args, CustomResourceOptions? opts = null)
    public BucketCors(String name, BucketCorsArgs args)
    public BucketCors(String name, BucketCorsArgs args, CustomResourceOptions options)
    
    type: alicloud:oss:BucketCors
    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 BucketCorsArgs
    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 BucketCorsArgs
    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 BucketCorsArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args BucketCorsArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args BucketCorsArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    Example

    The following reference example uses placeholder values for all input properties.

    var bucketCorsResource = new AliCloud.Oss.BucketCors("bucketCorsResource", new()
    {
        Bucket = "string",
        CorsRules = new[]
        {
            new AliCloud.Oss.Inputs.BucketCorsCorsRuleArgs
            {
                AllowedMethods = new[]
                {
                    "string",
                },
                AllowedHeaders = new[]
                {
                    "string",
                },
                AllowedOrigins = new[]
                {
                    "string",
                },
                ExposeHeaders = new[]
                {
                    "string",
                },
                MaxAgeSeconds = 0,
            },
        },
        ResponseVary = false,
    });
    
    example, err := oss.NewBucketCors(ctx, "bucketCorsResource", &oss.BucketCorsArgs{
    	Bucket: pulumi.String("string"),
    	CorsRules: oss.BucketCorsCorsRuleArray{
    		&oss.BucketCorsCorsRuleArgs{
    			AllowedMethods: pulumi.StringArray{
    				pulumi.String("string"),
    			},
    			AllowedHeaders: pulumi.StringArray{
    				pulumi.String("string"),
    			},
    			AllowedOrigins: pulumi.StringArray{
    				pulumi.String("string"),
    			},
    			ExposeHeaders: pulumi.StringArray{
    				pulumi.String("string"),
    			},
    			MaxAgeSeconds: pulumi.Int(0),
    		},
    	},
    	ResponseVary: pulumi.Bool(false),
    })
    
    var bucketCorsResource = new BucketCors("bucketCorsResource", BucketCorsArgs.builder()        
        .bucket("string")
        .corsRules(BucketCorsCorsRuleArgs.builder()
            .allowedMethods("string")
            .allowedHeaders("string")
            .allowedOrigins("string")
            .exposeHeaders("string")
            .maxAgeSeconds(0)
            .build())
        .responseVary(false)
        .build());
    
    bucket_cors_resource = alicloud.oss.BucketCors("bucketCorsResource",
        bucket="string",
        cors_rules=[alicloud.oss.BucketCorsCorsRuleArgs(
            allowed_methods=["string"],
            allowed_headers=["string"],
            allowed_origins=["string"],
            expose_headers=["string"],
            max_age_seconds=0,
        )],
        response_vary=False)
    
    const bucketCorsResource = new alicloud.oss.BucketCors("bucketCorsResource", {
        bucket: "string",
        corsRules: [{
            allowedMethods: ["string"],
            allowedHeaders: ["string"],
            allowedOrigins: ["string"],
            exposeHeaders: ["string"],
            maxAgeSeconds: 0,
        }],
        responseVary: false,
    });
    
    type: alicloud:oss:BucketCors
    properties:
        bucket: string
        corsRules:
            - allowedHeaders:
                - string
              allowedMethods:
                - string
              allowedOrigins:
                - string
              exposeHeaders:
                - string
              maxAgeSeconds: 0
        responseVary: false
    

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

    Bucket string
    The name of the Bucket.
    CorsRules List<Pulumi.AliCloud.Oss.Inputs.BucketCorsCorsRule>
    The Cross-Origin Resource Sharing (CORS) configuration of the Bucket. See cors_rule below.
    ResponseVary bool
    Specifies whether to return the Vary: Origin header. Valid values: true: returns the Vary: Origin header, regardless of whether the request is a cross-origin request or whether the cross-origin request succeeds. false: does not return the Vary: Origin header. This element is valid only when at least one CORS rule is configured.
    Bucket string
    The name of the Bucket.
    CorsRules []BucketCorsCorsRuleArgs
    The Cross-Origin Resource Sharing (CORS) configuration of the Bucket. See cors_rule below.
    ResponseVary bool
    Specifies whether to return the Vary: Origin header. Valid values: true: returns the Vary: Origin header, regardless of whether the request is a cross-origin request or whether the cross-origin request succeeds. false: does not return the Vary: Origin header. This element is valid only when at least one CORS rule is configured.
    bucket String
    The name of the Bucket.
    corsRules List<BucketCorsCorsRule>
    The Cross-Origin Resource Sharing (CORS) configuration of the Bucket. See cors_rule below.
    responseVary Boolean
    Specifies whether to return the Vary: Origin header. Valid values: true: returns the Vary: Origin header, regardless of whether the request is a cross-origin request or whether the cross-origin request succeeds. false: does not return the Vary: Origin header. This element is valid only when at least one CORS rule is configured.
    bucket string
    The name of the Bucket.
    corsRules BucketCorsCorsRule[]
    The Cross-Origin Resource Sharing (CORS) configuration of the Bucket. See cors_rule below.
    responseVary boolean
    Specifies whether to return the Vary: Origin header. Valid values: true: returns the Vary: Origin header, regardless of whether the request is a cross-origin request or whether the cross-origin request succeeds. false: does not return the Vary: Origin header. This element is valid only when at least one CORS rule is configured.
    bucket str
    The name of the Bucket.
    cors_rules Sequence[BucketCorsCorsRuleArgs]
    The Cross-Origin Resource Sharing (CORS) configuration of the Bucket. See cors_rule below.
    response_vary bool
    Specifies whether to return the Vary: Origin header. Valid values: true: returns the Vary: Origin header, regardless of whether the request is a cross-origin request or whether the cross-origin request succeeds. false: does not return the Vary: Origin header. This element is valid only when at least one CORS rule is configured.
    bucket String
    The name of the Bucket.
    corsRules List<Property Map>
    The Cross-Origin Resource Sharing (CORS) configuration of the Bucket. See cors_rule below.
    responseVary Boolean
    Specifies whether to return the Vary: Origin header. Valid values: true: returns the Vary: Origin header, regardless of whether the request is a cross-origin request or whether the cross-origin request succeeds. false: does not return the Vary: Origin header. This element is valid only when at least one CORS rule is configured.

    Outputs

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

    Get an existing BucketCors 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?: BucketCorsState, opts?: CustomResourceOptions): BucketCors
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            bucket: Optional[str] = None,
            cors_rules: Optional[Sequence[BucketCorsCorsRuleArgs]] = None,
            response_vary: Optional[bool] = None) -> BucketCors
    func GetBucketCors(ctx *Context, name string, id IDInput, state *BucketCorsState, opts ...ResourceOption) (*BucketCors, error)
    public static BucketCors Get(string name, Input<string> id, BucketCorsState? state, CustomResourceOptions? opts = null)
    public static BucketCors get(String name, Output<String> id, BucketCorsState 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.
    CorsRules List<Pulumi.AliCloud.Oss.Inputs.BucketCorsCorsRule>
    The Cross-Origin Resource Sharing (CORS) configuration of the Bucket. See cors_rule below.
    ResponseVary bool
    Specifies whether to return the Vary: Origin header. Valid values: true: returns the Vary: Origin header, regardless of whether the request is a cross-origin request or whether the cross-origin request succeeds. false: does not return the Vary: Origin header. This element is valid only when at least one CORS rule is configured.
    Bucket string
    The name of the Bucket.
    CorsRules []BucketCorsCorsRuleArgs
    The Cross-Origin Resource Sharing (CORS) configuration of the Bucket. See cors_rule below.
    ResponseVary bool
    Specifies whether to return the Vary: Origin header. Valid values: true: returns the Vary: Origin header, regardless of whether the request is a cross-origin request or whether the cross-origin request succeeds. false: does not return the Vary: Origin header. This element is valid only when at least one CORS rule is configured.
    bucket String
    The name of the Bucket.
    corsRules List<BucketCorsCorsRule>
    The Cross-Origin Resource Sharing (CORS) configuration of the Bucket. See cors_rule below.
    responseVary Boolean
    Specifies whether to return the Vary: Origin header. Valid values: true: returns the Vary: Origin header, regardless of whether the request is a cross-origin request or whether the cross-origin request succeeds. false: does not return the Vary: Origin header. This element is valid only when at least one CORS rule is configured.
    bucket string
    The name of the Bucket.
    corsRules BucketCorsCorsRule[]
    The Cross-Origin Resource Sharing (CORS) configuration of the Bucket. See cors_rule below.
    responseVary boolean
    Specifies whether to return the Vary: Origin header. Valid values: true: returns the Vary: Origin header, regardless of whether the request is a cross-origin request or whether the cross-origin request succeeds. false: does not return the Vary: Origin header. This element is valid only when at least one CORS rule is configured.
    bucket str
    The name of the Bucket.
    cors_rules Sequence[BucketCorsCorsRuleArgs]
    The Cross-Origin Resource Sharing (CORS) configuration of the Bucket. See cors_rule below.
    response_vary bool
    Specifies whether to return the Vary: Origin header. Valid values: true: returns the Vary: Origin header, regardless of whether the request is a cross-origin request or whether the cross-origin request succeeds. false: does not return the Vary: Origin header. This element is valid only when at least one CORS rule is configured.
    bucket String
    The name of the Bucket.
    corsRules List<Property Map>
    The Cross-Origin Resource Sharing (CORS) configuration of the Bucket. See cors_rule below.
    responseVary Boolean
    Specifies whether to return the Vary: Origin header. Valid values: true: returns the Vary: Origin header, regardless of whether the request is a cross-origin request or whether the cross-origin request succeeds. false: does not return the Vary: Origin header. This element is valid only when at least one CORS rule is configured.

    Supporting Types

    BucketCorsCorsRule, BucketCorsCorsRuleArgs

    AllowedMethods List<string>
    The cross-origin request method that is allowed. Valid values: GET, PUT, DELETE, POST, and HEAD.
    AllowedHeaders List<string>
    Specifies whether the headers specified by Access-Control-Request-Headers in the OPTIONS preflight request are allowed. You can use only one asterisk (*) as the wildcard for allowed header. .
    AllowedOrigins List<string>
    The origins from which cross-origin requests are allowed. .
    ExposeHeaders List<string>
    The response headers for allowed access requests from applications, such as an XMLHttpRequest object in JavaScript. .
    MaxAgeSeconds int
    The period of time within which the browser can cache the response to an OPTIONS preflight request for the specified resource. Unit: seconds.
    AllowedMethods []string
    The cross-origin request method that is allowed. Valid values: GET, PUT, DELETE, POST, and HEAD.
    AllowedHeaders []string
    Specifies whether the headers specified by Access-Control-Request-Headers in the OPTIONS preflight request are allowed. You can use only one asterisk (*) as the wildcard for allowed header. .
    AllowedOrigins []string
    The origins from which cross-origin requests are allowed. .
    ExposeHeaders []string
    The response headers for allowed access requests from applications, such as an XMLHttpRequest object in JavaScript. .
    MaxAgeSeconds int
    The period of time within which the browser can cache the response to an OPTIONS preflight request for the specified resource. Unit: seconds.
    allowedMethods List<String>
    The cross-origin request method that is allowed. Valid values: GET, PUT, DELETE, POST, and HEAD.
    allowedHeaders List<String>
    Specifies whether the headers specified by Access-Control-Request-Headers in the OPTIONS preflight request are allowed. You can use only one asterisk (*) as the wildcard for allowed header. .
    allowedOrigins List<String>
    The origins from which cross-origin requests are allowed. .
    exposeHeaders List<String>
    The response headers for allowed access requests from applications, such as an XMLHttpRequest object in JavaScript. .
    maxAgeSeconds Integer
    The period of time within which the browser can cache the response to an OPTIONS preflight request for the specified resource. Unit: seconds.
    allowedMethods string[]
    The cross-origin request method that is allowed. Valid values: GET, PUT, DELETE, POST, and HEAD.
    allowedHeaders string[]
    Specifies whether the headers specified by Access-Control-Request-Headers in the OPTIONS preflight request are allowed. You can use only one asterisk (*) as the wildcard for allowed header. .
    allowedOrigins string[]
    The origins from which cross-origin requests are allowed. .
    exposeHeaders string[]
    The response headers for allowed access requests from applications, such as an XMLHttpRequest object in JavaScript. .
    maxAgeSeconds number
    The period of time within which the browser can cache the response to an OPTIONS preflight request for the specified resource. Unit: seconds.
    allowed_methods Sequence[str]
    The cross-origin request method that is allowed. Valid values: GET, PUT, DELETE, POST, and HEAD.
    allowed_headers Sequence[str]
    Specifies whether the headers specified by Access-Control-Request-Headers in the OPTIONS preflight request are allowed. You can use only one asterisk (*) as the wildcard for allowed header. .
    allowed_origins Sequence[str]
    The origins from which cross-origin requests are allowed. .
    expose_headers Sequence[str]
    The response headers for allowed access requests from applications, such as an XMLHttpRequest object in JavaScript. .
    max_age_seconds int
    The period of time within which the browser can cache the response to an OPTIONS preflight request for the specified resource. Unit: seconds.
    allowedMethods List<String>
    The cross-origin request method that is allowed. Valid values: GET, PUT, DELETE, POST, and HEAD.
    allowedHeaders List<String>
    Specifies whether the headers specified by Access-Control-Request-Headers in the OPTIONS preflight request are allowed. You can use only one asterisk (*) as the wildcard for allowed header. .
    allowedOrigins List<String>
    The origins from which cross-origin requests are allowed. .
    exposeHeaders List<String>
    The response headers for allowed access requests from applications, such as an XMLHttpRequest object in JavaScript. .
    maxAgeSeconds Number
    The period of time within which the browser can cache the response to an OPTIONS preflight request for the specified resource. Unit: seconds.

    Import

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

    $ pulumi import alicloud:oss/bucketCors:BucketCors 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.55.1 published on Tuesday, May 14, 2024 by Pulumi