Updated on 2022-02-10 GMT+08:00

Performing Basic Operations

Application Scenario

Object Storage Service (OBS) is a cloud storage service optimized for storing data of any type and size. It provides unlimited, secure, and highly reliable storage capabilities at a low cost. It is suitable for various data storage scenarios, such as enterprise-level backup/archiving, video on demand (VoD), and video surveillance.

Procedure

  1. Create an OBS bucket.

    1. Create the main.tf file, enter the following information, and save the file:
      resource "huaweicloud_obs_bucket" "myexample" {
        bucket = "myexample-bucket"
        acl    = "private"
        tags = {
          type = "bucket"
          env  = "Test"
        }
      }
    2. Run terraform init to initialize the environment.
    3. Run terraform plan to view resources.
    4. After you confirm that the resource information is correct, run terraform apply to start OBS bucket creation.
    5. Run terraform show to view the created OBS bucket.

  2. Upload objects.

    1. Objects can be uploaded through data flows or source files. Add the following information to the main.tf file:
      # Upload an object through data flows.
      resource "huaweicloud_obs_bucket_object" "myobject1" {
        bucket       = huaweicloud_obs_bucket.myexample.bucket
        key          = "myobject1"
        content      = "content of myobject1"
        content_type = "application/xml"
      }
      # Upload an object through a source file.
      resource "huaweicloud_obs_bucket_object" "myobject2" {
        bucket = huaweicloud_obs_bucket.myexample.bucket
        key    = "myobject2"
        source = "hello.txt"
      }
      # Upload an object through a source file and enable server-side encryption.
      resource "huaweicloud_obs_bucket_object" "myobject3" {
        bucket     = huaweicloud_obs_bucket.myexample.bucket
        key        = "myobject3"
        source     = "hello.txt"
        encryption = true
      }
    2. Run terraform plan to view resources.
    3. After you confirm that the resource information is correct, run terraform apply to start resource creation.
    4. Run terraform show to view the uploaded objects.

Table 1 Parameter description

Resource Name

Parameter

Description

huaweicloud_obs_bucket

bucket

(Mandatory) OBS bucket name.

An OBS bucket name:

  • Must be globally unique in OBS.
  • Contains 3 to 63 characters, including lowercase letters, digits, hyphens (-), and periods (.).
  • Cannot start or end with a period (.) or hyphen (-).
  • Cannot contain two consecutive periods (..) or adjacent periods and hyphens (.- or -.).
  • Cannot be an IP address.

acl

(Optional) OBS bucket access control policy.

  • Value:

    private (default value): No access permission beyond the bucket ACL settings is granted.

    public-read: Any user can read objects in the bucket.

    public-read-write: Any user can read, write, and delete objects in the bucket.

tags

(Optional) Bucket tag.

huaweicloud_obs_bucket_object

bucket

(Mandatory) Bucket name.

key

(Mandatory) Object name.

source

(Optional) Path to the source file of the object.

content

(Optional) Data flow of the object.

content_type

(Optional) MIME type of the object.

encryption

(Optional) Whether to enable server-side encryption using keys hosted by KMS (SSE-KMS).