Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support to enable the multi-AZ mode for OBS bucket #1190

Merged
merged 1 commit into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 40 additions & 18 deletions docs/resources/obs_bucket.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
subcategory: "Object Storage Service (OBS)"
---

# huaweicloud\_obs\_bucket
# huaweicloud_obs_bucket

Provides an OBS bucket resource.

Expand Down Expand Up @@ -147,13 +147,17 @@ The following arguments are supported:
A bucket must be named according to the globally applied DNS naming regulations as follows:
* The name must be globally unique in OBS.
* The name must contain 3 to 63 characters. Only lowercase letters, digits, hyphens (-), and periods (.) are allowed.
* The name cannot start or end with a period (.) or hyphen (-), and cannot contain two consecutive periods (.) or contain a period (.) and a hyphen (-) adjacent to each other.
* The name cannot start or end with a period (.) or hyphen (-), and cannot contain two consecutive periods (.) or
contain a period (.) and a hyphen (-) adjacent to each other.
* The name cannot be an IP address.
* If the name contains any periods (.), a security certificate verification message may appear when you access the bucket or its objects by entering a domain name.
* If the name contains any periods (.), a security certificate verification message may appear when you access
the bucket or its objects by entering a domain name.

* `storage_class` - (Optional, String) Specifies the storage class of the bucket. OBS provides three storage classes: "STANDARD", "WARM" (Infrequent Access) and "COLD" (Archive). Defaults to `STANDARD`.
* `storage_class` - (Optional, String) Specifies the storage class of the bucket. OBS provides three storage classes:
"STANDARD", "WARM" (Infrequent Access) and "COLD" (Archive). Defaults to `STANDARD`.

* `acl` - (Optional, String) Specifies the ACL policy for a bucket. The predefined common policies are as follows: "private", "public-read", "public-read-write" and "log-delivery-write". Defaults to `private`.
* `acl` - (Optional, String) Specifies the ACL policy for a bucket. The predefined common policies are as follows:
"private", "public-read", "public-read-write" and "log-delivery-write". Defaults to `private`.

* `policy` - (Optional, String) Specifies the text of the bucket policy in JSON format. For more information about
obs format bucket policy, see the [Developer Guide](https://support.huaweicloud.com/intl/en-us/devg-obs/obs_06_0048.html).
Expand All @@ -167,17 +171,31 @@ The following arguments are supported:

* `logging` - (Optional, Map) A settings of bucket logging (documented below).

* `quota` - (Optional, Int) Specifies bucket storage quota. Must be a positive integer in the unit of byte. The maximum storage quota is 2<sup>63</sup> – 1 bytes. The default bucket storage quota is 0, indicating that the bucket storage quota is not limited.
* `quota` - (Optional, Int) Specifies bucket storage quota. Must be a positive integer in the unit of byte.
The maximum storage quota is 2<sup>63</sup> – 1 bytes. The default bucket storage quota is 0, indicating that
the bucket storage quota is not limited.

* `website` - (Optional, List) A website object (documented below).

* `cors_rule` - (Optional, List) A rule of Cross-Origin Resource Sharing (documented below).

* `lifecycle_rule` - (Optional, List) A configuration of object lifecycle management (documented below).

* `force_destroy` - (Optional, Bool) A boolean that indicates all objects should be deleted from the bucket so that the bucket can be destroyed without error. Default to `false`.
* `force_destroy` - (Optional, Bool) A boolean that indicates all objects should be deleted from the bucket,
so that the bucket can be destroyed without error. Default to `false`.

* `region` - (Optional, String, ForceNew) Specifies the region where this bucket will be created.
If not specified, used the region by the provider. Changing this will create a new bucket.

* `multi_az` - (Optional, Bool, ForceNew) Whether enable the multi-AZ mode for the bucket.
When the multi-AZ mode is enabled, data in the bucket is duplicated and stored in multiple AZs.

* `region` - (Optional, String, ForceNew) Specified the region where this bucket will be created. If not specified, used the region by the provider.
-> **NOTE:** Once a bucket is created, you cannot enable or disable the multi-AZ mode.
Changing this will create a new bucket, but the name of a deleted bucket can be reused
for another bucket at least 30 minutes after the deletion. Exercise caution when changing this field.

* `enterprise_project_id` - (Optional, String, ForceNew) The enterprise project id of the OBS bucket. Changing this creates a OBS bucket.
* `enterprise_project_id` - (Optional, String, ForceNew) Specifies the enterprise project id of the OBS bucket.
Changing this will create a new bucket.

The `logging` object supports the following:

Expand All @@ -187,22 +205,25 @@ The `logging` object supports the following:

The `website` object supports the following:

* `index_document` - (Required, String) Unless using `redirect_all_requests_to`. Specifies the default homepage of the static website, only HTML web pages are supported.
* `index_document` - (Required, String) Unless using `redirect_all_requests_to`. Specifies the default homepage of
the static website, only HTML web pages are supported.
OBS only allows files such as `index.html` in the root directory of a bucket to function as the default homepage.
That is to say, do not set the default homepage with a multi-level directory structure (for example, /page/index.html).

* `error_document` - (Optional, String) Specifies the error page returned when an error occurs during static website access.
Only HTML, JPG, PNG, BMP, and WEBP files under the root directory are supported.

* `redirect_all_requests_to` - (Optional, String) A hostname to redirect all website requests for this bucket to. Hostname can optionally be prefixed with a protocol (`http://` or `https://`) to use when redirecting requests. The default is the protocol that is used in the original request.
* `redirect_all_requests_to` - (Optional, String) A hostname to redirect all website requests for this bucket to.
Hostname can optionally be prefixed with a protocol (`http://` or `https://`) to use when redirecting requests.
The default is the protocol that is used in the original request.

* `routing_rules` - (Optional, String) A JSON or XML format containing routing rules describing redirect behavior and when redirects are applied.
Each rule contains a `Condition` and a `Redirect` as shown in the following table:
* `routing_rules` - (Optional, String) A JSON or XML format containing routing rules describing redirect behavior and
when redirects are applied. Each rule contains a `Condition` and a `Redirect` as shown in the following table:

Parameter | Key
-|-
Condition | KeyPrefixEquals, HttpErrorCodeReturnedEquals
Redirect | Protocol, HostName, ReplaceKeyPrefixWith, ReplaceKeyWith, HttpRedirectCode
Parameter | Key
--- | ---
Condition | KeyPrefixEquals, HttpErrorCodeReturnedEquals
Redirect | Protocol, HostName, ReplaceKeyPrefixWith, ReplaceKeyWith, HttpRedirectCode

The `cors_rule` object supports the following:

Expand All @@ -228,7 +249,8 @@ The `lifecycle_rule` object supports the following:

* `prefix` - (Optional, String) Object key prefix identifying one or more objects to which the rule applies.
If omitted, all objects in the bucket will be managed by the lifecycle rule.
The prefix cannot start or end with a slash (/), cannot have consecutive slashes (/), and cannot contain the following special characters: \:*?"<>|.
The prefix cannot start or end with a slash (/), cannot have consecutive slashes (/), and
cannot contain the following special characters: \:*?"<>|.

* `expiration` - (Optional, List) Specifies a period when objects that have been last updated are automatically deleted. (documented below).
* `transition` - (Optional, List) Specifies a period when objects that have been last updated are automatically transitioned to `WARM` or `COLD` storage class (documented below).
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/hashicorp/errwrap v1.0.0
github.com/hashicorp/go-multierror v1.0.0
github.com/hashicorp/terraform-plugin-sdk v1.16.0
github.com/huaweicloud/golangsdk v0.0.0-20210528023633-c90ae4249a71
github.com/huaweicloud/golangsdk v0.0.0-20210602080359-3d6e5cdfc40f
github.com/jen20/awspolicyequivalence v1.1.0
github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa // indirect
github.com/stretchr/testify v1.4.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/huaweicloud/golangsdk v0.0.0-20210528023633-c90ae4249a71 h1:o2s9CcW277XbOQp0EolTCWHrNdBUHCjuu0aKtAedF/k=
github.com/huaweicloud/golangsdk v0.0.0-20210528023633-c90ae4249a71/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/huaweicloud/golangsdk v0.0.0-20210602080359-3d6e5cdfc40f h1:7FSmwn+mnDmezxuOjfDotwmyxQCQOU1waZDLORl7kGc=
github.com/huaweicloud/golangsdk v0.0.0-20210602080359-3d6e5cdfc40f/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg=
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
Expand Down
32 changes: 23 additions & 9 deletions huaweicloud/resource_huaweicloud_obs_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,17 @@ func ResourceObsBucket() *schema.Resource {
Computed: true,
ForceNew: true,
},

"multi_az": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
ForceNew: true,
},
"enterprise_project_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
ForceNew: true,
},

