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: Add Object Storage Service to Terraform Provider #22

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
149 changes: 149 additions & 0 deletions commons/api_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package commons

import "fmt"

const ObjectStorageApiPrefix = "/v1/vmware/vpc"

var ApiPath = struct {
SSH string
Storage func(vpcId string) string
Expand Down Expand Up @@ -58,6 +60,49 @@ var ApiPath = struct {
ManagedFKEDelete func(vpcId string, platform string, clusterName string) string
ManagedFKECreate func(vpcId string, platform string) string
GetFKEOSVersion func(vpcId string, platform string) string

// Object Storage
// Common
CheckS3ServiceEnable func(vpcId string) string

// Bucket
ListBuckets func(vpcId, s3ServiceId string, page, pageSize int) string
CreateBucket func(vpcId, s3ServiceId string) string
DeleteBucket func(vpcId, s3ServiceId string) string
// Bucket Policy
GetBucketPolicy func(vpcId, s3ServiceId, bucketName string) string
PutBucketPolicy func(vpcId, s3ServiceId, bucketName string) string
// Bucket Static Website
GetBucketWebsite func(vpcId, s3ServiceId, bucketName string) string
PutBucketWebsite func(vpcId, s3ServiceId, bucketName string) string
DeleteBucketStaticWebsite func(vpcId, s3ServiceId, bucketName string) string
// Bucket Versioning
GetBucketVersioning func(vpcId, s3ServiceId, bucketName string) string
PutBucketVersioning func(vpcId, s3ServiceId, bucketName string) string
// Bucket Lifecycle
GetBucketLifecycle func(vpcId, s3ServiceId, bucketName string, page, pageSize int) string
PutBucketLifecycle func(vpcId, s3ServiceId, bucketName string) string
DeleteBucketLifecycle func(vpcId, s3ServiceId, bucketName string) string
// Bucket CORS
GetBucketCORS func(vpcId, s3ServiceId, bucketName string, page, pageSize int) string
PutBucketCORS func(vpcId, s3ServiceId, bucketName string) string
CreateBucketCors func(vpcId, s3ServiceId, bucketName string) string
// Bucket ACL
GetBucketAcl func(vpcId, s3ServiceId, bucketName string) string
PutBucketAcl func(vpcId, s3ServiceId, bucketName string) string

// Sub-user
ListSubUsers func(vpcId, s3ServiceId string, page, pageSize int) string
CreateSubUser func(vpcId, s3ServiceId string) string
UpdateSubUser func(vpcId, s3ServiceId, subUserId string) string
DeleteSubUser func(vpcId, s3ServiceId, subUserId string) string
DetailSubUser func(vpcId, s3ServiceId, subUserId string) string
CreateSubUserAccessKey func(vpcId, s3ServiceId, subUserId string) string
DeleteSubUserAccessKey func(vpcId, s3ServiceId, subUserId string) string
// Access Key
ListAccessKeys func(vpcId, s3ServiceId string) string
CreateAccessKey func(vpcId, s3ServiceId string) string
DeleteAccessKey func(vpcId, s3ServiceId string) string
}{
SSH: "/v1/user/sshs",
Storage: func(vpcId string) string {
Expand Down Expand Up @@ -219,4 +264,108 @@ var ApiPath = struct {
GetFKEOSVersion: func(vpcId string, platform string) string {
return fmt.Sprintf("/v1/xplat/fke/vpc/%s/m-fke/%s/get_k8s_versions", vpcId, platform)
},

// Object Storage
// Common
CheckS3ServiceEnable: func(vpcId string) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/check-service-enabled?check_unlimited=undefined", vpcId)
},

// Bucket
ListBuckets: func(vpcId, s3ServiceId string, page, pageSize int) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/buckets?page=%d&page_size=%d&s3_service_id=%s", vpcId, page, pageSize, s3ServiceId)
},
CreateBucket: func(vpcId, s3ServiceId string) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/%s/buckets/create", vpcId, s3ServiceId)
},

DeleteBucket: func(vpcId, s3ServiceId string) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/%s/buckets/delete", vpcId, s3ServiceId)
},

