Skip to content

Commit

Permalink
Merge pull request #119 from volcengine/feat/cfs
Browse files Browse the repository at this point in the history
Feat/cfs
  • Loading branch information
zpp12354321 authored Aug 28, 2023
2 parents d2d51df + 9144e6d commit 49ff97a
Show file tree
Hide file tree
Showing 34 changed files with 2,652 additions and 1 deletion.
2 changes: 1 addition & 1 deletion common/common_volcengine_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package common

const (
TerraformProviderName = "terraform-provider-volcengine"
TerraformProviderVersion = "0.0.101"
TerraformProviderVersion = "0.0.102"
)
1 change: 1 addition & 0 deletions docgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ var resourceKeys = map[string]string{
"privatelink": "PRIVATELINK",
"redis": "REDIS",
"tls": "TLS",
"cloudfs": "CLOUDFS",
}

type Products struct {
Expand Down
7 changes: 7 additions & 0 deletions example/cloudfsAccess/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "volcengine_cloudfs_access" "foo1" {
fs_name = "tftest2"

subnet_id = "subnet-13fca1crr5d6o3n6nu46cyb5m"
security_group_id = "sg-rrv1klfg5s00v0x578mx14m"
vpc_route_enabled = false
}
31 changes: 31 additions & 0 deletions example/cloudfsFileSystem/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
resource "volcengine_cloudfs_file_system" "foo" {
fs_name = "tffile"
zone_id = "cn-beijing-b"
cache_plan = "T2"
mode = "HDFS_MODE"
read_only = true

subnet_id = "subnet-13fca1crr5d6o3n6nu46cyb5m"
security_group_id = "sg-rrv1klfg5s00v0x578mx14m"
cache_capacity_tib = 10
vpc_route_enabled = true

tos_bucket = "tfacc"
tos_prefix = "pre/"
}


resource "volcengine_cloudfs_file_system" "foo1" {
fs_name = "tffileu"
zone_id = "cn-beijing-b"
cache_plan = "T2"
mode = "ACC_MODE"
read_only = true

subnet_id = "subnet-13fca1crr5d6o3n6nu46cyb5m"
security_group_id = "sg-rrv1klfg5s00v0x578mx14m"
cache_capacity_tib = 15
vpc_route_enabled = false

tos_bucket = "tfacc"
}
5 changes: 5 additions & 0 deletions example/cloudfsNamespace/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "volcengine_cloudfs_namespace" "foo" {
fs_name = "tf-test-fs"
tos_bucket = "tf-test"
read_only = true
}
3 changes: 3 additions & 0 deletions example/dataCloudfsAccesses/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "volcengine_cloudfs_accesses" "default" {
fs_name = "tftest2"
}
3 changes: 3 additions & 0 deletions example/dataCloudfsFileSystems/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "volcengine_cloudfs_file_systems" "default" {
fs_name = "tftest2"
}
4 changes: 4 additions & 0 deletions example/dataCloudfsNamespaces/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
data "volcengine_cloudfs_namespaces" "default" {
fs_name = "tf-test-fs"
ns_id = "1801439850948****"
}
3 changes: 3 additions & 0 deletions example/dataCloudfsNsQuotas/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "volcengine_cloudfs_ns_quotas" "default" {
fs_names = ["tffile", "tftest2"]
}
2 changes: 2 additions & 0 deletions example/dataCloudfsQuotas/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
data "volcengine_cloudfs_quotas" "default" {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package cloudfs_access

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
ve "github.com/volcengine/terraform-provider-volcengine/common"
)

func DataSourceVolcengineCloudfsAccesses() *schema.Resource {
return &schema.Resource{
Read: dataSourceVolcengineCloudfsAccessesRead,
Schema: map[string]*schema.Schema{
"fs_name": {
Type: schema.TypeString,
Required: true,
Description: "The name of file system.",
},
"output_file": {
Type: schema.TypeString,
Optional: true,
Description: "File name where to save data source results.",
},
"total_count": {
Type: schema.TypeInt,
Computed: true,
Description: "The total count of query.",
},
"accesses": {
Description: "The collection of query.",
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"fs_name": {
Type: schema.TypeString,
Computed: true,
Description: "The name of cloud fs.",
},
"access_id": {
Type: schema.TypeString,
Computed: true,
Description: "The id of access.",
},
"access_account_id": {
Type: schema.TypeInt,
Computed: true,
Description: "The account id of access.",
},
"access_service_name": {
Type: schema.TypeString,
Computed: true,
Description: "The service name of access.",
},
"vpc_id": {
Type: schema.TypeString,
Computed: true,
Description: "The id of vpc.",
},
"subnet_id": {
Type: schema.TypeString,
Computed: true,
Description: "The id of subnet.",
},
"security_group_id": {
Type: schema.TypeString,
Computed: true,
Description: "The id of security group.",
},
"is_default": {
Type: schema.TypeBool,
Computed: true,
Description: "Whether is default access.",
},
"created_time": {
Type: schema.TypeString,
Computed: true,
Description: "The creation time.",
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "The status of access.",
},
"vpc_route_enabled": {
Type: schema.TypeBool,
Computed: true,
Description: "Whether to enable all vpc route.",
},
},
},
},
},
}
}

