alicloud.oss.BucketCors
Explore with Pulumi AI
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";
import * as random from "@pulumi/random";
const config = new pulumi.Config();
const name = config.get("name") || "terraform-example";
const _default = new random.index.Uuid("default", {});
const createBucket = new alicloud.oss.Bucket("CreateBucket", {
storageClass: "Standard",
bucket: `${name}-${_default.result}`,
});
const defaultBucketCors = 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
import pulumi_random as random
config = pulumi.Config()
name = config.get("name")
if name is None:
name = "terraform-example"
default = random.index.Uuid("default")
create_bucket = alicloud.oss.Bucket("CreateBucket",
storage_class="Standard",
bucket=f"{name}-{default['result']}")
default_bucket_cors = alicloud.oss.BucketCors("default",
bucket=create_bucket.bucket,
response_vary=True,
cors_rules=[{
"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 (
"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.NewUuid(ctx, "default", nil)
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
}
_, 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;
using Random = Pulumi.Random;
return await Deployment.RunAsync(() =>
{
var config = new Config();
var name = config.Get("name") ?? "terraform-example";
var @default = new Random.Index.Uuid("default");
var createBucket = new AliCloud.Oss.Bucket("CreateBucket", new()
{
StorageClass = "Standard",
BucketName = $"{name}-{@default.Result}",
});
var defaultBucketCors = 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.random.uuid;
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 default_ = new Uuid("default");
var createBucket = new Bucket("createBucket", BucketArgs.builder()
.storageClass("Standard")
.bucket(String.format("%s-%s", name,default_.result()))
.build());
var defaultBucketCors = new BucketCors("defaultBucketCors", 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:
default:
type: random:uuid
createBucket:
type: alicloud:oss:Bucket
name: CreateBucket
properties:
storageClass: Standard
bucket: ${name}-${default.result}
defaultBucketCors:
type: alicloud:oss:BucketCors
name: default
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.
Constructor 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=[{
"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
In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.
The BucketCors resource accepts the following input properties:
- Bucket string
- The name of the Bucket.
- Cors
Rules List<Pulumi.Ali Cloud. Oss. Inputs. Bucket Cors Cors Rule> - 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.
- Cors
Rules []BucketCors Cors Rule Args - 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.
- cors
Rules List<BucketCors Cors Rule> - The Cross-Origin Resource Sharing (CORS) configuration of the Bucket. See
cors_rule
below. - response
Vary 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.
- cors
Rules BucketCors Cors Rule[] - The Cross-Origin Resource Sharing (CORS) configuration of the Bucket. See
cors_rule
below. - response
Vary 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[BucketCors Cors Rule Args] - 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.
- cors
Rules List<Property Map> - The Cross-Origin Resource Sharing (CORS) configuration of the Bucket. See
cors_rule
below. - response
Vary 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.
- Bucket string
- The name of the Bucket.
- Cors
Rules List<Pulumi.Ali Cloud. Oss. Inputs. Bucket Cors Cors Rule> - 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.
- Cors
Rules []BucketCors Cors Rule Args - 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.
- cors
Rules List<BucketCors Cors Rule> - The Cross-Origin Resource Sharing (CORS) configuration of the Bucket. See
cors_rule
below. - response
Vary 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.
- cors
Rules BucketCors Cors Rule[] - The Cross-Origin Resource Sharing (CORS) configuration of the Bucket. See
cors_rule
below. - response
Vary 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[BucketCors Cors Rule Args] - 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.
- cors
Rules List<Property Map> - The Cross-Origin Resource Sharing (CORS) configuration of the Bucket. See
cors_rule
below. - response
Vary 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
- Allowed
Methods List<string> - The cross-origin request method that is allowed. Valid values: GET, PUT, DELETE, POST, and HEAD.
- Allowed
Headers 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. .
- Allowed
Origins List<string> - The origins from which cross-origin requests are allowed. .
- Expose
Headers List<string> - The response headers for allowed access requests from applications, such as an XMLHttpRequest object in JavaScript. .
- Max
Age intSeconds - 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 []string - The cross-origin request method that is allowed. Valid values: GET, PUT, DELETE, POST, and HEAD.
- Allowed
Headers []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. .
- Allowed
Origins []string - The origins from which cross-origin requests are allowed. .
- Expose
Headers []string - The response headers for allowed access requests from applications, such as an XMLHttpRequest object in JavaScript. .
- Max
Age intSeconds - 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 List<String> - The cross-origin request method that is allowed. Valid values: GET, PUT, DELETE, POST, and HEAD.
- allowed
Headers 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. .
- allowed
Origins List<String> - The origins from which cross-origin requests are allowed. .
- expose
Headers List<String> - The response headers for allowed access requests from applications, such as an XMLHttpRequest object in JavaScript. .
- max
Age IntegerSeconds - 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 string[] - The cross-origin request method that is allowed. Valid values: GET, PUT, DELETE, POST, and HEAD.
- allowed
Headers 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. .
- allowed
Origins string[] - The origins from which cross-origin requests are allowed. .
- expose
Headers string[] - The response headers for allowed access requests from applications, such as an XMLHttpRequest object in JavaScript. .
- max
Age numberSeconds - 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_ intseconds - 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 List<String> - The cross-origin request method that is allowed. Valid values: GET, PUT, DELETE, POST, and HEAD.
- allowed
Headers 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. .
- allowed
Origins List<String> - The origins from which cross-origin requests are allowed. .
- expose
Headers List<String> - The response headers for allowed access requests from applications, such as an XMLHttpRequest object in JavaScript. .
- max
Age NumberSeconds - 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.