Skip to content

Commit

Permalink
Merge pull request #154 from volcengine/feat/ecs
Browse files Browse the repository at this point in the history
Feat/ecs
  • Loading branch information
zpp12354321 authored Jan 2, 2024
2 parents 423600c + 7a000a3 commit ddc6d51
Show file tree
Hide file tree
Showing 23 changed files with 353 additions and 83 deletions.
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.133"
TerraformProviderVersion = "0.0.134"
)
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,6 @@ resource "volcengine_ecs_instance" "foo" {
}
}

resource "volcengine_ecs_instance" "foo1" {
instance_name = "acc-test-ecs-1"
description = "acc-test"
host_name = "tf-acc-test"
image_id = data.volcengine_images.foo.images[0].image_id
instance_type = "ecs.g1ie.large"
password = "93f0cb0614Aab12"
instance_charge_type = "PostPaid"
system_volume_type = "ESSD_PL0"
system_volume_size = 40
data_volumes {
volume_type = "ESSD_PL0"
size = 50
delete_with_instance = true
}
subnet_id = volcengine_subnet.foo.id
security_group_ids = [volcengine_security_group.foo.id]
project_name = "default"
tags {
key = "k1"
value = "v1"
}
}

resource "volcengine_iam_role" "foo" {
role_name = "acc-test-role"
display_name = "acc-test"
Expand Down
36 changes: 21 additions & 15 deletions example/rdsMysqlInstance/main.tf
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
data "volcengine_zones" "foo"{
data "volcengine_zones" "foo" {
}

resource "volcengine_vpc" "foo" {
vpc_name = "acc-test-project1"
vpc_name = "acc-test-project1"
cidr_block = "172.16.0.0/16"
}

resource "volcengine_subnet" "foo" {
subnet_name = "acc-subnet-test-2"
cidr_block = "172.16.0.0/24"
zone_id = data.volcengine_zones.foo.zones[0].id
vpc_id = volcengine_vpc.foo.id
cidr_block = "172.16.0.0/24"
zone_id = data.volcengine_zones.foo.zones[0].id
vpc_id = volcengine_vpc.foo.id
}

resource "volcengine_rds_mysql_instance" "foo" {
db_engine_version = "MySQL_5_7"
node_spec = "rds.mysql.1c2g"
primary_zone_id = data.volcengine_zones.foo.zones[0].id
secondary_zone_id = data.volcengine_zones.foo.zones[0].id
storage_space = 80
subnet_id = volcengine_subnet.foo.id
instance_name = "acc-test"
db_engine_version = "MySQL_5_7"
node_spec = "rds.mysql.1c2g"
primary_zone_id = data.volcengine_zones.foo.zones[0].id
secondary_zone_id = data.volcengine_zones.foo.zones[0].id
storage_space = 80
subnet_id = volcengine_subnet.foo.id
instance_name = "acc-test"
lower_case_table_names = "1"

charge_info {
charge_type = "PostPaid"
}

parameters {
parameter_name = "auto_increment_increment"
parameter_name = "auto_increment_increment"
parameter_value = "2"
}
parameters {
parameter_name = "auto_increment_offset"
parameter_name = "auto_increment_offset"
parameter_value = "4"
}
}

project_name = "default"
tags {
key = "k1"
value = "v1"
}
}
3 changes: 3 additions & 0 deletions volcengine/cr/cr_namespace/service_volcengine_cr_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ func (s *VolcengineCrNamespaceService) RemoveResource(resourceData *schema.Resou
logger.Debug(logger.ReqFormat, call.Action, call.SdkParam)
return s.Client.UniversalClient.DoCall(getUniversalInfo(call.Action), call.SdkParam)
},
AfterCall: func(d *schema.ResourceData, client *ve.SdkClient, resp *map[string]interface{}, call ve.SdkCall) error {
return ve.CheckResourceUtilRemoved(d, s.ReadResource, 3*time.Minute)
},
},
}
return []ve.Callback{callback}
Expand Down
8 changes: 8 additions & 0 deletions volcengine/cr/cr_registry/service_volcengine_cr_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,14 @@ func (s *VolcengineCrRegistryService) RemoveResource(resourceData *schema.Resour
logger.Debug(logger.ReqFormat, call.Action, call.SdkParam)
return s.Client.UniversalClient.DoCall(getUniversalInfo(call.Action), call.SdkParam)
},
AfterCall: func(d *schema.ResourceData, client *ve.SdkClient, resp *map[string]interface{}, call ve.SdkCall) error {
deleteImmediately := d.Get("delete_immediately").(bool)
// 如选择立即销毁,则进行removed检查
if deleteImmediately {
return ve.CheckResourceUtilRemoved(d, s.ReadResource, 5*time.Minute)
}
return nil
},
},
}
return []ve.Callback{callback}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ func (s *VolcengineCrRepositoryService) RemoveResource(resourceData *schema.Reso
logger.Debug(logger.ReqFormat, call.Action, call.SdkParam)
return s.Client.UniversalClient.DoCall(getUniversalInfo(call.Action), call.SdkParam)
},
AfterCall: func(d *schema.ResourceData, client *ve.SdkClient, resp *map[string]interface{}, call ve.SdkCall) error {
return ve.CheckResourceUtilRemoved(d, s.ReadResource, 3*time.Minute)
},
},
}
return []ve.Callback{callback}
Expand Down
3 changes: 3 additions & 0 deletions volcengine/cr/cr_tag/service_volcengine_cr_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ func (s *VolcengineCrTagService) RemoveResource(resourceData *schema.ResourceDat
logger.Debug(logger.ReqFormat, call.Action, call.SdkParam)
return s.Client.UniversalClient.DoCall(getUniversalInfo(call.Action), call.SdkParam)
},
AfterCall: func(d *schema.ResourceData, client *ve.SdkClient, resp *map[string]interface{}, call ve.SdkCall) error {
return ve.CheckResourceUtilRemoved(d, s.ReadResource, 3*time.Minute)
},
},
}
return []ve.Callback{callback}
Expand Down
24 changes: 22 additions & 2 deletions volcengine/ecs/ecs_instance/resource_volcengine_ecs_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,29 @@ func ResourceVolcengineEcsInstance() *schema.Resource {
Schema: map[string]*schema.Schema{
"threads_per_core": {
Type: schema.TypeInt,
Required: true,
Optional: true,
Computed: true,
ForceNew: true,
Description: "The per core of threads, only support for ebm. `1` indicates disabling hyper threading function.",
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
//暂时增加这个逻辑 在不包含ebm的情况下 忽略掉这个变化 目前这个方式比较hack 后续接口能力完善后改变一下
if it, ok := d.Get("instance_type").(string); ok {
its := strings.Split(it, ".")
if len(its) == 3 && !strings.Contains(strings.ToLower(its[1]), "ebm") {
return true
} else {
return false
}
} else {
return true
}
},
},
"numa_per_socket": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Description: "The per core of threads,only support for ebm.",
Description: "The number of subnuma in socket, only support for ebm. `1` indicates disabling SNC/NPS function. When importing resources, this attribute will not be imported. If this attribute is set, please use lifecycle and ignore_changes ignore changes in fields.",
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
//暂时增加这个逻辑 在不包含ebm的情况下 忽略掉这个变化 目前这个方式比较hack 后续接口能力完善后改变一下
if it, ok := d.Get("instance_type").(string); ok {
Expand Down
14 changes: 14 additions & 0 deletions volcengine/ecs/ecs_instance/service_volcengine_ecs_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,17 @@ func (s *VolcengineEcsService) ReadResource(resourceData *schema.ResourceData, i
if len(data) == 0 {
return data, fmt.Errorf("Ecs Instance %s not exist ", instanceId)
}

if numa := resourceData.Get("cpu_options.0.numa_per_socket"); numa != 0 {
if v, exist := data["CpuOptions"]; exist {
cpuOptions, ok := v.(map[string]interface{})
if !ok {
return data, fmt.Errorf("CpuOptions is not map ")
}
cpuOptions["NumaPerSocket"] = numa
}
}

return data, nil
}

Expand Down Expand Up @@ -440,6 +451,9 @@ func (s *VolcengineEcsService) CreateResource(resourceData *schema.ResourceData,
"threads_per_core": {
TargetField: "ThreadsPerCore",
},
"numa_per_socket": {
TargetField: "NumaPerSocket",
},
},
},
"secondary_network_interfaces": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import (
"github.com/volcengine/terraform-provider-volcengine/logger"
)

type VolcenginePrivateLinkVpcEndpointConnection struct {
type VolcenginePrivateLinkVpcEndpointConnectionService struct {
Client *ve.SdkClient
}

func (v *VolcenginePrivateLinkVpcEndpointConnection) GetClient() *ve.SdkClient {
func (v *VolcenginePrivateLinkVpcEndpointConnectionService) GetClient() *ve.SdkClient {
return v.Client
}

func (v *VolcenginePrivateLinkVpcEndpointConnection) ReadResources(m map[string]interface{}) (data []interface{}, err error) {
func (v *VolcenginePrivateLinkVpcEndpointConnectionService) ReadResources(m map[string]interface{}) (data []interface{}, err error) {
var (
resp *map[string]interface{}
results interface{}
Expand Down Expand Up @@ -55,7 +55,7 @@ func (v *VolcenginePrivateLinkVpcEndpointConnection) ReadResources(m map[string]
})
}

func (v *VolcenginePrivateLinkVpcEndpointConnection) ReadResource(resourceData *schema.ResourceData, id string) (data map[string]interface{}, err error) {
func (v *VolcenginePrivateLinkVpcEndpointConnectionService) ReadResource(resourceData *schema.ResourceData, id string) (data map[string]interface{}, err error) {
var (
results []interface{}
ok bool
Expand Down Expand Up @@ -86,7 +86,7 @@ func (v *VolcenginePrivateLinkVpcEndpointConnection) ReadResource(resourceData *
return data, nil
}

func (v *VolcenginePrivateLinkVpcEndpointConnection) RefreshResourceState(resourceData *schema.ResourceData, target []string, timeout time.Duration, id string) *resource.StateChangeConf {
func (v *VolcenginePrivateLinkVpcEndpointConnectionService) RefreshResourceState(resourceData *schema.ResourceData, target []string, timeout time.Duration, id string) *resource.StateChangeConf {
return &resource.StateChangeConf{
Pending: []string{},
Delay: 1 * time.Second,
Expand Down Expand Up @@ -119,11 +119,11 @@ func (v *VolcenginePrivateLinkVpcEndpointConnection) RefreshResourceState(resour
}
}

func (v *VolcenginePrivateLinkVpcEndpointConnection) WithResourceResponseHandlers(m map[string]interface{}) []ve.ResourceResponseHandler {
func (v *VolcenginePrivateLinkVpcEndpointConnectionService) WithResourceResponseHandlers(m map[string]interface{}) []ve.ResourceResponseHandler {
return nil
}

func (v *VolcenginePrivateLinkVpcEndpointConnection) CreateResource(data *schema.ResourceData, resource *schema.Resource) []ve.Callback {
func (v *VolcenginePrivateLinkVpcEndpointConnectionService) CreateResource(data *schema.ResourceData, resource *schema.Resource) []ve.Callback {
callback := ve.Callback{
Call: ve.SdkCall{
Action: "EnableVpcEndpointConnection",
Expand All @@ -146,11 +146,11 @@ func (v *VolcenginePrivateLinkVpcEndpointConnection) CreateResource(data *schema
return []ve.Callback{callback}
}

func (v *VolcenginePrivateLinkVpcEndpointConnection) ModifyResource(data *schema.ResourceData, resource *schema.Resource) []ve.Callback {
func (v *VolcenginePrivateLinkVpcEndpointConnectionService) ModifyResource(data *schema.ResourceData, resource *schema.Resource) []ve.Callback {
return nil
}

func (v *VolcenginePrivateLinkVpcEndpointConnection) RemoveResource(resourceData *schema.ResourceData, resource *schema.Resource) []ve.Callback {
func (v *VolcenginePrivateLinkVpcEndpointConnectionService) RemoveResource(resourceData *schema.ResourceData, resource *schema.Resource) []ve.Callback {
callback := ve.Callback{
Call: ve.SdkCall{
Action: "DisableVpcEndpointConnection",
Expand All @@ -172,7 +172,7 @@ func (v *VolcenginePrivateLinkVpcEndpointConnection) RemoveResource(resourceData
return []ve.Callback{callback}
}

func (v *VolcenginePrivateLinkVpcEndpointConnection) DatasourceResources(data *schema.ResourceData, resource *schema.Resource) ve.DataSourceInfo {
func (v *VolcenginePrivateLinkVpcEndpointConnectionService) DatasourceResources(data *schema.ResourceData, resource *schema.Resource) ve.DataSourceInfo {
return ve.DataSourceInfo{
CollectField: "connections",
ResponseConverts: map[string]ve.ResponseConvert{
Expand All @@ -183,12 +183,12 @@ func (v *VolcenginePrivateLinkVpcEndpointConnection) DatasourceResources(data *s
}
}

func (v *VolcenginePrivateLinkVpcEndpointConnection) ReadResourceId(s string) string {
func (v *VolcenginePrivateLinkVpcEndpointConnectionService) ReadResourceId(s string) string {
return s
}

func NewVpcEndpointConnectionService(c *ve.SdkClient) *VolcenginePrivateLinkVpcEndpointConnection {
return &VolcenginePrivateLinkVpcEndpointConnection{
func NewVpcEndpointConnectionService(c *ve.SdkClient) *VolcenginePrivateLinkVpcEndpointConnectionService {
return &VolcenginePrivateLinkVpcEndpointConnectionService{
Client: c,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ VpcEndpointService can be imported using the id, e.g.
```
$ terraform import volcengine_privatelink_vpc_endpoint_service.default epsvc-2fe630gurkl37k5gfuy33****
```
It is recommended to bind resources using the resources' field in this resource instead of using vpc_endpoint_service_resource.
For operations that jointly use this resource and vpc_endpoint_service_resource, use lifecycle ignore_changes to suppress changes to the resources field.
*/

func ResourceVolcenginePrivatelinkVpcEndpointService() *schema.Resource {
Expand Down Expand Up @@ -48,10 +49,13 @@ func ResourceVolcenginePrivatelinkVpcEndpointService() *schema.Resource {
},
// 创建 service 时候,必须传入一个 resource;在修改 resource 的时候,必须保留一个,不能全部删除
"resources": {
Type: schema.TypeSet,
Required: true,
Description: "The resources info. When create vpc endpoint service, the resource must exist.",
Set: resourceHash,
Type: schema.TypeSet,
Required: true,
Description: "The resources info. When create vpc endpoint service, the resource must exist. " +
"It is recommended to bind resources using the resources' field in this resource instead of " +
"using vpc_endpoint_service_resource. For operations that jointly use this resource and vpc_endpoint_service_resource, " +
"use lifecycle ignore_changes to suppress changes to the resources field.",
Set: resourceHash,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"resource_type": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ VpcEndpointServiceResource can be imported using the serviceId:resourceId, e.g.
```
$ terraform import volcengine_privatelink_vpc_endpoint_service_resource.default epsvc-2fe630gurkl37k5gfuy33****:clb-bp1o94dp5i6ea****
```
It is not recommended to use this resource for binding resources, it is recommended to use the resources field of vpc_endpoint_service for binding.
If using this resource and vpc_endpoint_service jointly for operations, use lifecycle ignore_changes to suppress changes to the resources field in vpc_endpoint_service.
*/

func ResourceVolcenginePrivatelinkVpcEndpointServiceResource() *schema.Resource {
Expand Down Expand Up @@ -45,10 +46,13 @@ func ResourceVolcenginePrivatelinkVpcEndpointServiceResource() *schema.Resource
},
Schema: map[string]*schema.Schema{
"resource_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The id of resource.",
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The id of resource. It is not recommended to use this resource for binding resources, " +
"it is recommended to use the resources field of vpc_endpoint_service for binding. " +
"If using this resource and vpc_endpoint_service jointly for operations, " +
"use lifecycle ignore_changes to suppress changes to the resources field in vpc_endpoint_service.",
},
"service_id": {
Type: schema.TypeString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ func DataSourceVolcengineRdsMysqlInstances() *schema.Resource {
Description: "The charge type of the RDS instance.",
ValidateFunc: validation.StringInSlice([]string{"PostPaid", "PrePaid"}, false),
},
"tags": ve.TagsSchema(),

"rds_mysql_instances": {
Description: "The collection of RDS instance query.",
Type: schema.TypeList,
Expand Down Expand Up @@ -188,6 +190,12 @@ func DataSourceVolcengineRdsMysqlInstances() *schema.Resource {
Computed: true,
Description: "The version of allow list.",
},
"project_name": {
Type: schema.TypeString,
Computed: true,
Description: "The project name of the RDS instance.",
},
"tags": ve.TagsSchemaComputed(),
"charge_detail": {
Type: schema.TypeList,
Computed: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ func ResourceVolcengineRdsMysqlInstance() *schema.Resource {
ForceNew: true,
Description: "Time zone. Support UTC -12:00 ~ +13:00. When importing resources, this attribute will not be imported. If this attribute is set, please use lifecycle and ignore_changes ignore changes in fields.",
},
"project_name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The project name of the RDS instance.",
},
"tags": ve.TagsSchema(),
"charge_info": {
Type: schema.TypeList,
MaxItems: 1,
Expand Down
Loading

0 comments on commit ddc6d51

Please sign in to comment.