// Bucket Versioning
GetBucketVersioning: func(vpcId, s3ServiceId, bucketName string) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/%s/bucket/%s/get-versioning", vpcId, s3ServiceId, bucketName)
},
PutBucketVersioning: func(vpcId, s3ServiceId, bucketName string) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/%s/bucket/%s/put-versioning", vpcId, s3ServiceId, bucketName)
},
// Bucket Policy
GetBucketPolicy: func(vpcId, s3ServiceId, bucketName string) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/%s/bucket/%s/get-policy", vpcId, s3ServiceId, bucketName)
},
PutBucketPolicy: func(vpcId, s3ServiceId, bucketName string) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/%s/bucket/%s/put-policy", vpcId, s3ServiceId, bucketName)
},
// Bucket Static Website
GetBucketWebsite: func(vpcId, s3ServiceId, bucketName string) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/%s/bucket/%s/get-config", vpcId, s3ServiceId, bucketName)
},
PutBucketWebsite: func(vpcId, s3ServiceId, bucketName string) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/%s/bucket/%s/put-config", vpcId, s3ServiceId, bucketName)
},
DeleteBucketStaticWebsite: func(vpcId, s3ServiceId, bucketName string) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/%s/bucket/%s/delete-config", vpcId, s3ServiceId, bucketName)
},
// Bucket Lifecycle
GetBucketLifecycle: func(vpcId, s3ServiceId, bucketName string, page, pageSize int) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/%s/bucket/%s/lifecycles?page=%d&page_size=%d", vpcId, s3ServiceId, bucketName, page, pageSize)
},
PutBucketLifecycle: func(vpcId, s3ServiceId, bucketName string) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/%s/bucket/%s/create-bucket-lifecycle-configuration", vpcId, s3ServiceId, bucketName)
},
DeleteBucketLifecycle: func(vpcId, s3ServiceId, bucketName string) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/%s/bucket/%s/delete-bucket-lifecycle-configuration", vpcId, s3ServiceId, bucketName)
},
// Bucket CORS
GetBucketCORS: func(vpcId, s3ServiceId, bucketName string, page, pageSize int) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/%s/bucket/%s/cors?page=%d&page_size=%d", vpcId, s3ServiceId, bucketName, page, pageSize)
},
PutBucketCORS: func(vpcId, s3ServiceId, bucketName string) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/%s/bucket/%s/put-bucket-cors", vpcId, s3ServiceId, bucketName)
},
CreateBucketCors: func(vpcId, s3ServiceId, bucketName string) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/%s/bucket/%s/create-bucket-cors", vpcId, s3ServiceId, bucketName)
},
// Bucket ACL
GetBucketAcl: func(vpcId, s3ServiceId, bucketName string) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/%s/bucket/%s/acl", vpcId, s3ServiceId, bucketName)
},
PutBucketAcl: func(vpcId, s3ServiceId, bucketName string) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/%s/bucket/%s/acl", vpcId, s3ServiceId, bucketName)
},
// Sub-user
ListSubUsers: func(vpcId, serviceId string, page, pageSize int) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/%s/sub-users/list?page=%d&page_size=%d", vpcId, serviceId, page, pageSize)
},
CreateSubUser: func(vpcId, s3ServiceId string) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/%s/sub-users/create", vpcId, s3ServiceId)
},
UpdateSubUser: func(vpcId, s3ServiceId, subUserId string) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/sub-users/%s/update", vpcId, subUserId)
},
DeleteSubUser: func(vpcId, s3ServiceId, subUserId string) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/%s/sub-users/%s/delete", vpcId, s3ServiceId, subUserId)
},
DetailSubUser: func(vpcId, s3ServiceId, subUserId string) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/%s/sub-users/%s/detail", vpcId, s3ServiceId, subUserId)
},
// Sub-user Access Key
CreateSubUserAccessKey: func(vpcId, s3ServiceId, subUserId string) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/%s/sub-users/%s/credentials/create", vpcId, s3ServiceId, subUserId)
},
DeleteSubUserAccessKey: func(vpcId, s3ServiceId, subUserId string) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/%s/sub-users/%s/credentials/delete", vpcId, s3ServiceId, subUserId)
},

// Access Key
ListAccessKeys: func(vpcId, s3ServiceId string) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/user/credentials?s3_service_id=%s", vpcId, s3ServiceId)
},
CreateAccessKey: func(vpcId, s3ServiceId string) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/%s/user/credentials", vpcId, s3ServiceId)
},
DeleteAccessKey: func(vpcId, s3ServiceId string) string {
return fmt.Sprintf("/v1/vmware/vpc/%s/s3/%s/user/credentials/delete", vpcId, s3ServiceId)
},
}
1 change: 0 additions & 1 deletion commons/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ func (c *Client) SendDeleteRequest(requestURL string) ([]byte, error) {
if err != nil {
return nil, err
}

return c.SendRequest(req)
}

Expand Down
34 changes: 34 additions & 0 deletions docs/data-sources/object_storage_access_key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "fptcloud_object_storage_access_key Data Source - terraform-provider-fptcloud"
subcategory: ""
description: |-

