文档

alicloud_oss_bucket_policy

更新时间:
一键部署

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

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

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

resource "random_integer" "default" {
  min = 10000
  max = 99999
}

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

resource "alicloud_oss_bucket_policy" "default" {
  depends_on = [alicloud_oss_bucket.CreateBucket]

  policy = jsonencode({ "Version" : "1", "Statement" : [{ "Action" : ["oss:PutObject", "oss:GetObject"], "Effect" : "Deny", "Principal" : ["1234567890"], "Resource" : ["acs:oss:*:1234567890:*/*"] }] })
  bucket = alicloud_oss_bucket.CreateBucket.bucket
}

Argument Reference

The following arguments are supported:

  • bucket - (Required, ForceNew) The name of the Bucket.
  • policy - (Required) Json-formatted authorization policies for buckets.

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 Policy.
  • delete - (Defaults to 5 mins) Used when delete the Bucket Policy.
  • update - (Defaults to 5 mins) Used when update the Bucket Policy.

Import

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

$ terraform import alicloud_oss_bucket_policy.example <id>