alicloud_oss_bucket_cors

更新时间:

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


variable "name" {
  default = "terraform-example"
}

provider "alicloud" {
  region = "cn-hangzhou"
}

resource "random_uuid" "default" {

}

resource "alicloud_oss_bucket" "CreateBucket" {
  storage_class = "Standard"
  bucket        = "${var.name}-${random_uuid.default.result}"
  lifecycle {
    ignore_changes = [
      cors_rule,
    ]
  }
}


resource "alicloud_oss_bucket_cors" "default" {
  bucket        = alicloud_oss_bucket.CreateBucket.bucket
  response_vary = true
  cors_rule {
    allowed_methods = ["GET"]
    allowed_origins = ["*"]
    allowed_headers = ["x-oss-test", "x-oss-abc"]
    expose_header   = ["x-oss-request-id"]
    max_age_seconds = "1000"
  }
}

Argument Reference

The following arguments are supported:

  • bucket - (Required, ForceNew) The name of the Bucket.
  • cors_rule - (Required) The Cross-Origin Resource Sharing (CORS) configuration of the Bucket. See cors_rule below.
  • response_vary - (Optional, Computed) 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.

cors_rule

The cors_rule supports the following:

  • allowed_headers - (Optional) 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_methods - (Required) The cross-origin request method that is allowed. Valid values: GET, PUT, DELETE, POST, and HEAD.
  • allowed_origins - (Optional) The origins from which cross-origin requests are allowed. .
  • expose_header - (Optional) The response headers for allowed access requests from applications, such as an XMLHttpRequest object in JavaScript. .
  • max_age_seconds - (Optional) The period of time within which the browser can cache the response to an OPTIONS preflight request for the specified resource. Unit: seconds.

Attributes Reference

The following attributes are exported:

  • id - The ID of the resource supplied above.

Timeouts

The timeouts block allows you to specify timeouts for certain actions:

  • create - (Defaults to 5 mins) Used when create the Bucket Cors.
  • delete - (Defaults to 5 mins) Used when delete the Bucket Cors.
  • update - (Defaults to 5 mins) Used when update the Bucket Cors.

Import

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

$ terraform import alicloud_oss_bucket_cors.example <id>