Skip to content

Commit

Permalink
feat: Add Object Storage service (NaverCloudPlatform#439)
Browse files Browse the repository at this point in the history
* chore: Upgrade Go version to v1.21

chore: Upgrade Go version to v1.21

chore: upgrade Go to v1.21

ci: Set go version 1.21 in GitHub Actions

ci: Upgrade actions version (checkout, setup-go, ci-lint)

ci: Upgrade golangci-lint v1.59

* chore: Install AWS SDK for Object Storage API

* feat: Add S3 Client configuration

* feat: Add Object Storage Resources

* feat: Add objectstorage_bucket resource

* feat: Add objectstorage_bucket_acl resource

* feat: Add objectstorage_object resource

* feat: Add objectstorage_object_acl resource

* fix: add "_bucket" suffix to bucket resource

* feat: Add examples of object storage

* docs: Add initial documentation of object storage

* feat: add type casting function for nested listValue

* feat: Add BucketRegion to bucket chema

* fix: Add detailed schema of grants & type casting method

* chore: Add error exception

* feat: Add regex validator for resource id

* chore: remove redundant EOL

* fix: Remove BucketName, BucketRegion from schema(doesn't provided)

* refactor: Add TrimForIDParsing util

* feat: Add temporary file creation logic

* feat: Add aclOptions for testing

* fix: Removed Unavailable object acl

* feat: Add Bucket data source

* fix: Add new bucket creation for independant testing

* fix: aws.String => ncloud.String

* chore: fix typo

* chore: change string value with constants

* refactor: expand TrimForParsing to parse vairous strings (not only ID)

* feat: use region info from initial configuration

* refactor: Set bucket id same as bucket name

* fix: Add detailed string validator with regex for bucket_name

* feat: Add NewObjectDataSource data source

* refactor: Move ObjectIDParser to object.go

* refactor: Set Object Resource ID with new format

* feat: set independent object testing

* feat: Add Owner info & Creation Date to bucket data source

* feat: Add OwnerID & OwnerDisplayname at object_acl attribute

* fix: set bucket_id & object_id w/o NRN

* docs: Add documentation of object storage resources

* feat: Change format - make resource id with '/' in object storage - object

* feat: Add objectstorage_object_copy

* fix: Change to do not use pointer method

* docs: Add data source documentation of bucket

* docs: Add object_storage_object.md in data-source

* docs: Add object_storage_object_copy.md

* feat: Add CreationDate attribute to bucket

* fix: fix logic to check whether output is nil

* fix: Add format of creationDate

* feat: Delete panic from object_copy Update

* feat: Remove endpoint from Config struct

* fix: Remove Optional keyword from creation_date(computed)

* refactor: set bucket unique value from bucket_id to bucket_name

* fix: Remove unused headbucket

* feat: Add bucket ID (since it uses id for default)

* feat: Add attributes based on HeadObjectOutput

* feat: Add endpoint abstract logic

* refactor: Move post fetch logic into refreshFromOutput

* feat: Add genEndpointWithCode (region, site)

* feat: Add optional endpoint configuration

* feat: Add region formatting logic

* feat: Add Optional variables compatible with aws sdk in object-kind resource

* docs: Update docs with additional attributes

* fix: Remove Object Encryption logic entirely

* feat: Add site variable in example tf code

* chore: Add Error with Diagnostics

* refactor: remove endpoint from providerConfig

* chore: add missed packages

* fix: fix endpoint env to optional

* fix: Parse bucket info after pulling plan data

* refactor: Abstract BucketNameValidator

* fix: Remove optional from creation_date

* fix: Change serverless environment => platform independent

* fix: change id with object_url

* feat: Add attribute documentation

* feat: Add update logic to object_acl

* feat: Add update logic to bucket_acl

* fix: Fix typo

Revert "fix: Fix typo"

This reverts commit 37c7737.

fix: Fix typo
  • Loading branch information
Geun-Oh committed Sep 10, 2024
1 parent 55daed1 commit 38a96cc
Show file tree
Hide file tree
Showing 30 changed files with 3,631 additions and 116 deletions.
33 changes: 33 additions & 0 deletions docs/data-sources/object_storage_bucket.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
subcategory: "Object Storage"
---

# Data Source: ncloud_objectstorage_bucket

Prvides information about a bucket.

~> **NOTE:** This resource is platform independent. Does not need VPC configuration.

## Example Usage

```terraform
data "ncloud_objectstorage_bucket" "test-bucket" {
bucket_name = "your-bucket"
}
```

## Argument Reference

The following arguments are required:

* `id` - Unique ID for bucket. Since bucket name is already unique in specific region, ID is same as `bucket_name`.
* `bucket_name` - (Required) Bucket name to create. Bucket name must be between 3 and 63 characters long, can contain lowercase letters, numbers, periods, and hyphens. It must start and end with a letter or number, and cannot have consecutive periods.
* `creation_date` - Date of when this bucket created.

## Attribute Reference

This data source exports the following attributes in addition to the arguments above:

* `owner_id` - ID of target bucket owner.
* `owner_displayname` - Display name of target bucket owner.
* `creation_date` - Date information of when this bucket created.
46 changes: 46 additions & 0 deletions docs/data-sources/object_storage_object.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
subcategory: "Object Storage"
---

# Data Source: ncloud_objectstorage_object

Prvides information about a object.

~> **NOTE:** This resource is platform independent. Does not need VPC configuration.

## Example Usage

```terraform
data "ncloud_objectstorage_object" "test" {
object_id = ncloud_objectstorage_object.testing_object.id
}
```

## Argument Reference

The following arguments are required:

* `object_id` - (Required) Object id to get. same as "\${bucket_name}/${object_key}".

## Attribute Reference

~> **NOTE:** Since Ncloud Object Stroage uses S3 Compatible SDK, these arguments are served as best-effort.

This data source exports the following attributes in addition to the arguments above:

* `bucket` - Name of bucket where object belongs.
* `key` - Key of object.
* `source` - Path that informs where does object is located in bucket.
* `content_language` - Language the content is in e.g., en-US or en-GB.
* `content_length` - How long the object is.
* `content_type` - Type of the object.
* `body` - Saved content of the object.
* `bucket_key_enabled` - Whether this resource uses Ncloud KMS Keys for SSE.
* `content_encoding` - Content encodings that have been applied to the object and thus what decoding mechanisms must be applied to obtain the media-type referenced by the Content-Type header field. Read [w3c content encoding](https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11) for further information.
* `accept_ranges` - Indicates that a range of bytes was specified.
* `etag` - ETag generated for the object (an MD5 sum of the object content). For plaintext objects or objects encrypted with an AWS-managed key, the hash is an MD5 digest of the object data. For objects encrypted with a KMS key or objects created by either the Multipart Upload or Part Copy operation, the hash is not an MD5 digest, regardless of the method of encryption. More information on possible values can be found on [Common Response Headers](https://docs.aws.amazon.com/AmazonS3/latest/API/RESTCommonResponseHeaders.html).
* `expiration` - the object expiration is configured, the response includes this header. It includes the expiry-date and rule-id key-value pairs providing object expiration information. The value of the rule-id is URL-encoded.
* `last_modified` - Date and time when the object was last modified.
* `parts_count` - The count of parts this object has. This value is only returned if you specify partNumber in your request and the object was uploaded as a multipart upload.
* `version_id` - Unique version ID value for the object, if bucket versioning is enabled.
* `website_redirect_location` - Target URL for website redirect.
54 changes: 54 additions & 0 deletions docs/resources/object_storage_bucket.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
subcategory: "Object Storage"
---


# Resource: ncloud_objectstorage_bucket

Provides Object Storage Bucket service resource.

~> **NOTE:** This resource is platform independent. Does not need VPC configuration.

## Example Usage

```terraform
provider "ncloud" {
support_vpc = true
access_key = var.access_key
secret_key = var.secret_key
region = var.region
}
resource "ncloud_objectstorage_bucket" "testing_bucket" {
bucket_name = "your-bucket-name"
}
```

## Argument Reference

The following arguments are supported:

* `id` - Unique ID for bucket. Since bucket name is already unique in specific region, ID is same as `bucket_name`.
* `bucket_name` - (Required) Bucket name to create. Bucket name must be between 3 and 63 characters long, can contain lowercase letters, numbers, periods, and hyphens. It must start and end with a letter or number, and cannot have consecutive periods.
* `creation_date` - Date of when this bucket created.

## Import

### `terraform import` command

* Object Storage Bucket can be imported using the `bucket_name`. For example:

```console
$ terraform import ncloud_objectstorage_object.rsc_name bucket-name
```

### `import` block

* In Terraform v1.5.0 and later, use a [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Object Storage Bucket using the `id`. For example:

```terraform
import {
to = ncloud_objectstorage_object.rsc_name
bucket_name = "bucket-name"
}
```
61 changes: 61 additions & 0 deletions docs/resources/object_storage_bucket_acl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
subcategory: "Object Storage"
---


# Resource: ncloud_objectstorage_bucket_acl

Provides Object Storage Bucket ACL service resource.

~> **NOTE:** This resource is platform independent. Does not need VPC configuration.

## Example Usage

```terraform
provider "ncloud" {
support_vpc = true
access_key = var.access_key
secret_key = var.secret_key
region = var.region
}
resource "ncloud_objectstorage_bucket" "testing_bucket" {
bucket_name = "your-bucket-name"
}
resource "ncloud_objectstorage_bucket_acl" "testing_acl" {
bucket_name = ncloud_objectstorage_bucket.testing_bucket.bucket_name
rule = "RULL_TO_APPLY"
}
```

## Argument Reference

The following arguments are supported:

* `id` - Unique ID for bucket. Has format of `bucket_acl_${bucket_name}`.
* `bucket_name` - (Required) Target bucket id to create(same as bucket name). Bucket name must be between 3 and 63 characters long, can contain lowercase letters, numbers, periods, and hyphens. It must start and end with a letter or number, and cannot have consecutive periods.
* `rule` - (Required) Rule to apply. Value must be one of "private", "public-read", "public-read-write", "authenticated-read".
* `grants` - List of member who grants this rule. Consists of `grantee`, `permission`. Individual `grantee` has `type`, `display_name`, `email-address`, `id`, `uri` attributes.
* `owner` - Who owns this ACL.

## Import

### `terraform import` command

* Object Storage Bucket ACL can be imported using the `bucket_name`. For example:

```console
$ terraform import ncloud_objectstorage_bucket_acl.rsc_name bucket_acl_bucket-name
```

### `import` block

* In Terraform v1.5.0 and later, use a [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Object Storage Bucket ACL using the `id`. For example:

```terraform
import {
to = ncloud_objectstorage_bucket_acl.rsc_name
bucket_name = "bucket_acl_bucket-name"
}
```
82 changes: 82 additions & 0 deletions docs/resources/object_storage_object.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
subcategory: "Object Storage"
---


# Resource: ncloud_objectstorage_object

Provides Object Storage Object service resource.

~> **NOTE:** This resource is platform independent. Does not need VPC configuration.

## Example Usage

```terraform
provider "ncloud" {
support_vpc = true
access_key = var.access_key
secret_key = var.secret_key
region = var.region
}
resource "ncloud_objectstorage_bucket" "testing_bucket" {
bucket_name = "your-bucket-name"
}
resource "ncloud_objectstorage_object" "testing_object" {
bucket = ncloud_objectstorage_bucket.testing_bucket.bucket_name
key = "your-object-key"
source = "path/to/file"
}
```

## Argument Reference

The following arguments are required:

* `bucket` - (Required) Name of the bucket to read the object from. Bucket name must be between 3 and 63 characters long, can contain lowercase letters, numbers, periods, and hyphens. It must start and end with a letter or number, and cannot have consecutive periods.
* `key` - (Required) Full path to the object inside the bucket.
* `source` - (Required) Path to the file you want to upload.

The following arguments are optional:

* `bucket_key_enabled` - (Optional) Whether this resource uses Ncloud KMS Keys for SSE.
* `content_encoding` - (Optional) Content encodings that have been applied to the object and thus what decoding mechanisms must be applied to obtain the media-type referenced by the Content-Type header field. Read [w3c content encoding](https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11) for further information.
* `content_language` - (Optional) Language the content is in e.g., en-US or en-GB.
* `content_type` - (Optional) Standard MIME type describing the format of the object data, e.g., application/octet-stream. All Valid MIME Types are valid for this input.
* `website_redirect_location` - (Optional) Target URL for website redirect.

## Attribute Reference.

~> **NOTE:** Since Ncloud Object Stroage uses S3 Compatible SDK, these arguments are served as best-effort.

This resource exports the following attributes in addition to the arguments above:

* `accept_ranges` - Indicates that a range of bytes was specified.
* `content_length` - Size of the body in bytes.
* `etag` - ETag generated for the object (an MD5 sum of the object content). For plaintext objects or objects encrypted with an AWS-managed key, the hash is an MD5 digest of the object data. For objects encrypted with a KMS key or objects created by either the Multipart Upload or Part Copy operation, the hash is not an MD5 digest, regardless of the method of encryption. More information on possible values can be found on [Common Response Headers](https://docs.aws.amazon.com/AmazonS3/latest/API/RESTCommonResponseHeaders.html).
* `expiration` - the object expiration is configured, the response includes this header. It includes the expiry-date and rule-id key-value pairs providing object expiration information. The value of the rule-id is URL-encoded.
* `last_modified` - Date and time when the object was last modified.
* `parts_count` - The count of parts this object has. This value is only returned if you specify partNumber in your request and the object was uploaded as a multipart upload.
* `version_id` - Unique version ID value for the object, if bucket versioning is enabled.

## Import

### `terraform import` command

* Object Storage Object can be imported using the `id`. For example:

```console
$ terraform import ncloud_objectstorage_object.rsc_name bucket-name/key
```

### `import` block

* In Terraform v1.5.0 and later, use a [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Object Storage Object using the `id`. For example:

```terraform
import {
to = ncloud_objectstorage_object.rsc_name
id = "bucket-name/key"
}
```
68 changes: 68 additions & 0 deletions docs/resources/object_storage_object_acl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
subcategory: "Object Storage"
---


# Resource: ncloud_objectstorage_object_acl

Provides Object Storage Object ACL service resource.

~> **NOTE:** This resource is platform independent. Does not need VPC configuration.

## Example Usage

```terraform
provider "ncloud" {
support_vpc = true
access_key = var.access_key
secret_key = var.secret_key
region = var.region
}
resource "ncloud_objectstorage_bucket" "testing_bucket" {
bucket_name = "your-bucket-name"
}
resource "ncloud_objectstorage_object" "testing_object" {
bucket = ncloud_objectstorage_bucket.testing_bucket.bucket_name
key = "your-object-key"
source = "path/to/file"
}
resource "ncloud_objectstorage_object_acl" "testing_acl" {
object_id = ncloud_objectstorage_object.testing_object.id
rule = "RULL_TO_APPLY"
}
```

## Argument Reference

The following arguments are supported:

* `id` - Unique ID for ACL. Has format of `object_acl_${object_id}`.
* `object_id` - (Required) Target object id to create.
* `rule` - (Required) Rule to apply. Value must be one of "private", "public-read", "public-read-write", "authenticated-read".
* `grants` - List of member who grants this rule. Consists of `grantee`, `permission`. Individual `grantee` has `type`, `display_name`, `email-address`, `id`, `uri` attributes.
* `owner_id` - ID of owner.
* `owner_displayname` - Name of owner.

## Import

### `terraform import` command

* Object Storage Object ACL can be imported using the `id`. For example:

```console
$ terraform import ncloud_objectstorage_object_acl.rsc_name object_acl_objectID
```

### `import` block

* In Terraform v1.5.0 and later, use a [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Object Storage Bucket ACL using the `id`. For example:

```terraform
import {
to = ncloud_objectstorage_object_acl.rsc_name
id = "object_acl_objectID"
}
```
Loading

0 comments on commit 38a96cc

Please sign in to comment.