func dataSourceVolcengineCloudfsAccessesRead(d *schema.ResourceData, meta interface{}) error {
service := NewService(meta.(*ve.SdkClient))
return ve.DefaultDispatcher().Data(service, d, DataSourceVolcengineCloudfsAccesses())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package cloudfs_access

import (
"fmt"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
ve "github.com/volcengine/terraform-provider-volcengine/common"
)

/*
Import
CloudFs Access can be imported using the FsName:AccessId, e.g.
```
$ terraform import volcengine_cloudfs_file_system.default tfname:access-**rdgmedx3fow
```
*/

func ResourceVolcengineCloudfsAccess() *schema.Resource {
resource := &schema.Resource{
Create: resourceVolcengineCloudfsAccessCreate,
Read: resourceVolcengineCloudfsAccessRead,
Update: resourceVolcengineCloudfsAccessUpdate,
Delete: resourceVolcengineCloudfsAccessDelete,
Importer: &schema.ResourceImporter{
State: func(data *schema.ResourceData, i interface{}) ([]*schema.ResourceData, error) {
items := strings.Split(data.Id(), ":")
if len(items) != 2 {
return []*schema.ResourceData{data}, fmt.Errorf("import id must split with ':'")
}
if err := data.Set("fs_name", items[0]); err != nil {
return []*schema.ResourceData{data}, err
}
if err := data.Set("access_id", items[1]); err != nil {
return []*schema.ResourceData{data}, err
}
return []*schema.ResourceData{data}, nil
},
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(30 * time.Minute),
Update: schema.DefaultTimeout(30 * time.Minute),
Delete: schema.DefaultTimeout(30 * time.Minute),
},
Schema: map[string]*schema.Schema{
"fs_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The name of file system.",
},
"access_account_id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ForceNew: true,
Description: "The account id of access.",
},
"access_iam_role": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "The iam role of access. If the VPC of another account is attached, " +
"the other account needs to create a role with CFSCacheAccess permission, " +
"and enter the role name as a parameter.",
},
"subnet_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The id of subnet.",
},
"security_group_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The id of security group.",
},
"vpc_route_enabled": {
Type: schema.TypeBool,
Optional: true,
Description: "Whether enable all vpc route.",
},

"status": {
Type: schema.TypeString,
Computed: true,
Description: "Status of access.",
},
"created_time": {
Type: schema.TypeString,
Computed: true,
Description: "The creation time.",
},
"is_default": {
Type: schema.TypeBool,
Computed: true,
Description: "Whether is default access.",
},
"access_service_name": {
Type: schema.TypeString,
Computed: true,
Description: "The service name of access.",
},
"vpc_id": {
Type: schema.TypeString,
Computed: true,
Description: "The id of vpc.",
},
"access_id": {
Type: schema.TypeString,
Computed: true,
Description: "The id of access.",
},
},
}
return resource
}

func resourceVolcengineCloudfsAccessCreate(d *schema.ResourceData, meta interface{}) (err error) {
service := NewService(meta.(*ve.SdkClient))
err = ve.DefaultDispatcher().Create(service, d, ResourceVolcengineCloudfsAccess())
if err != nil {
return fmt.Errorf("error on creating access %q, %s", d.Id(), err)
}
return resourceVolcengineCloudfsAccessRead(d, meta)
}

func resourceVolcengineCloudfsAccessRead(d *schema.ResourceData, meta interface{}) (err error) {
service := NewService(meta.(*ve.SdkClient))
err = ve.DefaultDispatcher().Read(service, d, ResourceVolcengineCloudfsAccess())
if err != nil {
return fmt.Errorf("error on reading access %q, %s", d.Id(), err)
}
return err
}

func resourceVolcengineCloudfsAccessUpdate(d *schema.ResourceData, meta interface{}) (err error) {
service := NewService(meta.(*ve.SdkClient))
err = ve.DefaultDispatcher().Update(service, d, ResourceVolcengineCloudfsAccess())
if err != nil {
return fmt.Errorf("error on updating access %q, %s", d.Id(), err)
}
return resourceVolcengineCloudfsAccessRead(d, meta)
}

func resourceVolcengineCloudfsAccessDelete(d *schema.ResourceData, meta interface{}) (err error) {
service := NewService(meta.(*ve.SdkClient))
err = ve.DefaultDispatcher().Delete(service, d, ResourceVolcengineCloudfsAccess())
if err != nil {
return fmt.Errorf("error on deleting access %q, %s", d.Id(), err)
}
return err
}
Loading

0 comments on commit 49ff97a

Please sign in to comment.