---

# fptcloud_object_storage_access_key (Data Source)





<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `region_name` (String) The region name that's are the same with the region name in the S3 service. Currently, we have: HCM-01, HCM-02, HN-01, HN-02
- `vpc_id` (String)

### Read-Only

- `credentials` (List of Object) (see [below for nested schema](#nestedatt--credentials))
- `id` (String) The ID of this resource.

<a id="nestedatt--credentials"></a>
### Nested Schema for `credentials`

Read-Only:

- `access_key` (String)
- `active` (Boolean)
43 changes: 43 additions & 0 deletions docs/data-sources/object_storage_bucket.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "fptcloud_object_storage_bucket Data Source - terraform-provider-fptcloud"
subcategory: ""
description: |-

---

# fptcloud_object_storage_bucket (Data Source)





<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `region_name` (String) The region name that's are the same with the region name in the S3 service. Currently, we have: HCM-01, HCM-02, HN-01, HN-02
- `vpc_id` (String) The VPC ID

### Optional

- `page` (Number) Page number
- `page_size` (Number) Number of items per page

### Read-Only

- `id` (String) The ID of this resource.
- `list_bucket_result` (List of Object) (see [below for nested schema](#nestedatt--list_bucket_result))

<a id="nestedatt--list_bucket_result"></a>
### Nested Schema for `list_bucket_result`

Read-Only:

- `bucket_name` (String)
- `creation_date` (String)
- `endpoint` (String)
- `is_empty` (Boolean)
- `is_enabled_logging` (Boolean)
- `s3_service_id` (String)
64 changes: 64 additions & 0 deletions docs/data-sources/object_storage_bucket_acl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "fptcloud_object_storage_bucket_acl Data Source - terraform-provider-fptcloud"
subcategory: ""
description: |-

---

# fptcloud_object_storage_bucket_acl (Data Source)





<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `bucket_name` (String) Name of the bucket to config the ACL
- `region_name` (String) The region name that's are the same with the region name in the S3 service. Currently, we have: HCM-01, HCM-02, HN-01, HN-02
- `vpc_id` (String) The VPC ID

### Read-Only

- `bucket_acl` (List of Object) (see [below for nested schema](#nestedatt--bucket_acl))
- `canned_acl` (String) The Access Control List (ACL) status of the bucket which can be one of the following values: private, public-read, default is private
- `id` (String) The ID of this resource.
- `status` (Boolean) The status after configuring the bucket ACL

<a id="nestedatt--bucket_acl"></a>
### Nested Schema for `bucket_acl`

Read-Only:

- `grants` (List of Object) (see [below for nested schema](#nestedobjatt--bucket_acl--grants))
- `owner` (List of Object) (see [below for nested schema](#nestedobjatt--bucket_acl--owner))

<a id="nestedobjatt--bucket_acl--grants"></a>
### Nested Schema for `bucket_acl.grants`

Read-Only:

- `grantee` (List of Object) (see [below for nested schema](#nestedobjatt--bucket_acl--grants--grantee))
- `permission` (String)

<a id="nestedobjatt--bucket_acl--grants--grantee"></a>
### Nested Schema for `bucket_acl.grants.grantee`

Read-Only:

- `display_name` (String)
- `id` (String)
- `type` (String)



<a id="nestedobjatt--bucket_acl--owner"></a>
### Nested Schema for `bucket_acl.owner`

Read-Only:

- `display_name` (String)
- `id` (String)
44 changes: 44 additions & 0 deletions docs/data-sources/object_storage_bucket_cors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "fptcloud_object_storage_bucket_cors Data Source - terraform-provider-fptcloud"
subcategory: ""
description: |-

---

# fptcloud_object_storage_bucket_cors (Data Source)





<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `bucket_name` (String) Name of the bucket
- `region_name` (String) The region name that's are the same with the region name in the S3 service. Currently, we have: HCM-01, HCM-02, HN-01, HN-02
- `vpc_id` (String) The VPC ID

### Optional

- `page` (Number) The page number
- `page_size` (Number) The number of items to return in each page

### Read-Only

- `cors_rule` (List of Object) The bucket cors rule (see [below for nested schema](#nestedatt--cors_rule))
- `id` (String) The ID of this resource.

<a id="nestedatt--cors_rule"></a>
### Nested Schema for `cors_rule`

Read-Only:

- `allowed_headers` (List of String)
- `allowed_methods` (List of String)
- `allowed_origins` (List of String)
- `expose_headers` (List of String)
- `id` (String)
- `max_age_seconds` (Number)
Loading