"bucket_domain_name": {
Expand Down Expand Up @@ -298,8 +303,11 @@ func resourceObsBucketCreate(d *schema.ResourceData, meta interface{}) error {
Epid: GetEnterpriseProjectID(d, config),
}
opts.Location = region
log.Printf("[DEBUG] OBS bucket create opts: %#v", opts)
if _, ok := d.GetOk("multi_az"); ok {
opts.AvailableZone = "3az"
}

log.Printf("[DEBUG] OBS bucket create opts: %#v", opts)
_, err = obsClient.CreateBucket(opts)
if err != nil {
return getObsError("Error creating bucket", bucket, err)
Expand Down Expand Up @@ -422,8 +430,8 @@ func resourceObsBucketRead(d *schema.ResourceData, meta interface{}) error {
return err
}

// Read enterprise project id
if err := setObsBucketEnterpriseProjectID(obsClient, d); err != nil {
// Read enterprise project id and multi_az
if err := setObsBucketMetadata(obsClient, d); err != nil {
return err
}

Expand Down Expand Up @@ -922,7 +930,7 @@ func setObsBucketStorageClass(obsClient *obs.ObsClient, d *schema.ResourceData)
return nil
}

func setObsBucketEnterpriseProjectID(obsClient *obs.ObsClient, d *schema.ResourceData) error {
func setObsBucketMetadata(obsClient *obs.ObsClient, d *schema.ResourceData) error {
bucket := d.Id()
input := &obs.GetBucketMetadataInput{
Bucket: bucket,
Expand All @@ -932,9 +940,15 @@ func setObsBucketEnterpriseProjectID(obsClient *obs.ObsClient, d *schema.Resourc
return getObsError("Error getting metadata of OBS bucket", bucket, err)
}

epsId := string(output.Epid)
log.Printf("[DEBUG] getting enterprise project id of OBS bucket %s: %s", bucket, epsId)
d.Set("enterprise_project_id", epsId)
epsID := string(output.Epid)
log.Printf("[DEBUG] getting enterprise project id of OBS bucket %s: %s", bucket, epsID)
d.Set("enterprise_project_id", epsID)

if output.AvailableZone == "3az" {
d.Set("multi_az", true)
} else {
d.Set("multi_az", false)
}

return nil
}
Expand Down
Loading