Skip to content

Commit

Permalink
Merge pull request #141 from volcengine/feat/vke_as
Browse files Browse the repository at this point in the history
Feat/vke as
  • Loading branch information
zpp12354321 committed Nov 6, 2023
2 parents 21b5bde + 2989753 commit f39e8c4
Show file tree
Hide file tree
Showing 25 changed files with 904 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.121"
TerraformProviderVersion = "0.0.122"
)
45 changes: 29 additions & 16 deletions example/scalingLifecycleHook/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
data "volcengine_zones" "foo" {
data "volcengine_zones" "foo"{
}

resource "volcengine_vpc" "foo" {
Expand All @@ -8,26 +8,39 @@ resource "volcengine_vpc" "foo" {

resource "volcengine_subnet" "foo" {
subnet_name = "acc-test-subnet"
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_ecs_command" "foo" {
name = "acc-test-command"
description = "tf"
working_dir = "/home"
username = "root"
timeout = 100
command_content = "IyEvYmluL2Jhc2gKCgplY2hvICJvcGVyYXRpb24gc3VjY2VzcyEi"
}

resource "volcengine_scaling_group" "foo" {
scaling_group_name = "acc-test-scaling-group-lifecycle"
subnet_ids = [volcengine_subnet.foo.id]
multi_az_policy = "BALANCE"
desire_instance_number = 0
min_instance_number = 0
max_instance_number = 1
scaling_group_name = "acc-test-scaling-group-lifecycle"
subnet_ids = ["${volcengine_subnet.foo.id}"]
multi_az_policy = "BALANCE"
desire_instance_number = 0
min_instance_number = 0
max_instance_number = 1
instance_terminate_policy = "OldestInstance"
default_cooldown = 10
default_cooldown = 10
}

resource "volcengine_scaling_lifecycle_hook" "foo" {
lifecycle_hook_name = "acc-test-lifecycle"
lifecycle_hook_policy = "CONTINUE"
lifecycle_hook_timeout = 30
lifecycle_hook_type = "SCALE_IN"
scaling_group_id = volcengine_scaling_group.foo.id
lifecycle_hook_name = "acc-test-lifecycle"
lifecycle_hook_policy = "ROLLBACK"
lifecycle_hook_timeout = 300
lifecycle_hook_type = "SCALE_OUT"
scaling_group_id = "${volcengine_scaling_group.foo.id}"
# lifecycle_command {
# command_id = volcengine_ecs_command.foo.id
# parameters = "{}"
# }
}
8 changes: 4 additions & 4 deletions example/vkeNodePool/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ resource "volcengine_vke_node_pool" "foo" {
image_id = [for image in data.volcengine_images.foo.images : image.image_id if image.image_name == "veLinux 1.0 CentOS兼容版 64位"][0]
system_volume {
type = "ESSD_PL0"
size = "60"
size = 80
}
data_volumes {
type = "ESSD_PL0"
size = "60"
size = 80
mount_point = "/tf1"
}
data_volumes {
type = "ESSD_PL0"
size = "60"
size = 60
mount_point = "/tf2"
}
initialize_script = "ZWNobyBoZWxsbyB0ZXJyYWZvcm0h"
Expand All @@ -89,7 +89,7 @@ resource "volcengine_vke_node_pool" "foo" {
security_strategies = ["Hids"]
security_group_ids = [volcengine_security_group.foo.id]
}
additional_container_storage_enabled = true
additional_container_storage_enabled = false
instance_charge_type = "PostPaid"
name_prefix = "acc-test"
ecs_tags {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ func DataSourceVolcengineScalingConfigurations() *schema.Resource {
Computed: true,
Description: "The preemption policy of the instance. Valid Value: NoSpot (default), SpotAsPriceGo.",
},
"ipv6_address_count": {
Type: schema.TypeInt,
Computed: true,
Description: "Assign IPv6 address to instance network card. Possible values:\n0: Do not assign IPv6 address.\n1: Assign IPv6 address and the system will automatically assign an IPv6 subnet for you.",
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ func ResourceVolcengineScalingConfiguration() *schema.Resource {
"SpotAsPriceGo",
}, false),
},
"ipv6_address_count": {
Type: schema.TypeInt,
Optional: true,
Description: "Assign IPv6 address to instance network card. Possible values:\n0: Do not assign IPv6 address.\n1: Assign IPv6 address and the system will automatically assign an IPv6 subnet for you.",
},
},
}
dataSource := DataSourceVolcengineScalingConfigurations().Schema["scaling_configurations"].Elem.(*schema.Resource).Schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ resource "volcengine_security_group" "foo" {
data "volcengine_images" "foo" {
os_type = "Linux"
visibility = "public"
instance_type_id = "ecs.g1.large"
instance_type_id = "ecs.g2i.large"
}
resource "volcengine_scaling_group" "foo" {
Expand All @@ -48,7 +48,7 @@ resource "volcengine_scaling_group" "foo" {
resource "volcengine_scaling_configuration" "foo" {
image_id = "${data.volcengine_images.foo.images[0].image_id}"
instance_name = "acc-test-instance"
instance_types = ["ecs.g1.large"]
instance_types = ["ecs.g2i.large"]
password = "93f0cb0614Aab12"
scaling_configuration_name = "acc-test-scaling-config"
scaling_group_id = "${volcengine_scaling_group.foo.id}"
Expand Down Expand Up @@ -85,7 +85,7 @@ resource "volcengine_security_group" "foo" {
data "volcengine_images" "foo" {
os_type = "Linux"
visibility = "public"
instance_type_id = "ecs.g1.large"
instance_type_id = "ecs.g2i.large"
}
resource "volcengine_scaling_group" "foo" {
Expand All @@ -102,7 +102,7 @@ resource "volcengine_scaling_group" "foo" {
resource "volcengine_scaling_configuration" "foo" {
image_id = "${data.volcengine_images.foo.images[0].image_id}"
instance_name = "acc-test-instance-new"
instance_types = ["ecs.g1.large"]
instance_types = ["ecs.g2i.large"]
password = "93f0cb0614Aab12"
scaling_configuration_name = "acc-test-scaling-config-new"
scaling_group_id = "${volcengine_scaling_group.foo.id}"
Expand All @@ -123,6 +123,7 @@ resource "volcengine_scaling_configuration" "foo" {
key = "k1"
value = "v1"
}
ipv6_address_count = 0
}
`

Expand Down Expand Up @@ -221,6 +222,7 @@ func TestAccVolcengineScalingConfigurationResource_Update(t *testing.T) {
resource.TestCheckResourceAttr(acc.ResourceId, "volumes.1.size", "100"),
resource.TestCheckResourceAttr(acc.ResourceId, "volumes.1.delete_with_instance", "true"),
resource.TestCheckResourceAttr(acc.ResourceId, "tags.#", "1"),
resource.TestCheckResourceAttr(acc.ResourceId, "ipv6_address_count", "0"),
volcengine.TestCheckTypeSetElemNestedAttrs(acc.ResourceId, "tags.*", map[string]string{
"key": "k1",
"value": "v1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ func (s *VolcengineScalingConfigurationService) ModifyResource(resourceData *sch
"hpc_cluster_id": {
ConvertType: ve.ConvertDefault,
},
"ipv6_address_count": {
ConvertType: ve.ConvertDefault,
},
},
RequestIdField: "ScalingConfigurationId",
BeforeCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (bool, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ func DataSourceVolcengineScalingGroups() *schema.Resource {
ValidateFunc: validation.StringIsValidRegExp,
Description: "A Name Regex of scaling group.",
},
"project_name": {
Type: schema.TypeString,
Optional: true,
Description: "The project name of the scaling group.",
},
"output_file": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -186,6 +191,45 @@ func DataSourceVolcengineScalingGroups() *schema.Resource {
Description: "The ProjectName of scaling group.",
},
"tags": ve.TagsSchemaComputed(),
"scaling_mode": {
Type: schema.TypeString,
Computed: true,
Description: "The scaling mode of the scaling group.",
},
"stopped_instance_count": {
Type: schema.TypeInt,
Computed: true,
Description: "The number of stopped instances.",
},
"health_check_type": {
Type: schema.TypeString,
Computed: true,
Description: "The health check type of the scaling group.",
},
"load_balancer_health_check_grace_period": {
Type: schema.TypeInt,
Computed: true,
Description: "Grace period for health check of CLB instance in elastic group.",
},
"launch_template_overrides": {
Type: schema.TypeList,
Computed: true,
Description: "Instance start template information.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"instance_type": {
Type: schema.TypeString,
Computed: true,
Description: "The instance type.",
},
"weighted_capacity": {
Type: schema.TypeInt,
Computed: true,
Description: "Weight of instance specifications.",
},
},
},
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,41 @@ func ResourceVolcengineScalingGroup() *schema.Resource {
Optional: true,
Description: "The version of the launch template bound to the scaling group. Valid values are the version number, Latest, or Default.",
},
"launch_template_overrides": {
Type: schema.TypeSet,
Description: "Specify instance specifications.",
Optional: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
_, ok := d.GetOk("launch_template_id")
return !ok
},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"instance_type": {
Type: schema.TypeString,
Required: true,
Description: "The instance type.",
},
},
},
},
"db_instance_ids": {
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
Set: schema.HashString,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "ID of the RDS database instance.",
},
"scaling_mode": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
Description: "Example recycling mode for the elastic group, with values:\nrelease (default): Release mode.\nrecycle: Shutdown recycling mode.",
},
"project_name": {
Type: schema.TypeString,
Optional: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ resource "volcengine_scaling_group" "foo" {
max_instance_number = 1
instance_terminate_policy = "OldestInstance"
default_cooldown = 10
scaling_mode = "recycle"
}
`

Expand Down Expand Up @@ -60,7 +61,7 @@ resource "volcengine_scaling_group" "foo" {
max_instance_number = 10
instance_terminate_policy = "OldestInstance"
default_cooldown = 30
scaling_mode = "recycle"
tags {
key = "k2"
value = "v2"
Expand Down Expand Up @@ -99,6 +100,7 @@ func TestAccVolcengineScalingGroupResource_Basic(t *testing.T) {
resource.TestCheckResourceAttr(acc.ResourceId, "min_instance_number", "0"),
resource.TestCheckResourceAttr(acc.ResourceId, "desire_instance_number", "0"),
resource.TestCheckResourceAttr(acc.ResourceId, "default_cooldown", "10"),
resource.TestCheckResourceAttr(acc.ResourceId, "scaling_mode", "recycle"),
),
},
{
Expand Down Expand Up @@ -136,6 +138,7 @@ func TestAccVolcengineScalingGroupResource_Update(t *testing.T) {
resource.TestCheckResourceAttr(acc.ResourceId, "min_instance_number", "0"),
resource.TestCheckResourceAttr(acc.ResourceId, "desire_instance_number", "0"),
resource.TestCheckResourceAttr(acc.ResourceId, "default_cooldown", "10"),
resource.TestCheckResourceAttr(acc.ResourceId, "scaling_mode", "recycle"),
),
},
{
Expand All @@ -157,6 +160,7 @@ func TestAccVolcengineScalingGroupResource_Update(t *testing.T) {
"key": "k2",
"value": "v2",
}),
resource.TestCheckResourceAttr(acc.ResourceId, "scaling_mode", "recycle"),
),
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ func (s *VolcengineScalingGroupService) CreateResource(resourceData *schema.Reso
TargetField: "Tags",
ConvertType: ve.ConvertListN,
},
"db_instance_ids": {
TargetField: "DBInstanceIds",
ConvertType: ve.ConvertWithN,
},
"launch_template_overrides": {
ConvertType: ve.ConvertListN,
},
},
ExecuteCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (*map[string]interface{}, error) {
logger.Debug(logger.RespFormat, call.Action, call.SdkParam)
Expand Down Expand Up @@ -252,6 +259,9 @@ func (s *VolcengineScalingGroupService) ModifyResource(resourceData *schema.Reso
"launch_template_version": {
ConvertType: ve.ConvertDefault,
},
"launch_template_overrides": {
ConvertType: ve.ConvertListN,
},
},
BeforeCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (bool, error) {
if len(*call.SdkParam) < 2 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,25 @@ func DataSourceVolcengineScalingLifecycleHooks() *schema.Resource {
Computed: true,
Description: "The policy of the lifecycle hook.",
},
"lifecycle_command": {
Type: schema.TypeList,
Computed: true,
Description: "Batch job command.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"command_id": {
Type: schema.TypeString,
Computed: true,
Description: "Batch job command ID, which indicates the batch job command to be executed after triggering the lifecycle hook and installed in the instance.",
},
"parameters": {
Type: schema.TypeString,
Computed: true,
Description: "Parameters and parameter values in batch job commands.\nThe number of parameters ranges from 0 to 60.",
},
},
},
},
},
},
},
Expand Down

0 comments on commit f39e8c4

Please sign in to comment.