diff --git a/common/common_volcengine_bypass_call.go b/common/common_volcengine_bypass_call.go index 8d2a8938..f1b0cfad 100644 --- a/common/common_volcengine_bypass_call.go +++ b/common/common_volcengine_bypass_call.go @@ -102,6 +102,7 @@ func (u *BypassSvc) DoBypassSvcCall(info BypassSvcInfo, input *map[string]interf if info.ContentPath != "" && (op.HTTPMethod == "PUT" || op.HTTPMethod == "POST") { content, _ = os.Open(info.ContentPath) req.Body = content + req.ResetBody() req.HTTPRequest.Header.Set("Content-Length", strconv.FormatInt(u.tryResolveLength(content), 10)) } diff --git a/common/common_volcengine_version.go b/common/common_volcengine_version.go index 65e785c9..ab5b1a31 100644 --- a/common/common_volcengine_version.go +++ b/common/common_volcengine_version.go @@ -2,5 +2,5 @@ package common const ( TerraformProviderName = "terraform-provider-volcengine" - TerraformProviderVersion = "0.0.96" + TerraformProviderVersion = "0.0.97" ) diff --git a/example/customerGateway/main.tf b/example/customerGateway/main.tf index ab602fa7..15ba6c10 100644 --- a/example/customerGateway/main.tf +++ b/example/customerGateway/main.tf @@ -1,6 +1,6 @@ resource "volcengine_customer_gateway" "foo" { ip_address = "192.0.1.3" - customer_gateway_name = "tf-test" - description = "tf-test" + customer_gateway_name = "acc-test" + description = "acc-test" project_name = "default" } \ No newline at end of file diff --git a/example/dataCustomerGateways/main.tf b/example/dataCustomerGateways/main.tf index d8f1c2ea..323e3baa 100644 --- a/example/dataCustomerGateways/main.tf +++ b/example/dataCustomerGateways/main.tf @@ -1,3 +1,9 @@ -data "volcengine_customer_gateways" "foo" { - ids = ["cgw-2d68c4zglycjk58ozfe96norh"] +resource "volcengine_customer_gateway" "foo" { + ip_address = "192.0.1.3" + customer_gateway_name = "acc-test" + description = "acc-test" + project_name = "default" +} +data "volcengine_customer_gateways" "foo"{ + ids = [volcengine_customer_gateway.foo.id] } \ No newline at end of file diff --git a/example/dataDnatEntries/main.tf b/example/dataDnatEntries/main.tf index 60c7519e..6a63efbe 100644 --- a/example/dataDnatEntries/main.tf +++ b/example/dataDnatEntries/main.tf @@ -1,2 +1,57 @@ -data "volcengine_dnat_entries" "default" { -} \ No newline at end of file +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_nat_gateway" "foo" { + vpc_id = volcengine_vpc.foo.id + subnet_id = volcengine_subnet.foo.id + spec = "Small" + nat_gateway_name = "acc-test-ng" + description = "acc-test" + billing_type = "PostPaid" + project_name = "default" + tags { + key = "k1" + value = "v1" + } +} + +resource "volcengine_eip_address" "foo" { + name = "acc-test-eip" + description = "acc-test" + bandwidth = 1 + billing_type = "PostPaidByBandwidth" + isp = "BGP" +} + +resource "volcengine_eip_associate" "foo" { + allocation_id = volcengine_eip_address.foo.id + instance_id = volcengine_nat_gateway.foo.id + instance_type = "Nat" +} + +resource "volcengine_dnat_entry" "foo" { + dnat_entry_name = "acc-test-dnat-entry" + external_ip = volcengine_eip_address.foo.eip_address + external_port = 80 + internal_ip = "172.16.0.10" + internal_port = 80 + nat_gateway_id = volcengine_nat_gateway.foo.id + protocol = "tcp" + depends_on = [volcengine_eip_associate.foo] +} + +data "volcengine_dnat_entries" "foo"{ + ids = [volcengine_dnat_entry.foo.id] +} diff --git a/example/dataNatGateways/main.tf b/example/dataNatGateways/main.tf index fa065093..eae1babb 100644 --- a/example/dataNatGateways/main.tf +++ b/example/dataNatGateways/main.tf @@ -1,3 +1,33 @@ -data "volcengine_nat_gateways" "default" { - ids = ["ngw-2743w1f6iqby87fap8tvm9kop", "ngw-274gwbqe340zk7fap8spkzo7x"] -} \ No newline at end of file +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_nat_gateway" "foo" { + vpc_id = volcengine_vpc.foo.id + subnet_id = volcengine_subnet.foo.id + spec = "Small" + nat_gateway_name = "acc-test-ng-${count.index}" + description = "acc-test" + billing_type = "PostPaid" + project_name = "default" + tags { + key = "k1" + value = "v1" + } + count =3 +} + +data "volcengine_nat_gateways" "foo"{ + ids = volcengine_nat_gateway.foo[*].id +} diff --git a/example/dataScalingActivities/main.tf b/example/dataScalingActivities/main.tf index a7266622..859fc46d 100644 --- a/example/dataScalingActivities/main.tf +++ b/example/dataScalingActivities/main.tf @@ -1,3 +1,104 @@ -data "volcengine_scaling_activities" "default"{ - scaling_group_id = "scg-ybqm0b6kcigh9zu9ce6t" +data "volcengine_zones" "foo" { } + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = volcengine_vpc.foo.id +} + + +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_ecs_key_pair" "foo" { + description = "acc-test-2" + key_pair_name = "acc-test-key-pair-name" +} + +resource "volcengine_ecs_launch_template" "foo" { + description = "acc-test-desc" + eip_bandwidth = 200 + eip_billing_type = "PostPaidByBandwidth" + eip_isp = "BGP" + host_name = "acc-hostname" + image_id = data.volcengine_images.foo.images[0].image_id + instance_charge_type = "PostPaid" + instance_name = "acc-instance-name" + instance_type_id = "ecs.g1.large" + key_pair_name = volcengine_ecs_key_pair.foo.key_pair_name + launch_template_name = "acc-test-template" + network_interfaces { + subnet_id = volcengine_subnet.foo.id + security_group_ids = [volcengine_security_group.foo.id] + } + volumes { + volume_type = "ESSD_PL0" + size = 50 + delete_with_instance = true + } +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + subnet_ids = [volcengine_subnet.foo.id] + multi_az_policy = "BALANCE" + desire_instance_number = -1 + min_instance_number = 0 + max_instance_number = 10 + instance_terminate_policy = "OldestInstance" + default_cooldown = 10 + launch_template_id = volcengine_ecs_launch_template.foo.id + launch_template_version = "Default" +} + +resource "volcengine_scaling_group_enabler" "foo" { + scaling_group_id = volcengine_scaling_group.foo.id +} + +resource "volcengine_ecs_instance" "foo" { + count = 3 + instance_name = "acc-test-ecs-${count.index}" + description = "acc-test" + host_name = "tf-acc-test" + image_id = data.volcengine_images.foo.images[0].image_id + instance_type = "ecs.g1.large" + password = "93f0cb0614Aab12" + instance_charge_type = "PostPaid" + system_volume_type = "ESSD_PL0" + system_volume_size = 40 + subnet_id = volcengine_subnet.foo.id + security_group_ids = [volcengine_security_group.foo.id] +} + +resource "volcengine_scaling_instance_attachment" "foo" { + count = length(volcengine_ecs_instance.foo) + instance_id = volcengine_ecs_instance.foo[count.index].id + scaling_group_id = volcengine_scaling_group.foo.id + entrusted = true + + depends_on = [ + volcengine_scaling_group_enabler.foo + ] +} + +data "volcengine_scaling_activities" "foo" { + scaling_group_id = volcengine_scaling_group.foo.id + depends_on = [ + volcengine_scaling_instance_attachment.foo + ] +} \ No newline at end of file diff --git a/example/dataScalingConfigurations/main.tf b/example/dataScalingConfigurations/main.tf index 409c93ff..22756579 100644 --- a/example/dataScalingConfigurations/main.tf +++ b/example/dataScalingConfigurations/main.tf @@ -1,3 +1,56 @@ -data "volcengine_scaling_configurations" "default"{ - ids = ["scc-ybrurj4uw6gh9zecj327"] +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = volcengine_vpc.foo.id +} + +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + 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 +} + +resource "volcengine_scaling_configuration" "foo" { + count = 3 + image_id = data.volcengine_images.foo.images[0].image_id + instance_name = "acc-test-instance" + instance_types = ["ecs.g1.large"] + password = "93f0cb0614Aab12" + scaling_configuration_name = "acc-test-scaling-config-${count.index}" + scaling_group_id = volcengine_scaling_group.foo.id + security_group_ids = [volcengine_security_group.foo.id] + volumes { + volume_type = "ESSD_PL0" + size = 50 + delete_with_instance = true + } +} + +data "volcengine_scaling_configurations" "foo" { + ids = volcengine_scaling_configuration.foo[*].id } \ No newline at end of file diff --git a/example/dataScalingGroups/main.tf b/example/dataScalingGroups/main.tf index 3143df53..cbcaf8ff 100644 --- a/example/dataScalingGroups/main.tf +++ b/example/dataScalingGroups/main.tf @@ -1,3 +1,40 @@ -data "volcengine_scaling_groups" "default"{ - ids = ["scg-ybru8pazhgl8j1di4tyd"] +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_scaling_group" "foo" { + count = 3 + scaling_group_name = "acc-test-scaling-group-${count.index}" + subnet_ids = [volcengine_subnet.foo.id] + multi_az_policy = "BALANCE" + desire_instance_number = 0 + min_instance_number = 0 + max_instance_number = 10 + instance_terminate_policy = "OldestInstance" + default_cooldown = 30 + + tags { + key = "k2" + value = "v2" + } + + tags { + key = "k1" + value = "v1" + } +} + +data "volcengine_scaling_groups" "default" { + ids = volcengine_scaling_group.foo[*].id } \ No newline at end of file diff --git a/example/dataScalingInstances/main.tf b/example/dataScalingInstances/main.tf index 017d7cda..57d6aa9e 100644 --- a/example/dataScalingInstances/main.tf +++ b/example/dataScalingInstances/main.tf @@ -1,6 +1,102 @@ -data "volcengine_scaling_instances" "default" { - scaling_group_id = "scg-ybtawtznszgh9yv8agcp" - ids = ["i-ybzl4u5uogl8j07hgcbg", "i-ybyncrcpzpgh9zmlct0w", "i-ybyncrcpzogh9z4ax9tv"] - scaling_configuration_id = "scc-ybtawzucw95pkgon0wst" - status = "InService" +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = volcengine_vpc.foo.id +} + + +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_ecs_key_pair" "foo" { + description = "acc-test-2" + key_pair_name = "acc-test-key-pair-name" +} + +resource "volcengine_ecs_launch_template" "foo" { + description = "acc-test-desc" + eip_bandwidth = 200 + eip_billing_type = "PostPaidByBandwidth" + eip_isp = "BGP" + host_name = "acc-hostname" + image_id = data.volcengine_images.foo.images[0].image_id + instance_charge_type = "PostPaid" + instance_name = "acc-instance-name" + instance_type_id = "ecs.g1.large" + key_pair_name = volcengine_ecs_key_pair.foo.key_pair_name + launch_template_name = "acc-test-template" + network_interfaces { + subnet_id = volcengine_subnet.foo.id + security_group_ids = [volcengine_security_group.foo.id] + } + volumes { + volume_type = "ESSD_PL0" + size = 50 + delete_with_instance = true + } +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + subnet_ids = [volcengine_subnet.foo.id] + multi_az_policy = "BALANCE" + desire_instance_number = -1 + min_instance_number = 0 + max_instance_number = 10 + instance_terminate_policy = "OldestInstance" + default_cooldown = 10 + launch_template_id = volcengine_ecs_launch_template.foo.id + launch_template_version = "Default" +} + +resource "volcengine_scaling_group_enabler" "foo" { + scaling_group_id = volcengine_scaling_group.foo.id +} + +resource "volcengine_ecs_instance" "foo" { + count = 3 + instance_name = "acc-test-ecs-${count.index}" + description = "acc-test" + host_name = "tf-acc-test" + image_id = data.volcengine_images.foo.images[0].image_id + instance_type = "ecs.g1.large" + password = "93f0cb0614Aab12" + instance_charge_type = "PostPaid" + system_volume_type = "ESSD_PL0" + system_volume_size = 40 + subnet_id = volcengine_subnet.foo.id + security_group_ids = [volcengine_security_group.foo.id] +} + +resource "volcengine_scaling_instance_attachment" "foo" { + count = length(volcengine_ecs_instance.foo) + instance_id = volcengine_ecs_instance.foo[count.index].id + scaling_group_id = volcengine_scaling_group.foo.id + entrusted = true + + depends_on = [ + volcengine_scaling_group_enabler.foo + ] +} + +data "volcengine_scaling_instances" "foo" { + scaling_group_id = volcengine_scaling_group.foo.id + ids = volcengine_scaling_instance_attachment.foo[*].instance_id } \ No newline at end of file diff --git a/example/dataScalingLifecycleHooks/main.tf b/example/dataScalingLifecycleHooks/main.tf index fcef64bb..7966f7f4 100644 --- a/example/dataScalingLifecycleHooks/main.tf +++ b/example/dataScalingLifecycleHooks/main.tf @@ -1,3 +1,39 @@ -data "volcengine_scaling_lifecycle_hooks" "default"{ - scaling_group_id = "scg-ybru8pazhgl8j1di4tyd" +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +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 + instance_terminate_policy = "OldestInstance" + default_cooldown = 10 +} + +resource "volcengine_scaling_lifecycle_hook" "foo" { + count = 3 + lifecycle_hook_name = "acc-test-lifecycle-${count.index}" + lifecycle_hook_policy = "CONTINUE" + lifecycle_hook_timeout = 30 + lifecycle_hook_type = "SCALE_IN" + scaling_group_id = volcengine_scaling_group.foo.id +} + +data "volcengine_scaling_lifecycle_hooks" "foo" { + ids = volcengine_scaling_lifecycle_hook.foo[*].lifecycle_hook_id + scaling_group_id = volcengine_scaling_group.foo.id } \ No newline at end of file diff --git a/example/dataScalingPolicies/main.tf b/example/dataScalingPolicies/main.tf index 6e28ed69..7de01cd0 100644 --- a/example/dataScalingPolicies/main.tf +++ b/example/dataScalingPolicies/main.tf @@ -1,4 +1,47 @@ -data "volcengine_scaling_policies" "default"{ - scaling_group_id = "scg-ybqm0b6kcigh9zu9ce6t" - ids = ["sp-ybruzckr8bgh9zrxw29v"] +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + 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 +} + +resource "volcengine_scaling_policy" "foo" { + count = 3 + active = false + scaling_group_id = volcengine_scaling_group.foo.id + scaling_policy_name = "acc-tf-sg-policy-test-${count.index}" + scaling_policy_type = "Alarm" + adjustment_type = "QuantityChangeInCapacity" + adjustment_value = 100 + cooldown = 10 + alarm_policy_rule_type = "Static" + alarm_policy_evaluation_count = 1 + alarm_policy_condition_metric_name = "Instance_CpuBusy_Avg" + alarm_policy_condition_metric_unit = "Percent" + alarm_policy_condition_comparison_operator = "=" + alarm_policy_condition_threshold = 100 +} + +data "volcengine_scaling_policies" "foo" { + ids = volcengine_scaling_policy.foo[*].scaling_policy_id + scaling_group_id = volcengine_scaling_group.foo.id } \ No newline at end of file diff --git a/example/dataSnatEntries/main.tf b/example/dataSnatEntries/main.tf index 411462fc..eaf51697 100644 --- a/example/dataSnatEntries/main.tf +++ b/example/dataSnatEntries/main.tf @@ -1,3 +1,62 @@ -data "volcengine_snat_entries" "default" { - ids = ["snat-274zl8b1kxzb47fap8u35uune"] -} \ No newline at end of file +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_nat_gateway" "foo" { + vpc_id = volcengine_vpc.foo.id + subnet_id = volcengine_subnet.foo.id + spec = "Small" + nat_gateway_name = "acc-test-ng" + description = "acc-test" + billing_type = "PostPaid" + project_name = "default" + tags { + key = "k1" + value = "v1" + } +} + +resource "volcengine_eip_address" "foo" { + name = "acc-test-eip" + description = "acc-test" + bandwidth = 1 + billing_type = "PostPaidByBandwidth" + isp = "BGP" +} + +resource "volcengine_eip_associate" "foo" { + allocation_id = volcengine_eip_address.foo.id + instance_id = volcengine_nat_gateway.foo.id + instance_type = "Nat" +} + +resource "volcengine_snat_entry" "foo1" { + snat_entry_name = "acc-test-snat-entry" + nat_gateway_id = volcengine_nat_gateway.foo.id + eip_id = volcengine_eip_address.foo.id + source_cidr = "172.16.0.0/24" + depends_on = ["volcengine_eip_associate.foo"] +} + +resource "volcengine_snat_entry" "foo2" { + snat_entry_name = "acc-test-snat-entry" + nat_gateway_id = volcengine_nat_gateway.foo.id + eip_id = volcengine_eip_address.foo.id + source_cidr = "172.16.0.0/16" + depends_on = ["volcengine_eip_associate.foo"] +} + +data "volcengine_snat_entries" "foo"{ + ids = [volcengine_snat_entry.foo1.id, volcengine_snat_entry.foo2.id] +} diff --git a/example/dataVolumes/main.tf b/example/dataVolumes/main.tf index ffa2f0df..60157763 100644 --- a/example/dataVolumes/main.tf +++ b/example/dataVolumes/main.tf @@ -1,3 +1,18 @@ -data "volcengine_volumes" "default"{ - ids = ["vol-3tzg6y5imn3b9fchkedb"] -} \ No newline at end of file +data "volcengine_zones" "foo"{ +} + +resource "volcengine_volume" "foo" { + volume_name = "acc-test-volume-${count.index}" + volume_type = "ESSD_PL0" + description = "acc-test" + kind = "data" + size = 60 + zone_id = data.volcengine_zones.foo.zones[0].id + volume_charge_type = "PostPaid" + project_name = "default" + count = 3 +} + +data "volcengine_volumes" "foo"{ + ids = volcengine_volume.foo[*].id +} diff --git a/example/dataVpnConnections/main.tf b/example/dataVpnConnections/main.tf index 52d6896f..1dd6a6ab 100644 --- a/example/dataVpnConnections/main.tf +++ b/example/dataVpnConnections/main.tf @@ -1,3 +1,57 @@ -data "volcengine_vpn_connections" "default"{ - ids = ["vgc-2d5wwids8cdts58ozfe63k2uq"] +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-test-subnet" + cidr_block = "172.16.0.0/24" + zone_id = "cn-beijing-a" + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_vpn_gateway" "foo" { + vpc_id = volcengine_vpc.foo.id + subnet_id = volcengine_subnet.foo.id + bandwidth = 20 + vpn_gateway_name = "acc-test" + description = "acc-test" + period = 2 + project_name = "default" +} + +resource "volcengine_customer_gateway" "foo" { + ip_address = "192.0.1.3" + customer_gateway_name = "acc-test" + description = "acc-test" + project_name = "default" +} + +resource "volcengine_vpn_connection" "foo" { + vpn_connection_name = "acc-tf-test" + description = "acc-tf-test" + vpn_gateway_id = volcengine_vpn_gateway.foo.id + customer_gateway_id = volcengine_customer_gateway.foo.id + local_subnet = ["192.168.0.0/22"] + remote_subnet = ["192.161.0.0/20"] + dpd_action = "none" + nat_traversal = true + ike_config_psk = "acctest@!3" + ike_config_version = "ikev1" + ike_config_mode = "main" + ike_config_enc_alg = "aes" + ike_config_auth_alg = "md5" + ike_config_dh_group = "group2" + ike_config_lifetime = 9000 + ike_config_local_id = "acc_test" + ike_config_remote_id = "acc_test" + ipsec_config_enc_alg = "aes" + ipsec_config_auth_alg = "sha256" + ipsec_config_dh_group = "group2" + ipsec_config_lifetime = 9000 + project_name = "default" +} + +data "volcengine_vpn_connections" "foo"{ + ids = [volcengine_vpn_connection.foo.id] } \ No newline at end of file diff --git a/example/dataVpnGatewayRoutes/main.tf b/example/dataVpnGatewayRoutes/main.tf index 7a30154e..b907d043 100644 --- a/example/dataVpnGatewayRoutes/main.tf +++ b/example/dataVpnGatewayRoutes/main.tf @@ -1,3 +1,64 @@ -data "volcengine_vpn_gateway_routes" "default"{ - ids = ["vgr-2byssu52dktts2dx0ee90r5hp]"] +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-test-subnet" + cidr_block = "172.16.0.0/24" + zone_id = "cn-beijig-a" + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_vpn_gateway" "foo" { + vpc_id = volcengine_vpc.foo.id + subnet_id = volcengine_subnet.foo.id + bandwidth = 20 + vpn_gateway_name = "acc-test" + description = "acc-test" + period = 2 + project_name = "default" +} + +resource "volcengine_customer_gateway" "foo" { + ip_address = "192.0.1.3" + customer_gateway_name = "acc-test" + description = "acc-test" + project_name = "default" +} + +resource "volcengine_vpn_connection" "foo" { + vpn_connection_name = "acc-tf-test" + description = "acc-tf-test" + vpn_gateway_id = volcengine_vpn_gateway.foo.id + customer_gateway_id = volcengine_customer_gateway.foo.id + local_subnet = ["192.168.0.0/22"] + remote_subnet = ["192.161.0.0/20"] + dpd_action = "none" + nat_traversal = true + ike_config_psk = "acctest@!3" + ike_config_version = "ikev1" + ike_config_mode = "main" + ike_config_enc_alg = "aes" + ike_config_auth_alg = "md5" + ike_config_dh_group = "group2" + ike_config_lifetime = 9000 + ike_config_local_id = "acc_test" + ike_config_remote_id = "acc_test" + ipsec_config_enc_alg = "aes" + ipsec_config_auth_alg = "sha256" + ipsec_config_dh_group = "group2" + ipsec_config_lifetime = 9000 + project_name = "default" + log_enabled = false +} + +resource "volcengine_vpn_gateway_route" "foo" { + vpn_gateway_id = volcengine_vpn_gateway.foo.id + destination_cidr_block = "192.168.0.0/20" + next_hop_id = volcengine_vpn_connection.foo.id +} + +data "volcengine_vpn_gateway_routes" "foo"{ + ids = [volcengine_vpn_gateway_route.foo.id] } \ No newline at end of file diff --git a/example/dataVpnGateways/main.tf b/example/dataVpnGateways/main.tf index 551b849a..aecb6883 100644 --- a/example/dataVpnGateways/main.tf +++ b/example/dataVpnGateways/main.tf @@ -1,3 +1,25 @@ -data "volcengine_vpn_gateways" "default"{ - ids = ["vgw-2c012ea9fm5mo2dx0efxg46qi"] +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-test-subnet" + cidr_block = "172.16.0.0/24" + zone_id = "cn-beijing-a" + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_vpn_gateway" "foo" { + vpc_id = volcengine_vpc.foo.id + subnet_id = volcengine_subnet.foo.id + bandwidth = 20 + vpn_gateway_name = "acc-test" + description = "acc-test" + period = 2 + project_name = "default" +} + +data "volcengine_vpn_gateways" "foo"{ + ids = [volcengine_vpn_gateway.foo.id] } \ No newline at end of file diff --git a/example/dnatEntry/main.tf b/example/dnatEntry/main.tf index 969c722a..c7e16477 100644 --- a/example/dnatEntry/main.tf +++ b/example/dnatEntry/main.tf @@ -1,9 +1,53 @@ +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_nat_gateway" "foo" { + vpc_id = volcengine_vpc.foo.id + subnet_id = volcengine_subnet.foo.id + spec = "Small" + nat_gateway_name = "acc-test-ng" + description = "acc-test" + billing_type = "PostPaid" + project_name = "default" + tags { + key = "k1" + value = "v1" + } +} + +resource "volcengine_eip_address" "foo" { + name = "acc-test-eip" + description = "acc-test" + bandwidth = 1 + billing_type = "PostPaidByBandwidth" + isp = "BGP" +} + +resource "volcengine_eip_associate" "foo" { + allocation_id = volcengine_eip_address.foo.id + instance_id = volcengine_nat_gateway.foo.id + instance_type = "Nat" +} + resource "volcengine_dnat_entry" "foo" { - nat_gateway_id = "ngw-imw3aej7e96o8gbssxkfbybv" - external_ip = "10.249.186.68" - external_port = "23" - internal_ip = "193.168.1.1" - internal_port = "24" + dnat_entry_name = "acc-test-dnat-entry" + external_ip = volcengine_eip_address.foo.eip_address + external_port = 80 + internal_ip = "172.16.0.10" + internal_port = 80 + nat_gateway_id = volcengine_nat_gateway.foo.id protocol = "tcp" - dnat_entry_name = "terraform-test2" + depends_on = [volcengine_eip_associate.foo] } diff --git a/example/natGateway/main.tf b/example/natGateway/main.tf index a977ce75..e1b841eb 100644 --- a/example/natGateway/main.tf +++ b/example/natGateway/main.tf @@ -1,9 +1,28 @@ +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + resource "volcengine_nat_gateway" "foo" { - vpc_id = "vpc-im67wjcikxkw8gbssx8ufpj8" - subnet_id = "subnet-im67x70vxla88gbssz1hy1z2" - spec = "Medium" - nat_gateway_name = "tf-auto-demo-1" + vpc_id = volcengine_vpc.foo.id + subnet_id = volcengine_subnet.foo.id + spec = "Small" + nat_gateway_name = "acc-test-ng" + description = "acc-test" billing_type = "PostPaid" - description = "This nat gateway auto-created by terraform. " project_name = "default" -} \ No newline at end of file + tags { + key = "k1" + value = "v1" + } +} diff --git a/example/scalingConfiguration/main.tf b/example/scalingConfiguration/main.tf index 000ec959..55dbc520 100644 --- a/example/scalingConfiguration/main.tf +++ b/example/scalingConfiguration/main.tf @@ -1,39 +1,76 @@ +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = volcengine_vpc.foo.id +} + +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + 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 +} + resource "volcengine_scaling_configuration" "foo" { - scaling_configuration_name = "tf-test" - scaling_group_id = "scg-ycinx27x25gh9y31p0fy" - image_id = "image-ycgud4t4hxgso0e27bdl" - instance_types = ["ecs.g2i.large"] - instance_name = "tf-test" - instance_description = "" - host_name = "" - password = "" - key_pair_name = "tf-keypair" + scaling_configuration_name = "tf-test" + scaling_group_id = volcengine_scaling_group.foo.id + image_id = data.volcengine_images.foo.images[0].image_id + instance_types = ["ecs.g2i.large"] + instance_name = "tf-test" + instance_description = "" + host_name = "" + password = "" + key_pair_name = "tf-keypair" security_enhancement_strategy = "InActive" volumes { - volume_type = "ESSD_PL0" - size = 20 + volume_type = "ESSD_PL0" + size = 20 delete_with_instance = false } volumes { - volume_type = "ESSD_PL0" - size = 20 + volume_type = "ESSD_PL0" + size = 50 delete_with_instance = true } - security_group_ids = ["sg-2fepz3c793g1s59gp67y21r34"] - eip_bandwidth = 10 - eip_isp = "ChinaMobile" - eip_billing_type = "PostPaidByBandwidth" - user_data = "IyEvYmluL2Jhc2gKZWNobyAidGVzdCI=" + security_group_ids = [volcengine_security_group.foo.id] + eip_bandwidth = 10 + eip_isp = "ChinaMobile" + eip_billing_type = "PostPaidByBandwidth" + user_data = "IyEvYmluL2Jhc2gKZWNobyAidGVzdCI=" tags { - key = "tf-key1" + key = "tf-key1" value = "tf-value1" } tags { - key = "tf-key2" + key = "tf-key2" value = "tf-value2" } - project_name = "default" + project_name = "default" hpc_cluster_id = "" - spot_strategy = "NoSpot" + spot_strategy = "NoSpot" } diff --git a/example/scalingConfigurationAttachment/main.tf b/example/scalingConfigurationAttachment/main.tf index 1ea572f2..e10c4234 100644 --- a/example/scalingConfigurationAttachment/main.tf +++ b/example/scalingConfigurationAttachment/main.tf @@ -1,3 +1,55 @@ -resource "volcengine_scaling_configuration_attachment" "foo1" { - scaling_configuration_id = "scc-ybrurj4uw6gh9zecj327" +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = volcengine_vpc.foo.id +} + +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + 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 +} + +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"] + password = "93f0cb0614Aab12" + scaling_configuration_name = "acc-test-scaling-config" + scaling_group_id = volcengine_scaling_group.foo.id + security_group_ids = [volcengine_security_group.foo.id] + volumes { + volume_type = "ESSD_PL0" + size = 50 + delete_with_instance = true + } +} + +resource "volcengine_scaling_configuration_attachment" "foo" { + scaling_configuration_id = volcengine_scaling_configuration.foo.id } \ No newline at end of file diff --git a/example/scalingGroup/main.tf b/example/scalingGroup/main.tf index 28039724..0ed19141 100644 --- a/example/scalingGroup/main.tf +++ b/example/scalingGroup/main.tf @@ -1,15 +1,36 @@ +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + resource "volcengine_scaling_group" "foo" { - scaling_group_name = "test-tf" - subnet_ids = ["subnet-2fe79j7c8o5c059gp68ksxr93"] - multi_az_policy = "BALANCE" - desire_instance_number = 0 - min_instance_number = 0 - max_instance_number = 1 + count = 3 + scaling_group_name = "acc-test-scaling-group-${count.index}" + subnet_ids = [volcengine_subnet.foo.id] + multi_az_policy = "BALANCE" + desire_instance_number = 0 + min_instance_number = 0 + max_instance_number = 10 instance_terminate_policy = "OldestInstance" - default_cooldown = 10 - project_name = "default" + default_cooldown = 30 + tags { - key = "tf-key1" - value = "tf-value1" + key = "k2" + value = "v2" + } + + tags { + key = "k1" + value = "v1" } } \ No newline at end of file diff --git a/example/scalingInstanceAttachment/main.tf b/example/scalingInstanceAttachment/main.tf index efd95438..5e8a63d9 100644 --- a/example/scalingInstanceAttachment/main.tf +++ b/example/scalingInstanceAttachment/main.tf @@ -1,7 +1,95 @@ +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = volcengine_vpc.foo.id +} + + +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_ecs_key_pair" "foo" { + description = "acc-test-2" + key_pair_name = "acc-test-key-pair-name" +} + +resource "volcengine_ecs_launch_template" "foo" { + description = "acc-test-desc" + eip_bandwidth = 200 + eip_billing_type = "PostPaidByBandwidth" + eip_isp = "BGP" + host_name = "acc-hostname" + image_id = data.volcengine_images.foo.images[0].image_id + instance_charge_type = "PostPaid" + instance_name = "acc-instance-name" + instance_type_id = "ecs.g1.large" + key_pair_name = volcengine_ecs_key_pair.foo.key_pair_name + launch_template_name = "acc-test-template" + network_interfaces { + subnet_id = volcengine_subnet.foo.id + security_group_ids = [volcengine_security_group.foo.id] + } + volumes { + volume_type = "ESSD_PL0" + size = 50 + delete_with_instance = true + } +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + subnet_ids = [volcengine_subnet.foo.id] + multi_az_policy = "BALANCE" + desire_instance_number = -1 + min_instance_number = 0 + max_instance_number = 1 + instance_terminate_policy = "OldestInstance" + default_cooldown = 10 + launch_template_id = volcengine_ecs_launch_template.foo.id + launch_template_version = "Default" +} + +resource "volcengine_scaling_group_enabler" "foo" { + scaling_group_id = volcengine_scaling_group.foo.id +} + +resource "volcengine_ecs_instance" "foo" { + instance_name = "acc-test-ecs" + description = "acc-test" + host_name = "tf-acc-test" + image_id = data.volcengine_images.foo.images[0].image_id + instance_type = "ecs.g1.large" + password = "93f0cb0614Aab12" + instance_charge_type = "PostPaid" + system_volume_type = "ESSD_PL0" + system_volume_size = 40 + subnet_id = volcengine_subnet.foo.id + security_group_ids = [volcengine_security_group.foo.id] +} + resource "volcengine_scaling_instance_attachment" "foo" { - scaling_group_id = "scg-yc23rtcea88hcchybf8g" - instance_id = "i-yc23soxj50gsnz7rxnjp" - delete_type = "Remove" - entrusted = true - detach_option = "none" + instance_id = volcengine_ecs_instance.foo.id + scaling_group_id = volcengine_scaling_group.foo.id + entrusted = true + + depends_on = [ + volcengine_scaling_group_enabler.foo + ] } \ No newline at end of file diff --git a/example/scalingLifecycleHook/main.tf b/example/scalingLifecycleHook/main.tf index 03a596b2..52e20c3d 100644 --- a/example/scalingLifecycleHook/main.tf +++ b/example/scalingLifecycleHook/main.tf @@ -1,7 +1,33 @@ +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +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 + instance_terminate_policy = "OldestInstance" + default_cooldown = 10 +} + resource "volcengine_scaling_lifecycle_hook" "foo" { - scaling_group_id = "scg-ybru8pazhgl8j1di4tyd" - lifecycle_hook_name = "tf-test" + lifecycle_hook_name = "acc-test-lifecycle" + lifecycle_hook_policy = "CONTINUE" lifecycle_hook_timeout = 30 - lifecycle_hook_type = "SCALE_IN" - lifecycle_hook_policy = "CONTINUE" + lifecycle_hook_type = "SCALE_IN" + scaling_group_id = volcengine_scaling_group.foo.id } \ No newline at end of file diff --git a/example/scalingPolicy/main.tf b/example/scalingPolicy/main.tf index 1d7f006f..5f26c00d 100644 --- a/example/scalingPolicy/main.tf +++ b/example/scalingPolicy/main.tf @@ -1,20 +1,41 @@ +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + 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 +} + resource "volcengine_scaling_policy" "foo" { - active = false - scaling_group_id = "scg-ybqm0b6kcigh9zu9ce6t" - scaling_policy_name = "tf-test" - scaling_policy_type = "Alarm" - adjustment_type = "QuantityChangeInCapacity" - adjustment_value = 100 - cooldown = 10 - scheduled_policy_launch_time = "2022-07-09T09:59Z" - scheduled_policy_recurrence_end_time = "2022-07-24T09:25Z" - scheduled_policy_recurrence_type = "Daily" - scheduled_policy_recurrence_value = 10 - alarm_policy_rule_type = "Static" - alarm_policy_evaluation_count = 1 - alarm_policy_condition_metric_name = "Instance_CpuBusy_Avg" - alarm_policy_condition_metric_unit = "Percent" + active = false + scaling_group_id = volcengine_scaling_group.foo.id + scaling_policy_name = "acc-tf-sg-policy-test" + scaling_policy_type = "Alarm" + adjustment_type = "QuantityChangeInCapacity" + adjustment_value = 100 + cooldown = 10 + alarm_policy_rule_type = "Static" + alarm_policy_evaluation_count = 1 + alarm_policy_condition_metric_name = "Instance_CpuBusy_Avg" + alarm_policy_condition_metric_unit = "Percent" alarm_policy_condition_comparison_operator = "=" - alarm_policy_condition_threshold = 100 + alarm_policy_condition_threshold = 100 } - diff --git a/example/snatEntry/main.tf b/example/snatEntry/main.tf index b82d1f1d..7b3bfbe0 100644 --- a/example/snatEntry/main.tf +++ b/example/snatEntry/main.tf @@ -1,6 +1,50 @@ +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_nat_gateway" "foo" { + vpc_id = volcengine_vpc.foo.id + subnet_id = volcengine_subnet.foo.id + spec = "Small" + nat_gateway_name = "acc-test-ng" + description = "acc-test" + billing_type = "PostPaid" + project_name = "default" + tags { + key = "k1" + value = "v1" + } +} + +resource "volcengine_eip_address" "foo" { + name = "acc-test-eip" + description = "acc-test" + bandwidth = 1 + billing_type = "PostPaidByBandwidth" + isp = "BGP" +} + +resource "volcengine_eip_associate" "foo" { + allocation_id = volcengine_eip_address.foo.id + instance_id = volcengine_nat_gateway.foo.id + instance_type = "Nat" +} + resource "volcengine_snat_entry" "foo" { - nat_gateway_id = "ngw-2743w1f6iqby87fap8tvm9kop" - subnet_id = "subnet-2744i7u9alnnk7fap8tkq8aft" - eip_id = "eip-274zlae117nr47fap8tzl24v4" - snat_entry_name = "tf-test-up" -} \ No newline at end of file + snat_entry_name = "acc-test-snat-entry" + nat_gateway_id = volcengine_nat_gateway.foo.id + eip_id = volcengine_eip_address.foo.id + source_cidr = "172.16.0.0/24" + depends_on = ["volcengine_eip_associate.foo"] +} diff --git a/example/volume/main.tf b/example/volume/main.tf index 393d6a45..411194fd 100644 --- a/example/volume/main.tf +++ b/example/volume/main.tf @@ -1,24 +1,69 @@ -resource "volcengine_volume" "foo" { - volume_name = "terraform-test" - zone_id = "cn-xx-a" +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = volcengine_vpc.foo.id +} + +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_ecs_instance" "foo" { + instance_name = "acc-test-ecs" + description = "acc-test" + host_name = "tf-acc-test" + image_id = data.volcengine_images.foo.images[0].image_id + instance_type = "ecs.g1.large" + password = "93f0cb0614Aab12" + instance_charge_type = "PrePaid" + period = 1 + system_volume_type = "ESSD_PL0" + system_volume_size = 40 + subnet_id = volcengine_subnet.foo.id + security_group_ids = [volcengine_security_group.foo.id] + project_name = "default" + tags { + key = "k1" + value = "v1" + } +} + +resource "volcengine_volume" "PreVolume" { + volume_name = "acc-test-volume" volume_type = "ESSD_PL0" + description = "acc-test" kind = "data" size = 40 - volume_charge_type = "PostPaid" + zone_id = data.volcengine_zones.foo.zones[0].id + volume_charge_type = "PrePaid" + instance_id = volcengine_ecs_instance.foo.id project_name = "default" + delete_with_instance = true } -resource "volcengine_volume_attach" "foo" { - volume_id = volcengine_volume.foo.id - instance_id = "i-yc8pfhbafwijutv6s1fv" -} - -resource "volcengine_volume" "foo2" { - volume_name = "terraform-test3" - zone_id = "cn-beijing-b" +resource "volcengine_volume" "PostVolume" { + volume_name = "acc-test-volume" volume_type = "ESSD_PL0" + description = "acc-test" kind = "data" size = 40 - volume_charge_type = "PrePaid" - instance_id = "i-yc8pfhbafwijutv6s1fv" -} \ No newline at end of file + zone_id = data.volcengine_zones.foo.zones[0].id + volume_charge_type = "PostPaid" + project_name = "default" +} diff --git a/example/volumeAttach/main.tf b/example/volumeAttach/main.tf index 6a571bbd..e2db678f 100644 --- a/example/volumeAttach/main.tf +++ b/example/volumeAttach/main.tf @@ -1,4 +1,60 @@ +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = volcengine_vpc.foo.id +} + +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_ecs_instance" "foo" { + instance_name = "acc-test-ecs" + description = "acc-test" + host_name = "tf-acc-test" + image_id = data.volcengine_images.foo.images[0].image_id + instance_type = "ecs.g1.large" + password = "93f0cb0614Aab12" + instance_charge_type = "PostPaid" + system_volume_type = "ESSD_PL0" + system_volume_size = 40 + subnet_id = volcengine_subnet.foo.id + security_group_ids = [volcengine_security_group.foo.id] + project_name = "default" + tags { + key = "k1" + value = "v1" + } +} + +resource "volcengine_volume" "foo" { + volume_name = "acc-test-volume" + volume_type = "ESSD_PL0" + description = "acc-test" + kind = "data" + size = 40 + zone_id = data.volcengine_zones.foo.zones[0].id + volume_charge_type = "PostPaid" + project_name = "default" +} + resource "volcengine_volume_attach" "foo" { - volume_id = "vol-3tzl52wubz3b9fciw7ev" - instance_id = "i-4ay59ww7dq8dt9c29hd4" -} \ No newline at end of file + instance_id = volcengine_ecs_instance.foo.id + volume_id = volcengine_volume.foo.id +} diff --git a/example/vpnConnection/main.tf b/example/vpnConnection/main.tf index 79e95470..23c7c50e 100644 --- a/example/vpnConnection/main.tf +++ b/example/vpnConnection/main.tf @@ -1,21 +1,50 @@ +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-test-subnet" + cidr_block = "172.16.0.0/24" + zone_id = "cn-beijing-a" + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_vpn_gateway" "foo" { + vpc_id = volcengine_vpc.foo.id + subnet_id = volcengine_subnet.foo.id + bandwidth = 20 + vpn_gateway_name = "acc-test" + description = "acc-test" + period = 2 + project_name = "default" +} + +resource "volcengine_customer_gateway" "foo" { + ip_address = "192.0.1.3" + customer_gateway_name = "acc-test" + description = "acc-test" + project_name = "default" +} + resource "volcengine_vpn_connection" "foo" { - vpn_connection_name = "tf-test" - description = "tf-test" - vpn_gateway_id = "vgw-2feq19gnyc9hc59gp68914u6o" - customer_gateway_id = "cgw-12ayj1s157gn417q7y29bixqy" + vpn_connection_name = "acc-tf-test" + description = "acc-tf-test" + vpn_gateway_id = volcengine_vpn_gateway.foo.id + customer_gateway_id = volcengine_customer_gateway.foo.id local_subnet = ["192.168.0.0/22"] remote_subnet = ["192.161.0.0/20"] dpd_action = "none" nat_traversal = true - ike_config_psk = "tftest@!3" + ike_config_psk = "acctest@!3" ike_config_version = "ikev1" ike_config_mode = "main" ike_config_enc_alg = "aes" ike_config_auth_alg = "md5" ike_config_dh_group = "group2" ike_config_lifetime = 9000 - ike_config_local_id = "tf_test" - ike_config_remote_id = "tf_test" + ike_config_local_id = "acc_test" + ike_config_remote_id = "acc_test" ipsec_config_enc_alg = "aes" ipsec_config_auth_alg = "sha256" ipsec_config_dh_group = "group2" diff --git a/example/vpnGateway/main.tf b/example/vpnGateway/main.tf index ad3e70b6..717c392f 100644 --- a/example/vpnGateway/main.tf +++ b/example/vpnGateway/main.tf @@ -1,9 +1,21 @@ +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-test-subnet" + cidr_block = "172.16.0.0/24" + zone_id = "cn-beijing-a" + vpc_id = volcengine_vpc.foo.id +} + resource "volcengine_vpn_gateway" "foo" { - vpc_id = "vpc-12b31m7z2kc8w17q7y2fih9ts" - subnet_id = "subnet-12bh8g2d7fshs17q7y2nx82uk" - bandwidth = 20 - vpn_gateway_name = "tf-test" - description = "tf-test" - period = 2 + vpc_id = volcengine_vpc.foo.id + subnet_id = volcengine_subnet.foo.id + bandwidth = 50 + vpn_gateway_name = "acc-test1" + description = "acc-test1" + period = 7 project_name = "default" } \ No newline at end of file diff --git a/example/vpnGatewayRoute/main.tf b/example/vpnGatewayRoute/main.tf index 3f590529..26f33873 100644 --- a/example/vpnGatewayRoute/main.tf +++ b/example/vpnGatewayRoute/main.tf @@ -1,5 +1,60 @@ +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-test-subnet" + cidr_block = "172.16.0.0/24" + zone_id = "cn-beijing-a" + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_vpn_gateway" "foo" { + vpc_id = volcengine_vpc.foo.id + subnet_id = volcengine_subnet.foo.id + bandwidth = 20 + vpn_gateway_name = "acc-test" + description = "acc-test" + period = 2 + project_name = "default" +} + +resource "volcengine_customer_gateway" "foo" { + ip_address = "192.0.1.3" + customer_gateway_name = "acc-test" + description = "acc-test" + project_name = "default" +} + +resource "volcengine_vpn_connection" "foo" { + vpn_connection_name = "acc-tf-test" + description = "acc-tf-test" + vpn_gateway_id = volcengine_vpn_gateway.foo.id + customer_gateway_id = volcengine_customer_gateway.foo.id + local_subnet = ["192.168.0.0/22"] + remote_subnet = ["192.161.0.0/20"] + dpd_action = "none" + nat_traversal = true + ike_config_psk = "acctest@!3" + ike_config_version = "ikev1" + ike_config_mode = "main" + ike_config_enc_alg = "aes" + ike_config_auth_alg = "md5" + ike_config_dh_group = "group2" + ike_config_lifetime = 9000 + ike_config_local_id = "acc_test" + ike_config_remote_id = "acc_test" + ipsec_config_enc_alg = "aes" + ipsec_config_auth_alg = "sha256" + ipsec_config_dh_group = "group2" + ipsec_config_lifetime = 9000 + project_name = "default" + log_enabled = false +} + resource "volcengine_vpn_gateway_route" "foo" { - vpn_gateway_id = "vgw-2c012ea9fm5mo2dx0efxg46qi" + vpn_gateway_id = volcengine_vpn_gateway.foo.id destination_cidr_block = "192.168.0.0/20" - next_hop_id = "vgc-2d5ww3ww2lwcg58ozfe61ppc3" + next_hop_id = volcengine_vpn_connection.foo.id } \ No newline at end of file diff --git a/volcengine/autoscaling/scaling_activity/data_source_volcengine_scaling_activities_test.go b/volcengine/autoscaling/scaling_activity/data_source_volcengine_scaling_activities_test.go new file mode 100644 index 00000000..b13aa91d --- /dev/null +++ b/volcengine/autoscaling/scaling_activity/data_source_volcengine_scaling_activities_test.go @@ -0,0 +1,240 @@ +package scaling_activity_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/autoscaling/scaling_activity" + "testing" +) + +const testAccVolcengineScalingActivitiesDatasourceConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = "${volcengine_vpc.foo.id}" +} + + +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_ecs_key_pair" "foo" { + description = "acc-test-2" + key_pair_name = "acc-test-key-pair-name" +} + +resource "volcengine_ecs_launch_template" "foo" { + description = "acc-test-desc" + eip_bandwidth = 200 + eip_billing_type = "PostPaidByBandwidth" + eip_isp = "BGP" + host_name = "acc-hostname" + image_id = "${data.volcengine_images.foo.images[0].image_id}" + instance_charge_type = "PostPaid" + instance_name = "acc-instance-name" + instance_type_id = "ecs.g1.large" + key_pair_name = "${volcengine_ecs_key_pair.foo.key_pair_name}" + launch_template_name = "acc-test-template" + network_interfaces { + subnet_id = "${volcengine_subnet.foo.id}" + security_group_ids = ["${volcengine_security_group.foo.id}"] + } + volumes { + volume_type = "ESSD_PL0" + size = 50 + delete_with_instance = true + } +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + subnet_ids = ["${volcengine_subnet.foo.id}"] + multi_az_policy = "BALANCE" + desire_instance_number = -1 + min_instance_number = 0 + max_instance_number = 10 + instance_terminate_policy = "OldestInstance" + default_cooldown = 10 + launch_template_id = "${volcengine_ecs_launch_template.foo.id}" + launch_template_version = "Default" +} + +resource "volcengine_scaling_group_enabler" "foo" { + scaling_group_id = "${volcengine_scaling_group.foo.id}" +} + +resource "volcengine_ecs_instance" "foo" { + count = 3 + instance_name = "acc-test-ecs-${count.index}" + description = "acc-test" + host_name = "tf-acc-test" + image_id = "${data.volcengine_images.foo.images[0].image_id}" + instance_type = "ecs.g1.large" + password = "93f0cb0614Aab12" + instance_charge_type = "PostPaid" + system_volume_type = "ESSD_PL0" + system_volume_size = 40 + subnet_id = "${volcengine_subnet.foo.id}" + security_group_ids = ["${volcengine_security_group.foo.id}"] +} + +resource "volcengine_scaling_instance_attachment" "foo" { + count = length(volcengine_ecs_instance.foo) + instance_id = volcengine_ecs_instance.foo[count.index].id + scaling_group_id = "${volcengine_scaling_group.foo.id}" + entrusted = true + + depends_on = [ + volcengine_scaling_group_enabler.foo + ] +} +` + +const testAccVolcengineScalingActivitiesDatasourceReadConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = "${volcengine_vpc.foo.id}" +} + + +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_ecs_key_pair" "foo" { + description = "acc-test-2" + key_pair_name = "acc-test-key-pair-name" +} + +resource "volcengine_ecs_launch_template" "foo" { + description = "acc-test-desc" + eip_bandwidth = 200 + eip_billing_type = "PostPaidByBandwidth" + eip_isp = "BGP" + host_name = "acc-hostname" + image_id = "${data.volcengine_images.foo.images[0].image_id}" + instance_charge_type = "PostPaid" + instance_name = "acc-instance-name" + instance_type_id = "ecs.g1.large" + key_pair_name = "${volcengine_ecs_key_pair.foo.key_pair_name}" + launch_template_name = "acc-test-template" + network_interfaces { + subnet_id = "${volcengine_subnet.foo.id}" + security_group_ids = ["${volcengine_security_group.foo.id}"] + } + volumes { + volume_type = "ESSD_PL0" + size = 50 + delete_with_instance = true + } +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + subnet_ids = ["${volcengine_subnet.foo.id}"] + multi_az_policy = "BALANCE" + desire_instance_number = -1 + min_instance_number = 0 + max_instance_number = 10 + instance_terminate_policy = "OldestInstance" + default_cooldown = 10 + launch_template_id = "${volcengine_ecs_launch_template.foo.id}" + launch_template_version = "Default" +} + +resource "volcengine_scaling_group_enabler" "foo" { + scaling_group_id = "${volcengine_scaling_group.foo.id}" +} + +resource "volcengine_ecs_instance" "foo" { + count = 3 + instance_name = "acc-test-ecs-${count.index}" + description = "acc-test" + host_name = "tf-acc-test" + image_id = "${data.volcengine_images.foo.images[0].image_id}" + instance_type = "ecs.g1.large" + password = "93f0cb0614Aab12" + instance_charge_type = "PostPaid" + system_volume_type = "ESSD_PL0" + system_volume_size = 40 + subnet_id = "${volcengine_subnet.foo.id}" + security_group_ids = ["${volcengine_security_group.foo.id}"] +} + +resource "volcengine_scaling_instance_attachment" "foo" { + count = length(volcengine_ecs_instance.foo) + instance_id = volcengine_ecs_instance.foo[count.index].id + scaling_group_id = "${volcengine_scaling_group.foo.id}" + entrusted = true + + depends_on = [ + volcengine_scaling_group_enabler.foo + ] +} + +data "volcengine_scaling_activities" "foo"{ + scaling_group_id = volcengine_scaling_group.foo.id +} +` + +func TestAccVolcengineScalingActivitiesDatasource_Basic(t *testing.T) { + resourceName := "data.volcengine_scaling_activities.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &scaling_activity.VolcengineScalingActivityService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineScalingActivitiesDatasourceConfig, + Check: resource.ComposeTestCheckFunc(), + }, + { + Config: testAccVolcengineScalingActivitiesDatasourceReadConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(acc.ResourceId, "activities.#", "3"), + ), + }, + }, + }) +} diff --git a/volcengine/autoscaling/scaling_configuration/data_source_volcengine_scaling_configurations_test.go b/volcengine/autoscaling/scaling_configuration/data_source_volcengine_scaling_configurations_test.go new file mode 100644 index 00000000..e31acf0d --- /dev/null +++ b/volcengine/autoscaling/scaling_configuration/data_source_volcengine_scaling_configurations_test.go @@ -0,0 +1,91 @@ +package scaling_configuration_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/autoscaling/scaling_configuration" + "testing" +) + +const testAccVolcengineScalingConfigurationsDatasourceConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = "${volcengine_vpc.foo.id}" +} + +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + 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 +} + +resource "volcengine_scaling_configuration" "foo" { + count = 3 + image_id = "${data.volcengine_images.foo.images[0].image_id}" + instance_name = "acc-test-instance" + instance_types = ["ecs.g1.large"] + password = "93f0cb0614Aab12" + scaling_configuration_name = "acc-test-scaling-config-${count.index}" + scaling_group_id = "${volcengine_scaling_group.foo.id}" + security_group_ids = ["${volcengine_security_group.foo.id}"] + volumes { + volume_type = "ESSD_PL0" + size = 50 + delete_with_instance = true + } +} + +data "volcengine_scaling_configurations" "foo"{ + ids = volcengine_scaling_configuration.foo[*].id +} +` + +func TestAccVolcengineScalingConfigurationsDatasource_Basic(t *testing.T) { + resourceName := "data.volcengine_scaling_configurations.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &scaling_configuration.VolcengineScalingConfigurationService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineScalingConfigurationsDatasourceConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(acc.ResourceId, "scaling_configurations.#", "3"), + ), + }, + }, + }) +} diff --git a/volcengine/autoscaling/scaling_configuration/resource_volcengine_scaling_configuration_test.go b/volcengine/autoscaling/scaling_configuration/resource_volcengine_scaling_configuration_test.go new file mode 100644 index 00000000..65e93cc8 --- /dev/null +++ b/volcengine/autoscaling/scaling_configuration/resource_volcengine_scaling_configuration_test.go @@ -0,0 +1,237 @@ +package scaling_configuration_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/autoscaling/scaling_configuration" + "testing" +) + +const testAccVolcengineScalingConfigurationCreateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = "${volcengine_vpc.foo.id}" +} + +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + 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 +} + +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"] + password = "93f0cb0614Aab12" + scaling_configuration_name = "acc-test-scaling-config" + scaling_group_id = "${volcengine_scaling_group.foo.id}" + security_group_ids = ["${volcengine_security_group.foo.id}"] + volumes { + volume_type = "ESSD_PL0" + size = 50 + delete_with_instance = true + } +} +` + +const testAccVolcengineScalingConfigurationUpdateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = "${volcengine_vpc.foo.id}" +} + +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + 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 +} + +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"] + password = "93f0cb0614Aab12" + scaling_configuration_name = "acc-test-scaling-config-new" + scaling_group_id = "${volcengine_scaling_group.foo.id}" + security_group_ids = ["${volcengine_security_group.foo.id}"] + volumes { + volume_type = "ESSD_PL0" + size = 50 + delete_with_instance = true + } + + volumes { + volume_type = "ESSD_PL0" + size = 100 + delete_with_instance = true + } + + tags { + key = "k1" + value = "v1" + } +} +` + +func TestAccVolcengineScalingConfigurationResource_Basic(t *testing.T) { + resourceName := "volcengine_scaling_configuration.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &scaling_configuration.VolcengineScalingConfigurationService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineScalingConfigurationCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "instance_name", "acc-test-instance"), + resource.TestCheckResourceAttr(acc.ResourceId, "instance_types.#", "1"), + resource.TestCheckResourceAttr(acc.ResourceId, "password", "93f0cb0614Aab12"), + resource.TestCheckResourceAttr(acc.ResourceId, "scaling_configuration_name", "acc-test-scaling-config"), + resource.TestCheckResourceAttr(acc.ResourceId, "security_enhancement_strategy", "Active"), + resource.TestCheckResourceAttr(acc.ResourceId, "security_group_ids.#", "1"), + resource.TestCheckResourceAttr(acc.ResourceId, "spot_strategy", "NoSpot"), + resource.TestCheckResourceAttr(acc.ResourceId, "volumes.#", "1"), + resource.TestCheckResourceAttr(acc.ResourceId, "volumes.0.volume_type", "ESSD_PL0"), + resource.TestCheckResourceAttr(acc.ResourceId, "volumes.0.size", "50"), + resource.TestCheckResourceAttr(acc.ResourceId, "volumes.0.delete_with_instance", "true"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "password", + }, + }, + }, + }) +} + +func TestAccVolcengineScalingConfigurationResource_Update(t *testing.T) { + resourceName := "volcengine_scaling_configuration.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &scaling_configuration.VolcengineScalingConfigurationService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineScalingConfigurationCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "instance_name", "acc-test-instance"), + resource.TestCheckResourceAttr(acc.ResourceId, "instance_types.#", "1"), + resource.TestCheckResourceAttr(acc.ResourceId, "password", "93f0cb0614Aab12"), + resource.TestCheckResourceAttr(acc.ResourceId, "scaling_configuration_name", "acc-test-scaling-config"), + resource.TestCheckResourceAttr(acc.ResourceId, "security_enhancement_strategy", "Active"), + resource.TestCheckResourceAttr(acc.ResourceId, "security_group_ids.#", "1"), + resource.TestCheckResourceAttr(acc.ResourceId, "spot_strategy", "NoSpot"), + resource.TestCheckResourceAttr(acc.ResourceId, "volumes.#", "1"), + resource.TestCheckResourceAttr(acc.ResourceId, "volumes.0.volume_type", "ESSD_PL0"), + resource.TestCheckResourceAttr(acc.ResourceId, "volumes.0.size", "50"), + resource.TestCheckResourceAttr(acc.ResourceId, "volumes.0.delete_with_instance", "true"), + ), + }, + { + Config: testAccVolcengineScalingConfigurationUpdateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "instance_name", "acc-test-instance-new"), + resource.TestCheckResourceAttr(acc.ResourceId, "instance_types.#", "1"), + resource.TestCheckResourceAttr(acc.ResourceId, "password", "93f0cb0614Aab12"), + resource.TestCheckResourceAttr(acc.ResourceId, "scaling_configuration_name", "acc-test-scaling-config-new"), + resource.TestCheckResourceAttr(acc.ResourceId, "security_enhancement_strategy", "Active"), + resource.TestCheckResourceAttr(acc.ResourceId, "security_group_ids.#", "1"), + resource.TestCheckResourceAttr(acc.ResourceId, "spot_strategy", "NoSpot"), + resource.TestCheckResourceAttr(acc.ResourceId, "volumes.#", "2"), + resource.TestCheckResourceAttr(acc.ResourceId, "volumes.0.volume_type", "ESSD_PL0"), + resource.TestCheckResourceAttr(acc.ResourceId, "volumes.0.size", "50"), + resource.TestCheckResourceAttr(acc.ResourceId, "volumes.0.delete_with_instance", "true"), + resource.TestCheckResourceAttr(acc.ResourceId, "volumes.1.volume_type", "ESSD_PL0"), + resource.TestCheckResourceAttr(acc.ResourceId, "volumes.1.size", "100"), + resource.TestCheckResourceAttr(acc.ResourceId, "volumes.1.delete_with_instance", "true"), + resource.TestCheckResourceAttr(acc.ResourceId, "tags.#", "1"), + volcengine.TestCheckTypeSetElemNestedAttrs(acc.ResourceId, "tags.*", map[string]string{ + "key": "k1", + "value": "v1", + }), + ), + }, + { + Config: testAccVolcengineScalingConfigurationUpdateConfig, + PlanOnly: true, + ExpectNonEmptyPlan: false, // 修改之后,不应该再产生diff + }, + }, + }) +} diff --git a/volcengine/autoscaling/scaling_configuration_attachment/resource_volcengine_scaling_configuration_attachment_test.go b/volcengine/autoscaling/scaling_configuration_attachment/resource_volcengine_scaling_configuration_attachment_test.go new file mode 100644 index 00000000..405540dc --- /dev/null +++ b/volcengine/autoscaling/scaling_configuration_attachment/resource_volcengine_scaling_configuration_attachment_test.go @@ -0,0 +1,190 @@ +package scaling_configuration_attachment_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/autoscaling/scaling_configuration_attachment" + "testing" +) + +const testAccVolcengineScalingConfigurationAttachmentCreateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = "${volcengine_vpc.foo.id}" +} + +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + 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 +} + +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"] + password = "93f0cb0614Aab12" + scaling_configuration_name = "acc-test-scaling-config" + scaling_group_id = "${volcengine_scaling_group.foo.id}" + security_group_ids = ["${volcengine_security_group.foo.id}"] + volumes { + volume_type = "ESSD_PL0" + size = 50 + delete_with_instance = true + } +} + +resource "volcengine_scaling_configuration_attachment" "foo" { + scaling_configuration_id = "${volcengine_scaling_configuration.foo.id}" +} +` + +const testAccVolcengineScalingConfigurationAttachmentUpdateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = "${volcengine_vpc.foo.id}" +} + +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_ecs_key_pair" "foo" { + description = "acc-test-2" + key_pair_name = "acc-test-key-pair-name" +} + +resource "volcengine_ecs_launch_template" "foo" { + description = "acc-test-desc" + eip_bandwidth = 200 + eip_billing_type = "PostPaidByBandwidth" + eip_isp = "BGP" + host_name = "acc-hostname" + image_id = "${data.volcengine_images.foo.images[0].image_id}" + instance_charge_type = "PostPaid" + instance_name = "acc-instance-name" + instance_type_id = "ecs.g1.large" + key_pair_name = "${volcengine_ecs_key_pair.foo.key_pair_name}" + launch_template_name = "acc-test-template" + network_interfaces { + subnet_id = "${volcengine_subnet.foo.id}" + security_group_ids = ["${volcengine_security_group.foo.id}"] + } + volumes { + volume_type = "ESSD_PL0" + size = 50 + delete_with_instance = true + } +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + 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 + launch_template_id = "${volcengine_ecs_launch_template.foo.id}" + launch_template_version = "Default" +} + +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"] + password = "93f0cb0614Aab12" + scaling_configuration_name = "acc-test-scaling-config" + scaling_group_id = "${volcengine_scaling_group.foo.id}" + security_group_ids = ["${volcengine_security_group.foo.id}"] + volumes { + volume_type = "ESSD_PL0" + size = 50 + delete_with_instance = true + } +} + +resource "volcengine_scaling_configuration_attachment" "foo" { + scaling_configuration_id = "${volcengine_scaling_configuration.foo.id}" +} +` + +func TestAccVolcengineScalingConfigurationAttachmentResource_Basic(t *testing.T) { + resourceName := "volcengine_scaling_configuration_attachment.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &scaling_configuration_attachment.VolcengineScalingConfigurationAttachmentService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineScalingConfigurationAttachmentCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccVolcengineScalingConfigurationAttachmentUpdateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + ), + }, + }, + }) +} diff --git a/volcengine/autoscaling/scaling_group/data_source_volcengine_scaling_groups_test.go b/volcengine/autoscaling/scaling_group/data_source_volcengine_scaling_groups_test.go new file mode 100644 index 00000000..9cde254d --- /dev/null +++ b/volcengine/autoscaling/scaling_group/data_source_volcengine_scaling_groups_test.go @@ -0,0 +1,75 @@ +package scaling_group_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/autoscaling/scaling_group" + "testing" +) + +const testAccScalingGroupDatasourceConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_scaling_group" "foo" { + count = 3 + scaling_group_name = "acc-test-scaling-group-${count.index}" + subnet_ids = ["${volcengine_subnet.foo.id}"] + multi_az_policy = "BALANCE" + desire_instance_number = 0 + min_instance_number = 0 + max_instance_number = 10 + instance_terminate_policy = "OldestInstance" + default_cooldown = 30 + + tags { + key = "k2" + value = "v2" + } + + tags { + key = "k1" + value = "v1" + } +} + +data "volcengine_scaling_groups" "foo"{ + ids = volcengine_scaling_group.foo[*].id +} +` + +func TestAccVolcengineScalingGroupDatasource_Basic(t *testing.T) { + resourceName := "data.volcengine_scaling_groups.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &scaling_group.VolcengineScalingGroupService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + Steps: []resource.TestStep{ + { + Config: testAccScalingGroupDatasourceConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(acc.ResourceId, "scaling_groups.#", "3"), + ), + }, + }, + }) +} diff --git a/volcengine/autoscaling/scaling_group/resource_volcengine_scaling_group_test.go b/volcengine/autoscaling/scaling_group/resource_volcengine_scaling_group_test.go new file mode 100644 index 00000000..03773bb9 --- /dev/null +++ b/volcengine/autoscaling/scaling_group/resource_volcengine_scaling_group_test.go @@ -0,0 +1,169 @@ +package scaling_group_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/autoscaling/scaling_group" + "testing" +) + +const testAccScalingGroupForCreate = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + 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 +} +` + +const testAccScalingGroupForUpdate = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group-new" + subnet_ids = ["${volcengine_subnet.foo.id}"] + multi_az_policy = "BALANCE" + desire_instance_number = 0 + min_instance_number = 0 + max_instance_number = 10 + instance_terminate_policy = "OldestInstance" + default_cooldown = 30 + + tags { + key = "k2" + value = "v2" + } + + tags { + key = "k1" + value = "v1" + } +} +` + +func TestAccVolcengineScalingGroupResource_Basic(t *testing.T) { + resourceName := "volcengine_scaling_group.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &scaling_group.VolcengineScalingGroupService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccScalingGroupForCreate, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "scaling_group_name", "acc-test-scaling-group"), + resource.TestCheckResourceAttr(acc.ResourceId, "multi_az_policy", "BALANCE"), + resource.TestCheckResourceAttr(acc.ResourceId, "instance_terminate_policy", "OldestInstance"), + resource.TestCheckResourceAttr(acc.ResourceId, "max_instance_number", "1"), + resource.TestCheckResourceAttr(acc.ResourceId, "min_instance_number", "0"), + resource.TestCheckResourceAttr(acc.ResourceId, "desire_instance_number", "0"), + resource.TestCheckResourceAttr(acc.ResourceId, "default_cooldown", "10"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccVolcengineScalingGroupResource_Update(t *testing.T) { + resourceName := "volcengine_scaling_group.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &scaling_group.VolcengineScalingGroupService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccScalingGroupForCreate, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "scaling_group_name", "acc-test-scaling-group"), + resource.TestCheckResourceAttr(acc.ResourceId, "multi_az_policy", "BALANCE"), + resource.TestCheckResourceAttr(acc.ResourceId, "instance_terminate_policy", "OldestInstance"), + resource.TestCheckResourceAttr(acc.ResourceId, "max_instance_number", "1"), + resource.TestCheckResourceAttr(acc.ResourceId, "min_instance_number", "0"), + resource.TestCheckResourceAttr(acc.ResourceId, "desire_instance_number", "0"), + resource.TestCheckResourceAttr(acc.ResourceId, "default_cooldown", "10"), + ), + }, + { + Config: testAccScalingGroupForUpdate, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "scaling_group_name", "acc-test-scaling-group-new"), + resource.TestCheckResourceAttr(acc.ResourceId, "multi_az_policy", "BALANCE"), + resource.TestCheckResourceAttr(acc.ResourceId, "instance_terminate_policy", "OldestInstance"), + resource.TestCheckResourceAttr(acc.ResourceId, "max_instance_number", "10"), + resource.TestCheckResourceAttr(acc.ResourceId, "min_instance_number", "0"), + resource.TestCheckResourceAttr(acc.ResourceId, "desire_instance_number", "0"), + resource.TestCheckResourceAttr(acc.ResourceId, "default_cooldown", "30"), + volcengine.TestCheckTypeSetElemNestedAttrs(acc.ResourceId, "tags.*", map[string]string{ + "key": "k1", + "value": "v1", + }), + volcengine.TestCheckTypeSetElemNestedAttrs(acc.ResourceId, "tags.*", map[string]string{ + "key": "k2", + "value": "v2", + }), + ), + }, + { + Config: testAccScalingGroupForUpdate, + PlanOnly: true, + ExpectNonEmptyPlan: false, // 修改之后,不应该再产生diff + }, + }, + }) +} diff --git a/volcengine/autoscaling/scaling_group_enabler/resource_volcengine_scaling_group_enabler_test.go b/volcengine/autoscaling/scaling_group_enabler/resource_volcengine_scaling_group_enabler_test.go new file mode 100644 index 00000000..45d3f106 --- /dev/null +++ b/volcengine/autoscaling/scaling_group_enabler/resource_volcengine_scaling_group_enabler_test.go @@ -0,0 +1,111 @@ +package scaling_group_enabler_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/autoscaling/scaling_group_enabler" + "testing" +) + +const testAccVolcengineScalingGroupEnablerCreateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = "${volcengine_vpc.foo.id}" +} + +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_ecs_key_pair" "foo" { + description = "acc-test-2" + key_pair_name = "acc-test-key-pair-name" +} + +resource "volcengine_ecs_launch_template" "foo" { + description = "acc-test-desc" + eip_bandwidth = 200 + eip_billing_type = "PostPaidByBandwidth" + eip_isp = "BGP" + host_name = "acc-hostname" + image_id = "${data.volcengine_images.foo.images[0].image_id}" + instance_charge_type = "PostPaid" + instance_name = "acc-instance-name" + instance_type_id = "ecs.g1.large" + key_pair_name = "${volcengine_ecs_key_pair.foo.key_pair_name}" + launch_template_name = "acc-test-template" + network_interfaces { + subnet_id = "${volcengine_subnet.foo.id}" + security_group_ids = ["${volcengine_security_group.foo.id}"] + } + volumes { + volume_type = "ESSD_PL0" + size = 50 + delete_with_instance = true + } +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + 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 + launch_template_id = "${volcengine_ecs_launch_template.foo.id}" + launch_template_version = "Default" +} + +resource "volcengine_scaling_group_enabler" "foo" { + scaling_group_id = "${volcengine_scaling_group.foo.id}" +} +` + +func TestAccVolcengineScalingGroupEnablerResource_Basic(t *testing.T) { + resourceName := "volcengine_scaling_group_enabler.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &scaling_group_enabler.VolcengineScalingGroupEnablerService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineScalingGroupEnablerCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/volcengine/autoscaling/scaling_group_enabler/service_volcengine_scaling_group_enabler.go b/volcengine/autoscaling/scaling_group_enabler/service_volcengine_scaling_group_enabler.go index e18c99b6..91c79c40 100644 --- a/volcengine/autoscaling/scaling_group_enabler/service_volcengine_scaling_group_enabler.go +++ b/volcengine/autoscaling/scaling_group_enabler/service_volcengine_scaling_group_enabler.go @@ -37,7 +37,7 @@ func (s *VolcengineScalingGroupEnablerService) ReadResources(m map[string]interf return data, err } } - logger.Debug(logger.RespFormat, action, action, resp) + logger.Debug(logger.RespFormat, action, action, *resp) results, err = ve.ObtainSdkValue("Result.ScalingGroups", *resp) if err != nil { return data, err diff --git a/volcengine/autoscaling/scaling_instance/data_source_volcengine_scaling_instances_test.go b/volcengine/autoscaling/scaling_instance/data_source_volcengine_scaling_instances_test.go new file mode 100644 index 00000000..a0a2bf95 --- /dev/null +++ b/volcengine/autoscaling/scaling_instance/data_source_volcengine_scaling_instances_test.go @@ -0,0 +1,137 @@ +package scaling_instance_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/autoscaling/scaling_instance" + "testing" +) + +const testAccVolcengineScalingInstancesDatasourceConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = "${volcengine_vpc.foo.id}" +} + + +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_ecs_key_pair" "foo" { + description = "acc-test-2" + key_pair_name = "acc-test-key-pair-name" +} + +resource "volcengine_ecs_launch_template" "foo" { + description = "acc-test-desc" + eip_bandwidth = 200 + eip_billing_type = "PostPaidByBandwidth" + eip_isp = "BGP" + host_name = "acc-hostname" + image_id = "${data.volcengine_images.foo.images[0].image_id}" + instance_charge_type = "PostPaid" + instance_name = "acc-instance-name" + instance_type_id = "ecs.g1.large" + key_pair_name = "${volcengine_ecs_key_pair.foo.key_pair_name}" + launch_template_name = "acc-test-template" + network_interfaces { + subnet_id = "${volcengine_subnet.foo.id}" + security_group_ids = ["${volcengine_security_group.foo.id}"] + } + volumes { + volume_type = "ESSD_PL0" + size = 50 + delete_with_instance = true + } +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + subnet_ids = ["${volcengine_subnet.foo.id}"] + multi_az_policy = "BALANCE" + desire_instance_number = -1 + min_instance_number = 0 + max_instance_number = 10 + instance_terminate_policy = "OldestInstance" + default_cooldown = 10 + launch_template_id = "${volcengine_ecs_launch_template.foo.id}" + launch_template_version = "Default" +} + +resource "volcengine_scaling_group_enabler" "foo" { + scaling_group_id = "${volcengine_scaling_group.foo.id}" +} + +resource "volcengine_ecs_instance" "foo" { + count = 3 + instance_name = "acc-test-ecs-${count.index}" + description = "acc-test" + host_name = "tf-acc-test" + image_id = "${data.volcengine_images.foo.images[0].image_id}" + instance_type = "ecs.g1.large" + password = "93f0cb0614Aab12" + instance_charge_type = "PostPaid" + system_volume_type = "ESSD_PL0" + system_volume_size = 40 + subnet_id = "${volcengine_subnet.foo.id}" + security_group_ids = ["${volcengine_security_group.foo.id}"] +} + +resource "volcengine_scaling_instance_attachment" "foo" { + count = length(volcengine_ecs_instance.foo) + instance_id = volcengine_ecs_instance.foo[count.index].id + scaling_group_id = "${volcengine_scaling_group.foo.id}" + entrusted = true + + depends_on = [ + volcengine_scaling_group_enabler.foo + ] +} + +data "volcengine_scaling_instances" "foo" { + scaling_group_id = volcengine_scaling_group.foo.id + ids = volcengine_scaling_instance_attachment.foo[*].instance_id +} +` + +func TestAccVolcengineScalingInstancesDatasource_Basic(t *testing.T) { + resourceName := "data.volcengine_scaling_instances.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &scaling_instance.VolcengineScalingInstanceService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineScalingInstancesDatasourceConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(acc.ResourceId, "scaling_instances.#", "3"), + ), + }, + }, + }) +} diff --git a/volcengine/autoscaling/scaling_instance/service_volcengine_scaling_instance.go b/volcengine/autoscaling/scaling_instance/service_volcengine_scaling_instance.go index ac182fef..052d8712 100644 --- a/volcengine/autoscaling/scaling_instance/service_volcengine_scaling_instance.go +++ b/volcengine/autoscaling/scaling_instance/service_volcengine_scaling_instance.go @@ -40,6 +40,7 @@ func (s *VolcengineScalingInstanceService) ReadResources(m map[string]interface{ return ve.WithPageNumberQuery(m, "PageSize", "PageNumber", 50, 1, func(condition map[string]interface{}) ([]interface{}, error) { universalClient := s.Client.UniversalClient action := "DescribeScalingInstances" + logger.Debug(logger.ReqFormat, action, condition) if condition == nil { resp, err = universalClient.DoCall(getUniversalInfo(action), nil) if err != nil { @@ -51,7 +52,7 @@ func (s *VolcengineScalingInstanceService) ReadResources(m map[string]interface{ return data, err } } - logger.Debug(logger.RespFormat, action, action, resp) + logger.Debug(logger.RespFormat, action, condition, *resp) results, err = ve.ObtainSdkValue("Result.ScalingInstances", *resp) if err != nil { return data, err diff --git a/volcengine/autoscaling/scaling_instance_attachment/resource_volcengine_scaling_instance_attachment.go b/volcengine/autoscaling/scaling_instance_attachment/resource_volcengine_scaling_instance_attachment.go index 1ead9b59..3c6244ff 100644 --- a/volcengine/autoscaling/scaling_instance_attachment/resource_volcengine_scaling_instance_attachment.go +++ b/volcengine/autoscaling/scaling_instance_attachment/resource_volcengine_scaling_instance_attachment.go @@ -44,6 +44,7 @@ func ResourceVolcengineScalingInstanceAttachment() *schema.Resource { "entrusted": { Type: schema.TypeBool, Optional: true, + ForceNew: true, Description: "Whether to host the instance to a scaling group. Default value is false.", }, "delete_type": { diff --git a/volcengine/autoscaling/scaling_instance_attachment/resource_volcengine_scaling_instance_attachment_test.go b/volcengine/autoscaling/scaling_instance_attachment/resource_volcengine_scaling_instance_attachment_test.go new file mode 100644 index 00000000..fd873da2 --- /dev/null +++ b/volcengine/autoscaling/scaling_instance_attachment/resource_volcengine_scaling_instance_attachment_test.go @@ -0,0 +1,137 @@ +package scaling_instance_attachment_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/autoscaling/scaling_instance_attachment" + "testing" +) + +const testAccVolcengineScalingInstanceAttachmentCreateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = "${volcengine_vpc.foo.id}" +} + + +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_ecs_key_pair" "foo" { + description = "acc-test-2" + key_pair_name = "acc-test-key-pair-name" +} + +resource "volcengine_ecs_launch_template" "foo" { + description = "acc-test-desc" + eip_bandwidth = 200 + eip_billing_type = "PostPaidByBandwidth" + eip_isp = "BGP" + host_name = "acc-hostname" + image_id = "${data.volcengine_images.foo.images[0].image_id}" + instance_charge_type = "PostPaid" + instance_name = "acc-instance-name" + instance_type_id = "ecs.g1.large" + key_pair_name = "${volcengine_ecs_key_pair.foo.key_pair_name}" + launch_template_name = "acc-test-template" + network_interfaces { + subnet_id = "${volcengine_subnet.foo.id}" + security_group_ids = ["${volcengine_security_group.foo.id}"] + } + volumes { + volume_type = "ESSD_PL0" + size = 50 + delete_with_instance = true + } +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + subnet_ids = ["${volcengine_subnet.foo.id}"] + multi_az_policy = "BALANCE" + desire_instance_number = -1 + min_instance_number = 0 + max_instance_number = 1 + instance_terminate_policy = "OldestInstance" + default_cooldown = 10 + launch_template_id = "${volcengine_ecs_launch_template.foo.id}" + launch_template_version = "Default" +} + +resource "volcengine_scaling_group_enabler" "foo" { + scaling_group_id = "${volcengine_scaling_group.foo.id}" +} + +resource "volcengine_ecs_instance" "foo" { + instance_name = "acc-test-ecs" + description = "acc-test" + host_name = "tf-acc-test" + image_id = "${data.volcengine_images.foo.images[0].image_id}" + instance_type = "ecs.g1.large" + password = "93f0cb0614Aab12" + instance_charge_type = "PostPaid" + system_volume_type = "ESSD_PL0" + system_volume_size = 40 + subnet_id = "${volcengine_subnet.foo.id}" + security_group_ids = ["${volcengine_security_group.foo.id}"] +} + +resource "volcengine_scaling_instance_attachment" "foo" { + instance_id = "${volcengine_ecs_instance.foo.id}" + scaling_group_id = "${volcengine_scaling_group.foo.id}" + entrusted = true + + depends_on = [ + volcengine_scaling_group_enabler.foo + ] +} +` + +func TestAccVolcengineScalingInstanceAttachmentResource_Basic(t *testing.T) { + resourceName := "volcengine_scaling_instance_attachment.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &scaling_instance_attachment.VolcengineScalingInstanceAttachmentService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineScalingInstanceAttachmentCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "entrusted", "true"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/volcengine/autoscaling/scaling_instance_attachment/service_volcengine_scaling_instance_attachment.go b/volcengine/autoscaling/scaling_instance_attachment/service_volcengine_scaling_instance_attachment.go index 2078004b..4ef8feb7 100644 --- a/volcengine/autoscaling/scaling_instance_attachment/service_volcengine_scaling_instance_attachment.go +++ b/volcengine/autoscaling/scaling_instance_attachment/service_volcengine_scaling_instance_attachment.go @@ -3,6 +3,7 @@ package scaling_instance_attachment import ( "errors" "fmt" + "github.com/volcengine/terraform-provider-volcengine/volcengine/autoscaling/scaling_group" "strings" "time" @@ -91,6 +92,7 @@ func (s *VolcengineScalingInstanceAttachmentService) ReadResource(resourceData * status = tempData["Status"].(string) data["InstanceId"] = instanceId data["Status"] = status + data["Entrusted"] = tempData["Entrusted"] return data, nil } @@ -139,7 +141,7 @@ func (VolcengineScalingInstanceAttachmentService) WithResourceResponseHandlers(s func (s *VolcengineScalingInstanceAttachmentService) CreateResource(d *schema.ResourceData, resource *schema.Resource) []ve.Callback { instanceId := d.Get("instance_id").(string) - return s.attachInstances(d.Get("scaling_group_id").(string), instanceId, d.Timeout(schema.TimeoutUpdate)) + return s.attachInstances(d, d.Get("scaling_group_id").(string), instanceId, d.Timeout(schema.TimeoutUpdate)) } func (s *VolcengineScalingInstanceAttachmentService) ModifyResource(d *schema.ResourceData, resource *schema.Resource) []ve.Callback { @@ -150,7 +152,7 @@ func (s *VolcengineScalingInstanceAttachmentService) RemoveResource(d *schema.Re instanceId := d.Get("instance_id").(string) deleteType := d.Get("delete_type").(string) detachOption := d.Get("detach_option").(string) - return s.removeInstances(d.Get("scaling_group_id").(string), instanceId, d.Timeout(schema.TimeoutDelete), deleteType, detachOption) + return s.removeInstances(d, d.Get("scaling_group_id").(string), instanceId, deleteType, detachOption) } func (s *VolcengineScalingInstanceAttachmentService) DatasourceResources(*schema.ResourceData, *schema.Resource) ve.DataSourceInfo { @@ -161,7 +163,7 @@ func (s *VolcengineScalingInstanceAttachmentService) ReadResourceId(id string) s return id } -func (s *VolcengineScalingInstanceAttachmentService) attachInstances(groupId string, instanceId string, timeout time.Duration) []ve.Callback { +func (s *VolcengineScalingInstanceAttachmentService) attachInstances(d *schema.ResourceData, groupId string, instanceId string, timeout time.Duration) []ve.Callback { callbacks := make([]ve.Callback, 0) attachCallback := ve.Callback{ Call: ve.SdkCall{ @@ -190,17 +192,27 @@ func (s *VolcengineScalingInstanceAttachmentService) attachInstances(groupId str d.SetId(fmt.Sprint((*call.SdkParam)["ScalingGroupId"], ":", (*call.SdkParam)["InstanceIds.1"])) return nil }, + LockId: func(d *schema.ResourceData) string { + return d.Get("scaling_group_id").(string) + }, Refresh: &ve.StateRefresh{ Target: []string{"InService", "Protected"}, Timeout: timeout, }, + ExtraRefresh: map[ve.ResourceService]*ve.StateRefresh{ + scaling_group.NewScalingGroupService(s.Client): { + Target: []string{"Active"}, + Timeout: d.Timeout(schema.TimeoutCreate), + ResourceId: d.Get("scaling_group_id").(string), + }, + }, }, } callbacks = append(callbacks, attachCallback) return callbacks } -func (s *VolcengineScalingInstanceAttachmentService) removeInstances(groupId string, instanceId string, timeout time.Duration, deleteType, detachOption string) []ve.Callback { +func (s *VolcengineScalingInstanceAttachmentService) removeInstances(d *schema.ResourceData, groupId string, instanceId string, deleteType, detachOption string) []ve.Callback { var action string if deleteType == "Detach" { action = "DetachInstances" @@ -225,6 +237,9 @@ func (s *VolcengineScalingInstanceAttachmentService) removeInstances(groupId str *call.SdkParam = param return true, nil }, + LockId: func(d *schema.ResourceData) string { + return d.Get("scaling_group_id").(string) + }, ExecuteCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (*map[string]interface{}, error) { logger.Debug(logger.RespFormat, call.Action, call.SdkParam) common, err := s.Client.UniversalClient.DoCall(getUniversalInfo(call.Action), call.SdkParam) @@ -234,6 +249,13 @@ func (s *VolcengineScalingInstanceAttachmentService) removeInstances(groupId str time.Sleep(10 * time.Second) // remove以后需要等一下 return common, nil }, + ExtraRefresh: map[ve.ResourceService]*ve.StateRefresh{ + scaling_group.NewScalingGroupService(s.Client): { + Target: []string{"Active"}, + Timeout: d.Timeout(schema.TimeoutCreate), + ResourceId: d.Get("scaling_group_id").(string), + }, + }, CallError: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall, baseErr error) error { return resource.Retry(15*time.Minute, func() *resource.RetryError { _, callErr := s.ReadResource(d, d.Id()) diff --git a/volcengine/autoscaling/scaling_lifecycle_hook/data_source_volcengine_scaling_lifecycle_hooks_test.go b/volcengine/autoscaling/scaling_lifecycle_hook/data_source_volcengine_scaling_lifecycle_hooks_test.go new file mode 100644 index 00000000..313642f5 --- /dev/null +++ b/volcengine/autoscaling/scaling_lifecycle_hook/data_source_volcengine_scaling_lifecycle_hooks_test.go @@ -0,0 +1,74 @@ +package scaling_lifecycle_hook_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/autoscaling/scaling_lifecycle_hook" + "testing" +) + +const testAccVolcengineScalingLifecycleHooksDatasourceConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +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 + instance_terminate_policy = "OldestInstance" + default_cooldown = 10 +} + +resource "volcengine_scaling_lifecycle_hook" "foo" { + count = 3 + lifecycle_hook_name = "acc-test-lifecycle-${count.index}" + lifecycle_hook_policy = "CONTINUE" + lifecycle_hook_timeout = 30 + lifecycle_hook_type = "SCALE_IN" + scaling_group_id = "${volcengine_scaling_group.foo.id}" +} + +data "volcengine_scaling_lifecycle_hooks" "foo"{ + ids = volcengine_scaling_lifecycle_hook.foo[*].lifecycle_hook_id + scaling_group_id = "${volcengine_scaling_group.foo.id}" +} +` + +func TestAccVolcengineScalingLifecycleHooksDatasource_Basic(t *testing.T) { + resourceName := "data.volcengine_scaling_lifecycle_hooks.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &scaling_lifecycle_hook.VolcengineScalingLifecycleHookService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineScalingLifecycleHooksDatasourceConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(acc.ResourceId, "lifecycle_hooks.#", "3"), + ), + }, + }, + }) +} diff --git a/volcengine/autoscaling/scaling_lifecycle_hook/resource_volcengine_scaling_lifecycle_hook_test.go b/volcengine/autoscaling/scaling_lifecycle_hook/resource_volcengine_scaling_lifecycle_hook_test.go new file mode 100644 index 00000000..ecf75592 --- /dev/null +++ b/volcengine/autoscaling/scaling_lifecycle_hook/resource_volcengine_scaling_lifecycle_hook_test.go @@ -0,0 +1,158 @@ +package scaling_lifecycle_hook_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/autoscaling/scaling_lifecycle_hook" + "testing" +) + +const testAccVolcengineScalingLifecycleHookCreateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +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 + instance_terminate_policy = "OldestInstance" + 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}" +} +` + +const testAccVolcengineScalingLifecycleHookUpdateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +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 + instance_terminate_policy = "OldestInstance" + default_cooldown = 10 +} + +resource "volcengine_scaling_lifecycle_hook" "foo" { + lifecycle_hook_name = "acc-test-lifecycle" + lifecycle_hook_policy = "CONTINUE" + lifecycle_hook_timeout = 300 + lifecycle_hook_type = "SCALE_OUT" + scaling_group_id = "${volcengine_scaling_group.foo.id}" +} +` + +func TestAccVolcengineScalingLifecycleHookResource_Basic(t *testing.T) { + resourceName := "volcengine_scaling_lifecycle_hook.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &scaling_lifecycle_hook.VolcengineScalingLifecycleHookService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineScalingLifecycleHookCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "lifecycle_hook_name", "acc-test-lifecycle"), + resource.TestCheckResourceAttr(acc.ResourceId, "lifecycle_hook_policy", "CONTINUE"), + resource.TestCheckResourceAttr(acc.ResourceId, "lifecycle_hook_timeout", "30"), + resource.TestCheckResourceAttr(acc.ResourceId, "lifecycle_hook_type", "SCALE_IN"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccVolcengineScalingLifecycleHookResource_Update(t *testing.T) { + resourceName := "volcengine_scaling_lifecycle_hook.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &scaling_lifecycle_hook.VolcengineScalingLifecycleHookService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineScalingLifecycleHookCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "lifecycle_hook_name", "acc-test-lifecycle"), + resource.TestCheckResourceAttr(acc.ResourceId, "lifecycle_hook_policy", "CONTINUE"), + resource.TestCheckResourceAttr(acc.ResourceId, "lifecycle_hook_timeout", "30"), + resource.TestCheckResourceAttr(acc.ResourceId, "lifecycle_hook_type", "SCALE_IN"), + ), + }, + { + Config: testAccVolcengineScalingLifecycleHookUpdateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "lifecycle_hook_name", "acc-test-lifecycle"), + resource.TestCheckResourceAttr(acc.ResourceId, "lifecycle_hook_policy", "CONTINUE"), + resource.TestCheckResourceAttr(acc.ResourceId, "lifecycle_hook_timeout", "300"), + resource.TestCheckResourceAttr(acc.ResourceId, "lifecycle_hook_type", "SCALE_OUT"), + ), + }, + { + Config: testAccVolcengineScalingLifecycleHookUpdateConfig, + PlanOnly: true, + ExpectNonEmptyPlan: false, // 修改之后,不应该再产生diff + }, + }, + }) +} diff --git a/volcengine/autoscaling/scaling_policy/data_source_volcengine_scaling_policies_test.go b/volcengine/autoscaling/scaling_policy/data_source_volcengine_scaling_policies_test.go new file mode 100644 index 00000000..0f25dd46 --- /dev/null +++ b/volcengine/autoscaling/scaling_policy/data_source_volcengine_scaling_policies_test.go @@ -0,0 +1,82 @@ +package scaling_policy_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/autoscaling/scaling_policy" + "testing" +) + +const testAccVolcengineScalingPoliciesDatasourceConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + 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 +} + +resource "volcengine_scaling_policy" "foo" { + count = 3 + active = false + scaling_group_id = "${volcengine_scaling_group.foo.id}" + scaling_policy_name = "acc-tf-sg-policy-test-${count.index}" + scaling_policy_type = "Alarm" + adjustment_type = "QuantityChangeInCapacity" + adjustment_value = 100 + cooldown = 10 + alarm_policy_rule_type = "Static" + alarm_policy_evaluation_count = 1 + alarm_policy_condition_metric_name = "Instance_CpuBusy_Avg" + alarm_policy_condition_metric_unit = "Percent" + alarm_policy_condition_comparison_operator = "=" + alarm_policy_condition_threshold = 100 +} + +data "volcengine_scaling_policies" "foo"{ + scaling_group_id = "${volcengine_scaling_group.foo.id}" + ids = volcengine_scaling_policy.foo[*].scaling_policy_id +} +` + +func TestAccVolcengineScalingPoliciesDatasource_Basic(t *testing.T) { + resourceName := "data.volcengine_scaling_policies.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &scaling_policy.VolcengineScalingPolicyService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineScalingPoliciesDatasourceConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(acc.ResourceId, "scaling_policies.#", "3"), + ), + }, + }, + }) +} diff --git a/volcengine/autoscaling/scaling_policy/resource_volcengine_scaling_policy.go b/volcengine/autoscaling/scaling_policy/resource_volcengine_scaling_policy.go index a11261cb..e1ac5175 100644 --- a/volcengine/autoscaling/scaling_policy/resource_volcengine_scaling_policy.go +++ b/volcengine/autoscaling/scaling_policy/resource_volcengine_scaling_policy.go @@ -45,6 +45,11 @@ func ResourceVolcengineScalingPolicy() *schema.Resource { ForceNew: true, Description: "The id of the scaling group to which the scaling policy belongs.", }, + "scaling_policy_id": { + Type: schema.TypeString, + Computed: true, + Description: "The id of the scaling policy.", + }, "scaling_policy_name": { Type: schema.TypeString, Required: true, diff --git a/volcengine/autoscaling/scaling_policy/resource_volcengine_scaling_policy_test.go b/volcengine/autoscaling/scaling_policy/resource_volcengine_scaling_policy_test.go new file mode 100644 index 00000000..3a639b8b --- /dev/null +++ b/volcengine/autoscaling/scaling_policy/resource_volcengine_scaling_policy_test.go @@ -0,0 +1,201 @@ +package scaling_policy_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/autoscaling/scaling_policy" + "testing" +) + +const testAccVolcengineScalingPolicyCreateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + 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 +} + +resource "volcengine_scaling_policy" "foo" { + active = false + scaling_group_id = "${volcengine_scaling_group.foo.id}" + scaling_policy_name = "acc-tf-sg-policy-test" + scaling_policy_type = "Alarm" + adjustment_type = "QuantityChangeInCapacity" + adjustment_value = 100 + cooldown = 10 + alarm_policy_rule_type = "Static" + alarm_policy_evaluation_count = 1 + alarm_policy_condition_metric_name = "Instance_CpuBusy_Avg" + alarm_policy_condition_metric_unit = "Percent" + alarm_policy_condition_comparison_operator = "=" + alarm_policy_condition_threshold = 100 +} +` + +const testAccVolcengineScalingPolicyUpdateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + 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 +} + +resource "volcengine_scaling_policy" "foo" { + active = false + scaling_group_id = "${volcengine_scaling_group.foo.id}" + scaling_policy_name = "acc-tf-sg-policy-test-new" + scaling_policy_type = "Alarm" + adjustment_type = "QuantityChangeInCapacity" + adjustment_value = 10 + cooldown = 30 + alarm_policy_rule_type = "Static" + alarm_policy_evaluation_count = 1 + alarm_policy_condition_metric_name = "Instance_CpuBusy_Avg" + alarm_policy_condition_metric_unit = "Percent" + alarm_policy_condition_comparison_operator = "=" + alarm_policy_condition_threshold = 100 +} +` + +func TestAccVolcengineScalingPolicyResource_Basic(t *testing.T) { + resourceName := "volcengine_scaling_policy.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &scaling_policy.VolcengineScalingPolicyService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineScalingPolicyCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "active", "false"), + resource.TestCheckResourceAttr(acc.ResourceId, "adjustment_type", "QuantityChangeInCapacity"), + resource.TestCheckResourceAttr(acc.ResourceId, "adjustment_value", "100"), + resource.TestCheckResourceAttr(acc.ResourceId, "alarm_policy_condition_comparison_operator", "="), + resource.TestCheckResourceAttr(acc.ResourceId, "alarm_policy_condition_metric_name", "Instance_CpuBusy_Avg"), + resource.TestCheckResourceAttr(acc.ResourceId, "alarm_policy_condition_metric_unit", "Percent"), + resource.TestCheckResourceAttr(acc.ResourceId, "alarm_policy_condition_threshold", "100"), + resource.TestCheckResourceAttr(acc.ResourceId, "alarm_policy_evaluation_count", "1"), + resource.TestCheckResourceAttr(acc.ResourceId, "alarm_policy_rule_type", "Static"), + resource.TestCheckResourceAttr(acc.ResourceId, "cooldown", "10"), + resource.TestCheckResourceAttr(acc.ResourceId, "scaling_policy_name", "acc-tf-sg-policy-test"), + resource.TestCheckResourceAttr(acc.ResourceId, "scaling_policy_type", "Alarm"), + resource.TestCheckResourceAttr(acc.ResourceId, "status", "InActive"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccVolcengineScalingPolicyResource_Update(t *testing.T) { + resourceName := "volcengine_scaling_policy.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &scaling_policy.VolcengineScalingPolicyService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineScalingPolicyCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "active", "false"), + resource.TestCheckResourceAttr(acc.ResourceId, "adjustment_type", "QuantityChangeInCapacity"), + resource.TestCheckResourceAttr(acc.ResourceId, "adjustment_value", "100"), + resource.TestCheckResourceAttr(acc.ResourceId, "alarm_policy_condition_comparison_operator", "="), + resource.TestCheckResourceAttr(acc.ResourceId, "alarm_policy_condition_metric_name", "Instance_CpuBusy_Avg"), + resource.TestCheckResourceAttr(acc.ResourceId, "alarm_policy_condition_metric_unit", "Percent"), + resource.TestCheckResourceAttr(acc.ResourceId, "alarm_policy_condition_threshold", "100"), + resource.TestCheckResourceAttr(acc.ResourceId, "alarm_policy_evaluation_count", "1"), + resource.TestCheckResourceAttr(acc.ResourceId, "alarm_policy_rule_type", "Static"), + resource.TestCheckResourceAttr(acc.ResourceId, "cooldown", "10"), + resource.TestCheckResourceAttr(acc.ResourceId, "scaling_policy_name", "acc-tf-sg-policy-test"), + resource.TestCheckResourceAttr(acc.ResourceId, "scaling_policy_type", "Alarm"), + resource.TestCheckResourceAttr(acc.ResourceId, "status", "InActive"), + ), + }, + { + Config: testAccVolcengineScalingPolicyUpdateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "active", "false"), + resource.TestCheckResourceAttr(acc.ResourceId, "adjustment_type", "QuantityChangeInCapacity"), + resource.TestCheckResourceAttr(acc.ResourceId, "adjustment_value", "10"), + resource.TestCheckResourceAttr(acc.ResourceId, "alarm_policy_condition_comparison_operator", "="), + resource.TestCheckResourceAttr(acc.ResourceId, "alarm_policy_condition_metric_name", "Instance_CpuBusy_Avg"), + resource.TestCheckResourceAttr(acc.ResourceId, "alarm_policy_condition_metric_unit", "Percent"), + resource.TestCheckResourceAttr(acc.ResourceId, "alarm_policy_condition_threshold", "100"), + resource.TestCheckResourceAttr(acc.ResourceId, "alarm_policy_evaluation_count", "1"), + resource.TestCheckResourceAttr(acc.ResourceId, "alarm_policy_rule_type", "Static"), + resource.TestCheckResourceAttr(acc.ResourceId, "cooldown", "30"), + resource.TestCheckResourceAttr(acc.ResourceId, "scaling_policy_name", "acc-tf-sg-policy-test-new"), + resource.TestCheckResourceAttr(acc.ResourceId, "scaling_policy_type", "Alarm"), + resource.TestCheckResourceAttr(acc.ResourceId, "status", "InActive"), + ), + }, + { + Config: testAccVolcengineScalingPolicyUpdateConfig, + PlanOnly: true, + ExpectNonEmptyPlan: false, // 修改之后,不应该再产生diff + }, + }, + }) +} diff --git a/volcengine/autoscaling/scaling_policy/service_volcengine_scaling_policy.go b/volcengine/autoscaling/scaling_policy/service_volcengine_scaling_policy.go index ab2cfb08..8ea998c3 100644 --- a/volcengine/autoscaling/scaling_policy/service_volcengine_scaling_policy.go +++ b/volcengine/autoscaling/scaling_policy/service_volcengine_scaling_policy.go @@ -127,7 +127,41 @@ func (s *VolcengineScalingPolicyService) RefreshResourceState(resourceData *sche func (VolcengineScalingPolicyService) WithResourceResponseHandlers(scalingPolicy map[string]interface{}) []ve.ResourceResponseHandler { handler := func() (map[string]interface{}, map[string]ve.ResponseConvert, error) { scalingPolicy["active"] = scalingPolicy["Status"].(string) == "Active" - return scalingPolicy, nil, nil + return scalingPolicy, map[string]ve.ResponseConvert{ + "ScheduledPolicy.LaunchTime": { + TargetField: "scheduled_policy_launch_time", + }, + "ScheduledPolicy.RecurrenceStartTime": { + TargetField: "scheduled_policy_recurrence_start_time", + }, + "ScheduledPolicy.RecurrenceEndTime": { + TargetField: "scheduled_policy_recurrence_end_time", + }, + "ScheduledPolicy.RecurrenceType": { + TargetField: "scheduled_policy_recurrence_type", + }, + "ScheduledPolicy.RecurrenceValue": { + TargetField: "scheduled_policy_recurrence_value", + }, + "AlarmPolicy.RuleType": { + TargetField: "alarm_policy_rule_type", + }, + "AlarmPolicy.EvaluationCount": { + TargetField: "alarm_policy_evaluation_count", + }, + "AlarmPolicy.Condition.MetricName": { + TargetField: "alarm_policy_condition_metric_name", + }, + "AlarmPolicy.Condition.MetricUnit": { + TargetField: "alarm_policy_condition_metric_unit", + }, + "AlarmPolicy.Condition.ComparisonOperator": { + TargetField: "alarm_policy_condition_comparison_operator", + }, + "AlarmPolicy.Condition.Threshold": { + TargetField: "alarm_policy_condition_threshold", + }, + }, nil } return []ve.ResourceResponseHandler{handler} @@ -188,6 +222,7 @@ func (s *VolcengineScalingPolicyService) CreateResource(resourceData *schema.Res //注意 获取内容 这个地方不能是指针 需要转一次 id, _ := ve.ObtainSdkValue("Result.ScalingPolicyId", *resp) d.SetId(fmt.Sprintf("%v:%v", d.Get("scaling_group_id"), id)) + d.Set("scaling_policy_id", id) return nil }, Refresh: &ve.StateRefresh{ @@ -425,7 +460,7 @@ func (s *VolcengineScalingPolicyService) DatasourceResources(*schema.ResourceDat } func (s *VolcengineScalingPolicyService) ReadResourceId(id string) string { - return strings.Split(id, ":")[1] + return id } func (s *VolcengineScalingPolicyService) enableOrDisablePolicyCallback(resourceData *schema.ResourceData) ve.Callback { diff --git a/volcengine/ebs/volume/data_source_volcengine_volumes_test.go b/volcengine/ebs/volume/data_source_volcengine_volumes_test.go new file mode 100644 index 00000000..2ec3d460 --- /dev/null +++ b/volcengine/ebs/volume/data_source_volcengine_volumes_test.go @@ -0,0 +1,53 @@ +package volume_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/ebs/volume" + "testing" +) + +const testAccVolcengineVolumesDatasourceConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_volume" "foo" { + volume_name = "acc-test-volume-${count.index}" + volume_type = "ESSD_PL0" + description = "acc-test" + kind = "data" + size = 60 + zone_id = "${data.volcengine_zones.foo.zones[0].id}" + volume_charge_type = "PostPaid" + project_name = "default" + count = 3 +} + +data "volcengine_volumes" "foo"{ + ids = volcengine_volume.foo[*].id +} +` + +func TestAccVolcengineVolumesDatasource_Basic(t *testing.T) { + resourceName := "data.volcengine_volumes.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &volume.VolcengineVolumeService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineVolumesDatasourceConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(acc.ResourceId, "volumes.#", "3"), + ), + }, + }, + }) +} diff --git a/volcengine/ebs/volume/resource_volcengine_volume.go b/volcengine/ebs/volume/resource_volcengine_volume.go index 5bcbcf69..984ce72a 100644 --- a/volcengine/ebs/volume/resource_volcengine_volume.go +++ b/volcengine/ebs/volume/resource_volcengine_volume.go @@ -75,7 +75,8 @@ func ResourceVolcengineVolume() *schema.Resource { Computed: true, ForceNew: true, Description: "The ID of the instance to which the created volume is automatically attached. " + - "Please note this field needs to ask the system administrator to apply for a whitelist.", + "Please note this field needs to ask the system administrator to apply for a whitelist.\n" + + "When use this field to attach ecs instance, the attached volume cannot be deleted by terraform, please use `terraform state rm volcengine_volume.resource_name` command to remove it from terraform state file and management.", }, "volume_charge_type": { Type: schema.TypeString, diff --git a/volcengine/ebs/volume/resource_volcengine_volume_test.go b/volcengine/ebs/volume/resource_volcengine_volume_test.go new file mode 100644 index 00000000..c71cb164 --- /dev/null +++ b/volcengine/ebs/volume/resource_volcengine_volume_test.go @@ -0,0 +1,224 @@ +package volume_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/ebs/volume" + "testing" +) + +const testAccVolcengineVolumeCreateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_volume" "foo" { + volume_name = "acc-test-volume" + volume_type = "ESSD_PL0" + description = "acc-test" + kind = "data" + size = 40 + zone_id = "${data.volcengine_zones.foo.zones[0].id}" + volume_charge_type = "PostPaid" + project_name = "default" +} +` + +func TestAccVolcengineVolumeResource_Basic(t *testing.T) { + resourceName := "volcengine_volume.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &volume.VolcengineVolumeService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineVolumeCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "volume_name", "acc-test-volume"), + resource.TestCheckResourceAttr(acc.ResourceId, "volume_type", "ESSD_PL0"), + resource.TestCheckResourceAttr(acc.ResourceId, "delete_with_instance", "false"), + resource.TestCheckResourceAttr(acc.ResourceId, "description", "acc-test"), + resource.TestCheckResourceAttr(acc.ResourceId, "kind", "data"), + resource.TestCheckResourceAttr(acc.ResourceId, "project_name", "default"), + resource.TestCheckResourceAttr(acc.ResourceId, "size", "40"), + resource.TestCheckResourceAttr(acc.ResourceId, "status", "available"), + resource.TestCheckResourceAttr(acc.ResourceId, "volume_charge_type", "PostPaid"), + resource.TestCheckResourceAttr(acc.ResourceId, "instance_id", ""), + resource.TestCheckResourceAttrSet(acc.ResourceId, "zone_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "created_at"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "trade_status"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccVolcengineVolumeUpdateBasicAttributeConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_volume" "foo" { + volume_name = "acc-test-volume-new" + volume_type = "ESSD_PL0" + description = "acc-test-new" + kind = "data" + size = 40 + zone_id = "${data.volcengine_zones.foo.zones[0].id}" + volume_charge_type = "PostPaid" + project_name = "default" + delete_with_instance = true +} +` + +func TestAccVolcengineVolumeResource_UpdateBasicAttribute(t *testing.T) { + resourceName := "volcengine_volume.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &volume.VolcengineVolumeService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineVolumeCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "volume_name", "acc-test-volume"), + resource.TestCheckResourceAttr(acc.ResourceId, "volume_type", "ESSD_PL0"), + resource.TestCheckResourceAttr(acc.ResourceId, "delete_with_instance", "false"), + resource.TestCheckResourceAttr(acc.ResourceId, "description", "acc-test"), + resource.TestCheckResourceAttr(acc.ResourceId, "kind", "data"), + resource.TestCheckResourceAttr(acc.ResourceId, "project_name", "default"), + resource.TestCheckResourceAttr(acc.ResourceId, "size", "40"), + resource.TestCheckResourceAttr(acc.ResourceId, "status", "available"), + resource.TestCheckResourceAttr(acc.ResourceId, "volume_charge_type", "PostPaid"), + resource.TestCheckResourceAttr(acc.ResourceId, "instance_id", ""), + resource.TestCheckResourceAttrSet(acc.ResourceId, "zone_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "created_at"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "trade_status"), + ), + }, + { + Config: testAccVolcengineVolumeUpdateBasicAttributeConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "volume_name", "acc-test-volume-new"), + resource.TestCheckResourceAttr(acc.ResourceId, "volume_type", "ESSD_PL0"), + resource.TestCheckResourceAttr(acc.ResourceId, "delete_with_instance", "true"), + resource.TestCheckResourceAttr(acc.ResourceId, "description", "acc-test-new"), + resource.TestCheckResourceAttr(acc.ResourceId, "kind", "data"), + resource.TestCheckResourceAttr(acc.ResourceId, "project_name", "default"), + resource.TestCheckResourceAttr(acc.ResourceId, "size", "40"), + resource.TestCheckResourceAttr(acc.ResourceId, "status", "available"), + resource.TestCheckResourceAttr(acc.ResourceId, "volume_charge_type", "PostPaid"), + resource.TestCheckResourceAttr(acc.ResourceId, "instance_id", ""), + resource.TestCheckResourceAttrSet(acc.ResourceId, "zone_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "created_at"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "trade_status"), + ), + }, + { + Config: testAccVolcengineVolumeUpdateBasicAttributeConfig, + PlanOnly: true, + ExpectNonEmptyPlan: false, // 修改之后,不应该再产生diff + }, + }, + }) +} + +const testAccVolcengineVolumeUpdateVolumeSizeConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_volume" "foo" { + volume_name = "acc-test-volume" + volume_type = "ESSD_PL0" + description = "acc-test" + kind = "data" + size = 60 + zone_id = "${data.volcengine_zones.foo.zones[0].id}" + volume_charge_type = "PostPaid" + project_name = "default" +} +` + +func TestAccVolcengineVolumeResource_UpdateVolumeSize(t *testing.T) { + resourceName := "volcengine_volume.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &volume.VolcengineVolumeService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineVolumeCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "volume_name", "acc-test-volume"), + resource.TestCheckResourceAttr(acc.ResourceId, "volume_type", "ESSD_PL0"), + resource.TestCheckResourceAttr(acc.ResourceId, "delete_with_instance", "false"), + resource.TestCheckResourceAttr(acc.ResourceId, "description", "acc-test"), + resource.TestCheckResourceAttr(acc.ResourceId, "kind", "data"), + resource.TestCheckResourceAttr(acc.ResourceId, "project_name", "default"), + resource.TestCheckResourceAttr(acc.ResourceId, "size", "40"), + resource.TestCheckResourceAttr(acc.ResourceId, "status", "available"), + resource.TestCheckResourceAttr(acc.ResourceId, "volume_charge_type", "PostPaid"), + resource.TestCheckResourceAttr(acc.ResourceId, "instance_id", ""), + resource.TestCheckResourceAttrSet(acc.ResourceId, "zone_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "created_at"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "trade_status"), + ), + }, + { + Config: testAccVolcengineVolumeUpdateVolumeSizeConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "volume_name", "acc-test-volume"), + resource.TestCheckResourceAttr(acc.ResourceId, "volume_type", "ESSD_PL0"), + resource.TestCheckResourceAttr(acc.ResourceId, "delete_with_instance", "false"), + resource.TestCheckResourceAttr(acc.ResourceId, "description", "acc-test"), + resource.TestCheckResourceAttr(acc.ResourceId, "kind", "data"), + resource.TestCheckResourceAttr(acc.ResourceId, "project_name", "default"), + resource.TestCheckResourceAttr(acc.ResourceId, "size", "60"), + resource.TestCheckResourceAttr(acc.ResourceId, "status", "available"), + resource.TestCheckResourceAttr(acc.ResourceId, "volume_charge_type", "PostPaid"), + resource.TestCheckResourceAttr(acc.ResourceId, "instance_id", ""), + resource.TestCheckResourceAttrSet(acc.ResourceId, "zone_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "created_at"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "trade_status"), + ), + }, + { + Config: testAccVolcengineVolumeUpdateVolumeSizeConfig, + PlanOnly: true, + ExpectNonEmptyPlan: false, // 修改之后,不应该再产生diff + }, + }, + }) +} diff --git a/volcengine/ebs/volume/service_volcengine_volume.go b/volcengine/ebs/volume/service_volcengine_volume.go index d33ac45c..f4fca481 100644 --- a/volcengine/ebs/volume/service_volcengine_volume.go +++ b/volcengine/ebs/volume/service_volcengine_volume.go @@ -85,6 +85,17 @@ func (s *VolcengineVolumeService) ReadResource(resourceData *schema.ResourceData if len(data) == 0 { return data, fmt.Errorf("volume %s not exist ", volumeId) } + + payType, ok := data["PayType"] + if !ok { + return data, fmt.Errorf(" PayType of volume is not exist ") + } + if payType.(string) == "post" { + data["VolumeChargeType"] = "PostPaid" + } else if payType.(string) == "pre" { + data["VolumeChargeType"] = "PrePaid" + } + return data, err } @@ -172,7 +183,19 @@ func (s *VolcengineVolumeService) ModifyResource(resourceData *schema.ResourceDa callbacks = append(callbacks, ve.Callback{ Call: ve.SdkCall{ Action: "ModifyVolumeAttribute", - ConvertMode: ve.RequestConvertAll, + ConvertMode: ve.RequestConvertInConvert, + Convert: map[string]ve.RequestConvert{ + "volume_name": { + TargetField: "VolumeName", + ForceGet: true, + }, + "description": { + TargetField: "Description", + }, + "delete_with_instance": { + TargetField: "DeleteWithInstance", + }, + }, BeforeCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (bool, error) { (*call.SdkParam)["VolumeId"] = d.Id() return true, nil @@ -225,16 +248,6 @@ func (s *VolcengineVolumeService) ModifyResource(resourceData *schema.ResourceDa return false, errors.New("instance id cannot be empty") } - // get volume current info - data, err := s.ReadResource(resourceData, d.Id()) - if err != nil { - return false, err - } - // PayType can be Pre or Post - if strings.Contains(resourceData.Get("volume_charge_type").(string), data["PayType"].(string)) { - return false, nil // 不再进行下去了 - } - (*call.SdkParam)["VolumeIds.1"] = d.Id() (*call.SdkParam)["DiskChargeType"] = "PrePaid" (*call.SdkParam)["AutoPay"] = true @@ -263,7 +276,7 @@ func (s *VolcengineVolumeService) ModifyResource(resourceData *schema.ResourceDa return re.NonRetryableError(fmt.Errorf("error on reading volume %q: %w", d.Id(), callErr)) } // 计费方式已经转变成功 - if data["PayType"] == "Pre" { + if data["PayType"] == "pre" { return nil } // 计费方式还没有转换成功,尝试重新转换 @@ -292,11 +305,32 @@ func (s *VolcengineVolumeService) RemoveResource(resourceData *schema.ResourceDa SdkParam: &map[string]interface{}{ "VolumeId": resourceData.Id(), }, + BeforeCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (bool, error) { + volume, err := s.ReadResource(d, d.Id()) + if err != nil { + return false, err + } + status, err := ve.ObtainSdkValue("Status", volume) + if err != nil { + return false, err + } + if status != "available" { + return false, fmt.Errorf(" Only volume with a status of `available` can be deleted. ") + } + return true, nil + }, ExecuteCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (*map[string]interface{}, error) { logger.Debug(logger.RespFormat, call.Action, call.SdkParam) return s.Client.EbsClient.DeleteVolumeCommon(call.SdkParam) }, CallError: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall, baseErr error) error { + // 不能删除已挂载云盘 + if strings.Contains(baseErr.Error(), "Only volume with a status of `available` can be deleted.") { + msg := fmt.Sprintf("error: %s\n msg: %s", + baseErr.Error(), + "For volume with a status of `attached`, please use `terraform state rm volcengine_volume.resource_name` command to remove it from terraform state file and management.") + return fmt.Errorf(msg) + } return resource.Retry(15*time.Minute, func() *resource.RetryError { _, callErr := s.ReadResource(d, "") if callErr != nil { diff --git a/volcengine/ebs/volume_attach/resource_volcengine_volume_attach.go b/volcengine/ebs/volume_attach/resource_volcengine_volume_attach.go index 45659392..4c41795f 100644 --- a/volcengine/ebs/volume_attach/resource_volcengine_volume_attach.go +++ b/volcengine/ebs/volume_attach/resource_volcengine_volume_attach.go @@ -45,10 +45,11 @@ func ResourceVolcengineVolumeAttach() *schema.Resource { Description: "The Id of Instance.", }, "delete_with_instance": { - Type: schema.TypeBool, - Optional: true, - Computed: true, - Description: "Delete Volume with Attached Instance.", + Type: schema.TypeBool, + Optional: true, + Computed: true, + Description: "Delete Volume with Attached Instance." + + "It is not recommended to use this field. If used, please ensure that the value of this field is consistent with the value of `delete_with_instance` in volcengine_volume.", }, "status": { Type: schema.TypeString, diff --git a/volcengine/ebs/volume_attach/resource_volcengine_volume_attach_test.go b/volcengine/ebs/volume_attach/resource_volcengine_volume_attach_test.go new file mode 100644 index 00000000..fdad279c --- /dev/null +++ b/volcengine/ebs/volume_attach/resource_volcengine_volume_attach_test.go @@ -0,0 +1,211 @@ +package volume_attach_test + +import ( + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/ebs/volume_attach" +) + +const testAccVolcengineVolumeAttachCreateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = "${volcengine_vpc.foo.id}" +} + +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_ecs_instance" "foo" { + instance_name = "acc-test-ecs" + description = "acc-test" + host_name = "tf-acc-test" + image_id = "${data.volcengine_images.foo.images[0].image_id}" + instance_type = "ecs.g1.large" + password = "93f0cb0614Aab12" + instance_charge_type = "PostPaid" + system_volume_type = "ESSD_PL0" + system_volume_size = 40 + subnet_id = "${volcengine_subnet.foo.id}" + security_group_ids = ["${volcengine_security_group.foo.id}"] + project_name = "default" + tags { + key = "k1" + value = "v1" + } +} + +resource "volcengine_volume" "foo" { + volume_name = "acc-test-volume" + volume_type = "ESSD_PL0" + description = "acc-test" + kind = "data" + size = 40 + zone_id = "${data.volcengine_zones.foo.zones[0].id}" + volume_charge_type = "PostPaid" + project_name = "default" +} + +resource "volcengine_volume_attach" "foo" { + instance_id = "${volcengine_ecs_instance.foo.id}" + volume_id = "${volcengine_volume.foo.id}" +} +` + +func TestAccVolcengineVolumeAttachResource_Basic(t *testing.T) { + resourceName := "volcengine_volume_attach.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &volume_attach.VolcengineVolumeAttachService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineVolumeAttachCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "status", "attached"), + resource.TestCheckResourceAttr(acc.ResourceId, "delete_with_instance", "false"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "instance_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "volume_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "created_at"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "updated_at"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccVolcengineVolumeAttachDeleteWithInstanceConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = "${volcengine_vpc.foo.id}" +} + +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_ecs_instance" "foo" { + instance_name = "acc-test-ecs" + description = "acc-test" + host_name = "tf-acc-test" + image_id = "${data.volcengine_images.foo.images[0].image_id}" + instance_type = "ecs.g1.large" + password = "93f0cb0614Aab12" + instance_charge_type = "PostPaid" + system_volume_type = "ESSD_PL0" + system_volume_size = 40 + subnet_id = "${volcengine_subnet.foo.id}" + security_group_ids = ["${volcengine_security_group.foo.id}"] + project_name = "default" + tags { + key = "k1" + value = "v1" + } +} + +resource "volcengine_volume" "foo" { + volume_name = "acc-test-volume" + volume_type = "ESSD_PL0" + description = "acc-test" + kind = "data" + size = 40 + zone_id = "${data.volcengine_zones.foo.zones[0].id}" + volume_charge_type = "PostPaid" + project_name = "default" + delete_with_instance = true +} + +resource "volcengine_volume_attach" "foo" { + instance_id = "${volcengine_ecs_instance.foo.id}" + volume_id = "${volcengine_volume.foo.id}" + delete_with_instance = true +} +` + +func TestAccVolcengineVolumeAttachResource_DeleteWithInstance(t *testing.T) { + resourceName := "volcengine_volume_attach.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &volume_attach.VolcengineVolumeAttachService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineVolumeAttachDeleteWithInstanceConfig, + ExpectError: regexp.MustCompile("^After applying this step, the plan was not empty(.|\n)*UPDATE: volcengine_volume\\.foo(.|\n)*delete_with_instance: \"false\" => \"true\""), + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "status", "attached"), + resource.TestCheckResourceAttr(acc.ResourceId, "delete_with_instance", "true"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "instance_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "volume_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "created_at"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "updated_at"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/volcengine/ebs/volume_attach/service_volcengine_volume_attach.go b/volcengine/ebs/volume_attach/service_volcengine_volume_attach.go index 0e118461..034f5ecb 100644 --- a/volcengine/ebs/volume_attach/service_volcengine_volume_attach.go +++ b/volcengine/ebs/volume_attach/service_volcengine_volume_attach.go @@ -10,15 +10,18 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ve "github.com/volcengine/terraform-provider-volcengine/common" "github.com/volcengine/terraform-provider-volcengine/logger" + "github.com/volcengine/terraform-provider-volcengine/volcengine/ebs/volume" ) type VolcengineVolumeAttachService struct { - Client *ve.SdkClient + Client *ve.SdkClient + volumeService *volume.VolcengineVolumeService } func NewVolumeAttachService(c *ve.SdkClient) *VolcengineVolumeAttachService { return &VolcengineVolumeAttachService{ - Client: c, + Client: c, + volumeService: volume.NewVolumeService(c), } } @@ -140,6 +143,24 @@ func (s *VolcengineVolumeAttachService) CreateResource(resourceData *schema.Reso Call: ve.SdkCall{ Action: "AttachVolume", ConvertMode: ve.RequestConvertAll, + BeforeCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (bool, error) { + _, exist := d.GetOkExists("delete_with_instance") + if exist { + return true, nil + } else { + volumeId := resourceData.Get("volume_id") + volume, err := s.volumeService.ReadResource(resourceData, volumeId.(string)) + if err != nil { + return false, err + } + deleteWithInstance, ok := volume["DeleteWithInstance"] + if !ok { + return false, fmt.Errorf(" DeleteWithInstance is not exist in volume ") + } + (*call.SdkParam)["DeleteWithInstance"] = deleteWithInstance + return true, nil + } + }, ExecuteCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (*map[string]interface{}, error) { logger.Debug(logger.RespFormat, call.Action, call.SdkParam) return s.Client.EbsClient.AttachVolumeCommon(call.SdkParam) @@ -148,9 +169,12 @@ func (s *VolcengineVolumeAttachService) CreateResource(resourceData *schema.Reso d.SetId(fmt.Sprint((*call.SdkParam)["VolumeId"], ":", (*call.SdkParam)["InstanceId"])) return nil }, - Refresh: &ve.StateRefresh{ - Target: []string{"attached"}, - Timeout: resourceData.Timeout(schema.TimeoutCreate), + ExtraRefresh: map[ve.ResourceService]*ve.StateRefresh{ + volume.NewVolumeService(s.Client): { + Target: []string{"attached"}, + Timeout: resourceData.Timeout(schema.TimeoutCreate), + ResourceId: resourceData.Get("volume_id").(string), + }, }, }, } @@ -188,9 +212,12 @@ func (s *VolcengineVolumeAttachService) RemoveResource(resourceData *schema.Reso return resource.RetryableError(callErr) }) }, - Refresh: &ve.StateRefresh{ - Target: []string{"available"}, - Timeout: resourceData.Timeout(schema.TimeoutDelete), + ExtraRefresh: map[ve.ResourceService]*ve.StateRefresh{ + volume.NewVolumeService(s.Client): { + Target: []string{"available"}, + Timeout: resourceData.Timeout(schema.TimeoutDelete), + ResourceId: resourceData.Get("volume_id").(string), + }, }, }, } diff --git a/volcengine/ecs/ecs_deployment_set/service_volcengine_ecs_deployment_set.go b/volcengine/ecs/ecs_deployment_set/service_volcengine_ecs_deployment_set.go index 66577872..be1dfab4 100644 --- a/volcengine/ecs/ecs_deployment_set/service_volcengine_ecs_deployment_set.go +++ b/volcengine/ecs/ecs_deployment_set/service_volcengine_ecs_deployment_set.go @@ -3,6 +3,7 @@ package ecs_deployment_set import ( "errors" "fmt" + "strings" "time" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -190,6 +191,10 @@ func (s *VolcengineEcsDeploymentSetService) RemoveResource(resourceData *schema. if callErr == nil { return nil } + if strings.Contains(callErr.Error(), "InvalidDeploymentSet.InUse") { + return resource.NonRetryableError(fmt.Errorf("there are instances in the deployment set, " + + "please remove the instances in the deployment set before deleting the deployment set")) + } return resource.RetryableError(callErr) }) }, diff --git a/volcengine/ecs/ecs_instance/service_volcengine_ecs_instance.go b/volcengine/ecs/ecs_instance/service_volcengine_ecs_instance.go index 9398fa6b..3e113659 100644 --- a/volcengine/ecs/ecs_instance/service_volcengine_ecs_instance.go +++ b/volcengine/ecs/ecs_instance/service_volcengine_ecs_instance.go @@ -456,6 +456,12 @@ func (s *VolcengineEcsService) CreateResource(resourceData *schema.ResourceData, ConvertType: ve.ConvertListN, TargetField: "Volumes", StartIndex: 1, + NextLevelConvert: map[string]ve.RequestConvert{ + "delete_with_instance": { + TargetField: "DeleteWithInstance", + ForceGet: true, + }, + }, }, "cpu_options": { ConvertType: ve.ConvertListUnique, diff --git a/volcengine/nat/dnat_entry/data_source_volcengine_dnat_entries_test.go b/volcengine/nat/dnat_entry/data_source_volcengine_dnat_entries_test.go new file mode 100644 index 00000000..b282f006 --- /dev/null +++ b/volcengine/nat/dnat_entry/data_source_volcengine_dnat_entries_test.go @@ -0,0 +1,92 @@ +package dnat_entry_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/nat/dnat_entry" + "testing" +) + +const testAccVolcengineDnatEntriesDatasourceConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_nat_gateway" "foo" { + vpc_id = "${volcengine_vpc.foo.id}" + subnet_id = "${volcengine_subnet.foo.id}" + spec = "Small" + nat_gateway_name = "acc-test-ng" + description = "acc-test" + billing_type = "PostPaid" + project_name = "default" + tags { + key = "k1" + value = "v1" + } +} + +resource "volcengine_eip_address" "foo" { + name = "acc-test-eip" + description = "acc-test" + bandwidth = 1 + billing_type = "PostPaidByBandwidth" + isp = "BGP" +} + +resource "volcengine_eip_associate" "foo" { + allocation_id = "${volcengine_eip_address.foo.id}" + instance_id = "${volcengine_nat_gateway.foo.id}" + instance_type = "Nat" +} + +resource "volcengine_dnat_entry" "foo" { + dnat_entry_name = "acc-test-dnat-entry" + external_ip = "${volcengine_eip_address.foo.eip_address}" + external_port = 80 + internal_ip = "172.16.0.10" + internal_port = 80 + nat_gateway_id = "${volcengine_nat_gateway.foo.id}" + protocol = "tcp" + depends_on = [volcengine_eip_associate.foo] +} + +data "volcengine_dnat_entries" "foo"{ + ids = ["${volcengine_dnat_entry.foo.id}"] +} +` + +func TestAccVolcengineDnatEntriesDatasource_Basic(t *testing.T) { + resourceName := "data.volcengine_dnat_entries.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &dnat_entry.VolcengineDnatEntryService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineDnatEntriesDatasourceConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(acc.ResourceId, "dnat_entries.#", "1"), + ), + }, + }, + }) +} diff --git a/volcengine/nat/dnat_entry/resource_volcengine_dnat_entry_test.go b/volcengine/nat/dnat_entry/resource_volcengine_dnat_entry_test.go new file mode 100644 index 00000000..626942c8 --- /dev/null +++ b/volcengine/nat/dnat_entry/resource_volcengine_dnat_entry_test.go @@ -0,0 +1,224 @@ +package dnat_entry_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/nat/dnat_entry" + "testing" +) + +const testAccVolcengineDnatEntryCreateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_nat_gateway" "foo" { + vpc_id = "${volcengine_vpc.foo.id}" + subnet_id = "${volcengine_subnet.foo.id}" + spec = "Small" + nat_gateway_name = "acc-test-ng" + description = "acc-test" + billing_type = "PostPaid" + project_name = "default" + tags { + key = "k1" + value = "v1" + } +} + +resource "volcengine_eip_address" "foo" { + name = "acc-test-eip" + description = "acc-test" + bandwidth = 1 + billing_type = "PostPaidByBandwidth" + isp = "BGP" +} + +resource "volcengine_eip_associate" "foo" { + allocation_id = "${volcengine_eip_address.foo.id}" + instance_id = "${volcengine_nat_gateway.foo.id}" + instance_type = "Nat" +} + +resource "volcengine_dnat_entry" "foo" { + dnat_entry_name = "acc-test-dnat-entry" + external_ip = "${volcengine_eip_address.foo.eip_address}" + external_port = 80 + internal_ip = "172.16.0.10" + internal_port = 80 + nat_gateway_id = "${volcengine_nat_gateway.foo.id}" + protocol = "tcp" + depends_on = [volcengine_eip_associate.foo] +} +` + +func TestAccVolcengineDnatEntryResource_Basic(t *testing.T) { + resourceName := "volcengine_dnat_entry.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &dnat_entry.VolcengineDnatEntryService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineDnatEntryCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "dnat_entry_name", "acc-test-dnat-entry"), + resource.TestCheckResourceAttr(acc.ResourceId, "external_port", "80"), + resource.TestCheckResourceAttr(acc.ResourceId, "internal_ip", "172.16.0.10"), + resource.TestCheckResourceAttr(acc.ResourceId, "internal_port", "80"), + resource.TestCheckResourceAttr(acc.ResourceId, "protocol", "tcp"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "external_ip"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "nat_gateway_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "dnat_entry_id"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccVolcengineDnatEntryUpdateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_nat_gateway" "foo" { + vpc_id = "${volcengine_vpc.foo.id}" + subnet_id = "${volcengine_subnet.foo.id}" + spec = "Small" + nat_gateway_name = "acc-test-ng" + description = "acc-test" + billing_type = "PostPaid" + project_name = "default" + tags { + key = "k1" + value = "v1" + } +} + +resource "volcengine_eip_address" "foo" { + name = "acc-test-eip" + description = "acc-test" + bandwidth = 1 + billing_type = "PostPaidByBandwidth" + isp = "BGP" +} + +resource "volcengine_eip_associate" "foo" { + allocation_id = "${volcengine_eip_address.foo.id}" + instance_id = "${volcengine_nat_gateway.foo.id}" + instance_type = "Nat" +} + +resource "volcengine_eip_address" "foo1" { + name = "acc-test-eip" + description = "acc-test" + bandwidth = 1 + billing_type = "PostPaidByBandwidth" + isp = "BGP" +} + +resource "volcengine_eip_associate" "foo1" { + allocation_id = "${volcengine_eip_address.foo1.id}" + instance_id = "${volcengine_nat_gateway.foo.id}" + instance_type = "Nat" +} + +resource "volcengine_dnat_entry" "foo" { + dnat_entry_name = "acc-test-dnat-entry-new" + external_ip = "${volcengine_eip_address.foo1.eip_address}" + external_port = 90 + internal_ip = "172.16.0.17" + internal_port = 90 + nat_gateway_id = "${volcengine_nat_gateway.foo.id}" + protocol = "udp" + depends_on = [volcengine_eip_associate.foo1] +} +` + +func TestAccVolcengineDnatEntryResource_Update(t *testing.T) { + resourceName := "volcengine_dnat_entry.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &dnat_entry.VolcengineDnatEntryService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineDnatEntryCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "dnat_entry_name", "acc-test-dnat-entry"), + resource.TestCheckResourceAttr(acc.ResourceId, "external_port", "80"), + resource.TestCheckResourceAttr(acc.ResourceId, "internal_ip", "172.16.0.10"), + resource.TestCheckResourceAttr(acc.ResourceId, "internal_port", "80"), + resource.TestCheckResourceAttr(acc.ResourceId, "protocol", "tcp"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "external_ip"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "nat_gateway_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "dnat_entry_id"), + ), + }, + { + Config: testAccVolcengineDnatEntryUpdateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "dnat_entry_name", "acc-test-dnat-entry-new"), + resource.TestCheckResourceAttr(acc.ResourceId, "external_port", "90"), + resource.TestCheckResourceAttr(acc.ResourceId, "internal_ip", "172.16.0.17"), + resource.TestCheckResourceAttr(acc.ResourceId, "internal_port", "90"), + resource.TestCheckResourceAttr(acc.ResourceId, "protocol", "udp"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "external_ip"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "nat_gateway_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "dnat_entry_id"), + ), + }, + { + Config: testAccVolcengineDnatEntryUpdateConfig, + PlanOnly: true, + ExpectNonEmptyPlan: false, // 修改之后,不应该再产生diff + }, + }, + }) +} diff --git a/volcengine/nat/nat_gateway/data_source_volcengine_nat_gateways_test.go b/volcengine/nat/nat_gateway/data_source_volcengine_nat_gateways_test.go new file mode 100644 index 00000000..28c8585d --- /dev/null +++ b/volcengine/nat/nat_gateway/data_source_volcengine_nat_gateways_test.go @@ -0,0 +1,68 @@ +package nat_gateway_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/nat/nat_gateway" + "testing" +) + +const testAccVolcengineNatGatewaysDatasourceConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_nat_gateway" "foo" { + vpc_id = "${volcengine_vpc.foo.id}" + subnet_id = "${volcengine_subnet.foo.id}" + spec = "Small" + nat_gateway_name = "acc-test-ng-${count.index}" + description = "acc-test" + billing_type = "PostPaid" + project_name = "default" + tags { + key = "k1" + value = "v1" + } + count =3 +} + +data "volcengine_nat_gateways" "foo"{ + ids = volcengine_nat_gateway.foo[*].id +} +` + +func TestAccVolcengineNatGatewaysDatasource_Basic(t *testing.T) { + resourceName := "data.volcengine_nat_gateways.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &nat_gateway.VolcengineNatGatewayService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineNatGatewaysDatasourceConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(acc.ResourceId, "nat_gateways.#", "3"), + ), + }, + }, + }) +} diff --git a/volcengine/nat/nat_gateway/resource_volcengine_nat_gateway_test.go b/volcengine/nat/nat_gateway/resource_volcengine_nat_gateway_test.go new file mode 100644 index 00000000..890ef4c3 --- /dev/null +++ b/volcengine/nat/nat_gateway/resource_volcengine_nat_gateway_test.go @@ -0,0 +1,352 @@ +package nat_gateway_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/nat/nat_gateway" + "testing" +) + +const testAccVolcengineNatGatewayCreateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_nat_gateway" "foo" { + vpc_id = "${volcengine_vpc.foo.id}" + subnet_id = "${volcengine_subnet.foo.id}" + spec = "Small" + nat_gateway_name = "acc-test-ng" + description = "acc-test" + billing_type = "PostPaid" + project_name = "default" + tags { + key = "k1" + value = "v1" + } +} +` + +func TestAccVolcengineNatGatewayResource_Basic(t *testing.T) { + resourceName := "volcengine_nat_gateway.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &nat_gateway.VolcengineNatGatewayService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineNatGatewayCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "nat_gateway_name", "acc-test-ng"), + resource.TestCheckResourceAttr(acc.ResourceId, "description", "acc-test"), + resource.TestCheckResourceAttr(acc.ResourceId, "billing_type", "PostPaid"), + resource.TestCheckResourceAttr(acc.ResourceId, "project_name", "default"), + resource.TestCheckResourceAttr(acc.ResourceId, "spec", "Small"), + resource.TestCheckResourceAttr(acc.ResourceId, "tags.#", "1"), + volcengine.TestCheckTypeSetElemNestedAttrs(acc.ResourceId, "tags.*", map[string]string{ + "key": "k1", + "value": "v1", + }), + resource.TestCheckResourceAttrSet(acc.ResourceId, "subnet_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "vpc_id"), + resource.TestCheckNoResourceAttr(acc.ResourceId, "period"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccVolcengineNatGatewayCreatePrePaidConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_nat_gateway" "foo" { + vpc_id = "${volcengine_vpc.foo.id}" + subnet_id = "${volcengine_subnet.foo.id}" + spec = "Small" + nat_gateway_name = "acc-test-ng" + description = "acc-test" + billing_type = "PrePaid" + period = "2" + project_name = "default" + tags { + key = "k1" + value = "v1" + } +} +` + +func TestAccVolcengineNatGatewayResource_CreatePrePaid(t *testing.T) { + resourceName := "volcengine_nat_gateway.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &nat_gateway.VolcengineNatGatewayService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineNatGatewayCreatePrePaidConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "nat_gateway_name", "acc-test-ng"), + resource.TestCheckResourceAttr(acc.ResourceId, "description", "acc-test"), + resource.TestCheckResourceAttr(acc.ResourceId, "billing_type", "PrePaid"), + resource.TestCheckResourceAttr(acc.ResourceId, "project_name", "default"), + resource.TestCheckResourceAttr(acc.ResourceId, "spec", "Small"), + resource.TestCheckResourceAttr(acc.ResourceId, "tags.#", "1"), + volcengine.TestCheckTypeSetElemNestedAttrs(acc.ResourceId, "tags.*", map[string]string{ + "key": "k1", + "value": "v1", + }), + resource.TestCheckResourceAttrSet(acc.ResourceId, "subnet_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "vpc_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "period"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"period"}, + }, + }, + }) +} + +const testAccVolcengineNatGatewayUpdateBasicAttributeConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_nat_gateway" "foo" { + vpc_id = "${volcengine_vpc.foo.id}" + subnet_id = "${volcengine_subnet.foo.id}" + spec = "Medium" + nat_gateway_name = "acc-test-ng-new" + description = "acc-test-new" + billing_type = "PostPaid" + project_name = "default" + tags { + key = "k1" + value = "v1" + } +} +` + +func TestAccVolcengineNatGatewayResource_UpdateBasicAttribute(t *testing.T) { + resourceName := "volcengine_nat_gateway.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &nat_gateway.VolcengineNatGatewayService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineNatGatewayCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "nat_gateway_name", "acc-test-ng"), + resource.TestCheckResourceAttr(acc.ResourceId, "description", "acc-test"), + resource.TestCheckResourceAttr(acc.ResourceId, "billing_type", "PostPaid"), + resource.TestCheckResourceAttr(acc.ResourceId, "project_name", "default"), + resource.TestCheckResourceAttr(acc.ResourceId, "spec", "Small"), + resource.TestCheckResourceAttr(acc.ResourceId, "tags.#", "1"), + volcengine.TestCheckTypeSetElemNestedAttrs(acc.ResourceId, "tags.*", map[string]string{ + "key": "k1", + "value": "v1", + }), + resource.TestCheckResourceAttrSet(acc.ResourceId, "subnet_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "vpc_id"), + resource.TestCheckNoResourceAttr(acc.ResourceId, "period"), + ), + }, + { + Config: testAccVolcengineNatGatewayUpdateBasicAttributeConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "nat_gateway_name", "acc-test-ng-new"), + resource.TestCheckResourceAttr(acc.ResourceId, "description", "acc-test-new"), + resource.TestCheckResourceAttr(acc.ResourceId, "billing_type", "PostPaid"), + resource.TestCheckResourceAttr(acc.ResourceId, "project_name", "default"), + resource.TestCheckResourceAttr(acc.ResourceId, "spec", "Medium"), + resource.TestCheckResourceAttr(acc.ResourceId, "tags.#", "1"), + volcengine.TestCheckTypeSetElemNestedAttrs(acc.ResourceId, "tags.*", map[string]string{ + "key": "k1", + "value": "v1", + }), + resource.TestCheckResourceAttrSet(acc.ResourceId, "subnet_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "vpc_id"), + resource.TestCheckNoResourceAttr(acc.ResourceId, "period"), + ), + }, + { + Config: testAccVolcengineNatGatewayUpdateBasicAttributeConfig, + PlanOnly: true, + ExpectNonEmptyPlan: false, // 修改之后,不应该再产生diff + }, + }, + }) +} + +const testAccVolcengineNatGatewayUpdateTagsConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_nat_gateway" "foo" { + vpc_id = "${volcengine_vpc.foo.id}" + subnet_id = "${volcengine_subnet.foo.id}" + spec = "Small" + nat_gateway_name = "acc-test-ng" + description = "acc-test" + billing_type = "PostPaid" + project_name = "default" + tags { + key = "k1" + value = "v1" + } + tags { + key = "k2" + value = "v2" + } +} +` + +func TestAccVolcengineNatGatewayResource_UpdateBasicTags(t *testing.T) { + resourceName := "volcengine_nat_gateway.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &nat_gateway.VolcengineNatGatewayService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineNatGatewayCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "nat_gateway_name", "acc-test-ng"), + resource.TestCheckResourceAttr(acc.ResourceId, "description", "acc-test"), + resource.TestCheckResourceAttr(acc.ResourceId, "billing_type", "PostPaid"), + resource.TestCheckResourceAttr(acc.ResourceId, "project_name", "default"), + resource.TestCheckResourceAttr(acc.ResourceId, "spec", "Small"), + resource.TestCheckResourceAttr(acc.ResourceId, "tags.#", "1"), + volcengine.TestCheckTypeSetElemNestedAttrs(acc.ResourceId, "tags.*", map[string]string{ + "key": "k1", + "value": "v1", + }), + resource.TestCheckResourceAttrSet(acc.ResourceId, "subnet_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "vpc_id"), + resource.TestCheckNoResourceAttr(acc.ResourceId, "period"), + ), + }, + { + Config: testAccVolcengineNatGatewayUpdateTagsConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "nat_gateway_name", "acc-test-ng"), + resource.TestCheckResourceAttr(acc.ResourceId, "description", "acc-test"), + resource.TestCheckResourceAttr(acc.ResourceId, "billing_type", "PostPaid"), + resource.TestCheckResourceAttr(acc.ResourceId, "project_name", "default"), + resource.TestCheckResourceAttr(acc.ResourceId, "spec", "Small"), + resource.TestCheckResourceAttr(acc.ResourceId, "tags.#", "2"), + volcengine.TestCheckTypeSetElemNestedAttrs(acc.ResourceId, "tags.*", map[string]string{ + "key": "k1", + "value": "v1", + }), + volcengine.TestCheckTypeSetElemNestedAttrs(acc.ResourceId, "tags.*", map[string]string{ + "key": "k2", + "value": "v2", + }), + resource.TestCheckResourceAttrSet(acc.ResourceId, "subnet_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "vpc_id"), + resource.TestCheckNoResourceAttr(acc.ResourceId, "period"), + ), + }, + { + Config: testAccVolcengineNatGatewayUpdateTagsConfig, + PlanOnly: true, + ExpectNonEmptyPlan: false, // 修改之后,不应该再产生diff + }, + }, + }) +} diff --git a/volcengine/nat/snat_entry/data_source_volcengine_snat_entries_test.go b/volcengine/nat/snat_entry/data_source_volcengine_snat_entries_test.go new file mode 100644 index 00000000..f8230902 --- /dev/null +++ b/volcengine/nat/snat_entry/data_source_volcengine_snat_entries_test.go @@ -0,0 +1,97 @@ +package snat_entry_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/nat/snat_entry" + "testing" +) + +const testAccVolcengineSnatEntriesDatasourceConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_nat_gateway" "foo" { + vpc_id = "${volcengine_vpc.foo.id}" + subnet_id = "${volcengine_subnet.foo.id}" + spec = "Small" + nat_gateway_name = "acc-test-ng" + description = "acc-test" + billing_type = "PostPaid" + project_name = "default" + tags { + key = "k1" + value = "v1" + } +} + +resource "volcengine_eip_address" "foo" { + name = "acc-test-eip" + description = "acc-test" + bandwidth = 1 + billing_type = "PostPaidByBandwidth" + isp = "BGP" +} + +resource "volcengine_eip_associate" "foo" { + allocation_id = "${volcengine_eip_address.foo.id}" + instance_id = "${volcengine_nat_gateway.foo.id}" + instance_type = "Nat" +} + +resource "volcengine_snat_entry" "foo1" { + snat_entry_name = "acc-test-snat-entry" + nat_gateway_id = "${volcengine_nat_gateway.foo.id}" + eip_id = "${volcengine_eip_address.foo.id}" + source_cidr = "172.16.0.0/24" + depends_on = ["volcengine_eip_associate.foo"] +} + +resource "volcengine_snat_entry" "foo2" { + snat_entry_name = "acc-test-snat-entry" + nat_gateway_id = "${volcengine_nat_gateway.foo.id}" + eip_id = "${volcengine_eip_address.foo.id}" + source_cidr = "172.16.0.0/16" + depends_on = ["volcengine_eip_associate.foo"] +} + +data "volcengine_snat_entries" "foo"{ + ids = ["${volcengine_snat_entry.foo1.id}", "${volcengine_snat_entry.foo2.id}"] +} +` + +func TestAccVolcengineSnatEntriesDatasource_Basic(t *testing.T) { + resourceName := "data.volcengine_snat_entries.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &snat_entry.VolcengineSnatEntryService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineSnatEntriesDatasourceConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(acc.ResourceId, "snat_entries.#", "2"), + ), + }, + }, + }) +} diff --git a/volcengine/nat/snat_entry/resource_volcengine_snat_entry.go b/volcengine/nat/snat_entry/resource_volcengine_snat_entry.go index a375bd9e..d31c88a8 100644 --- a/volcengine/nat/snat_entry/resource_volcengine_snat_entry.go +++ b/volcengine/nat/snat_entry/resource_volcengine_snat_entry.go @@ -42,6 +42,7 @@ func ResourceVolcengineSnatEntry() *schema.Resource { "subnet_id": { Type: schema.TypeString, Optional: true, + Computed: true, ForceNew: true, ExactlyOneOf: []string{"subnet_id", "source_cidr"}, Description: "The id of the subnet that is required to access the internet. Only one of `subnet_id,source_cidr` can be specified.", @@ -65,6 +66,7 @@ func ResourceVolcengineSnatEntry() *schema.Resource { "source_cidr": { Type: schema.TypeString, Optional: true, + Computed: true, ForceNew: true, ExactlyOneOf: []string{"subnet_id", "source_cidr"}, Description: "The SourceCidr of the SNAT entry. Only one of `subnet_id,source_cidr` can be specified.", diff --git a/volcengine/nat/snat_entry/resource_volcengine_snat_entry_test.go b/volcengine/nat/snat_entry/resource_volcengine_snat_entry_test.go new file mode 100644 index 00000000..0ba65d5d --- /dev/null +++ b/volcengine/nat/snat_entry/resource_volcengine_snat_entry_test.go @@ -0,0 +1,301 @@ +package snat_entry_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/nat/snat_entry" + "testing" +) + +const testAccVolcengineSnatEntryCreateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_nat_gateway" "foo" { + vpc_id = "${volcengine_vpc.foo.id}" + subnet_id = "${volcengine_subnet.foo.id}" + spec = "Small" + nat_gateway_name = "acc-test-ng" + description = "acc-test" + billing_type = "PostPaid" + project_name = "default" + tags { + key = "k1" + value = "v1" + } +} + +resource "volcengine_eip_address" "foo" { + name = "acc-test-eip" + description = "acc-test" + bandwidth = 1 + billing_type = "PostPaidByBandwidth" + isp = "BGP" +} + +resource "volcengine_eip_associate" "foo" { + allocation_id = "${volcengine_eip_address.foo.id}" + instance_id = "${volcengine_nat_gateway.foo.id}" + instance_type = "Nat" +} + +resource "volcengine_snat_entry" "foo" { + snat_entry_name = "acc-test-snat-entry" + nat_gateway_id = "${volcengine_nat_gateway.foo.id}" + eip_id = "${volcengine_eip_address.foo.id}" + subnet_id = "${volcengine_subnet.foo.id}" + depends_on = [volcengine_eip_associate.foo] +} +` + +func TestAccVolcengineSnatEntryResource_Basic(t *testing.T) { + resourceName := "volcengine_snat_entry.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &snat_entry.VolcengineSnatEntryService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineSnatEntryCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "snat_entry_name", "acc-test-snat-entry"), + resource.TestCheckResourceAttr(acc.ResourceId, "status", "Available"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "eip_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "nat_gateway_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "subnet_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "source_cidr"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccVolcengineSnatEntryCreateSourceCidrConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_nat_gateway" "foo" { + vpc_id = "${volcengine_vpc.foo.id}" + subnet_id = "${volcengine_subnet.foo.id}" + spec = "Small" + nat_gateway_name = "acc-test-ng" + description = "acc-test" + billing_type = "PostPaid" + project_name = "default" + tags { + key = "k1" + value = "v1" + } +} + +resource "volcengine_eip_address" "foo" { + name = "acc-test-eip" + description = "acc-test" + bandwidth = 1 + billing_type = "PostPaidByBandwidth" + isp = "BGP" +} + +resource "volcengine_eip_associate" "foo" { + allocation_id = "${volcengine_eip_address.foo.id}" + instance_id = "${volcengine_nat_gateway.foo.id}" + instance_type = "Nat" +} + +resource "volcengine_snat_entry" "foo" { + snat_entry_name = "acc-test-snat-entry" + nat_gateway_id = "${volcengine_nat_gateway.foo.id}" + eip_id = "${volcengine_eip_address.foo.id}" + source_cidr = "172.16.0.0/24" + depends_on = [volcengine_eip_associate.foo] +} +` + +func TestAccVolcengineSnatEntryResource_SourceCidr(t *testing.T) { + resourceName := "volcengine_snat_entry.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &snat_entry.VolcengineSnatEntryService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineSnatEntryCreateSourceCidrConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "snat_entry_name", "acc-test-snat-entry"), + resource.TestCheckResourceAttr(acc.ResourceId, "status", "Available"), + resource.TestCheckResourceAttr(acc.ResourceId, "source_cidr", "172.16.0.0/24"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "eip_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "nat_gateway_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "subnet_id"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccVolcengineSnatEntryUpdateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_nat_gateway" "foo" { + vpc_id = "${volcengine_vpc.foo.id}" + subnet_id = "${volcengine_subnet.foo.id}" + spec = "Small" + nat_gateway_name = "acc-test-ng" + description = "acc-test" + billing_type = "PostPaid" + project_name = "default" + tags { + key = "k1" + value = "v1" + } +} + +resource "volcengine_eip_address" "foo" { + name = "acc-test-eip" + description = "acc-test" + bandwidth = 1 + billing_type = "PostPaidByBandwidth" + isp = "BGP" +} + +resource "volcengine_eip_associate" "foo" { + allocation_id = "${volcengine_eip_address.foo.id}" + instance_id = "${volcengine_nat_gateway.foo.id}" + instance_type = "Nat" +} + +resource "volcengine_eip_address" "foo1" { + name = "acc-test-eip1" + description = "acc-test" + bandwidth = 1 + billing_type = "PostPaidByBandwidth" + isp = "BGP" +} + +resource "volcengine_eip_associate" "foo1" { + allocation_id = "${volcengine_eip_address.foo1.id}" + instance_id = "${volcengine_nat_gateway.foo.id}" + instance_type = "Nat" +} + +resource "volcengine_snat_entry" "foo" { + snat_entry_name = "acc-test-snat-entry-new" + nat_gateway_id = "${volcengine_nat_gateway.foo.id}" + eip_id = "${volcengine_eip_address.foo1.id}" + subnet_id = "${volcengine_subnet.foo.id}" + depends_on = [volcengine_eip_associate.foo1] +} +` + +func TestAccVolcengineSnatEntryResource_Update(t *testing.T) { + resourceName := "volcengine_snat_entry.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &snat_entry.VolcengineSnatEntryService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineSnatEntryCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "snat_entry_name", "acc-test-snat-entry"), + resource.TestCheckResourceAttr(acc.ResourceId, "status", "Available"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "eip_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "nat_gateway_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "subnet_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "source_cidr"), + ), + }, + { + Config: testAccVolcengineSnatEntryUpdateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "snat_entry_name", "acc-test-snat-entry-new"), + resource.TestCheckResourceAttr(acc.ResourceId, "status", "Available"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "eip_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "nat_gateway_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "subnet_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "source_cidr"), + ), + }, + { + Config: testAccVolcengineSnatEntryUpdateConfig, + PlanOnly: true, + ExpectNonEmptyPlan: false, // 修改之后,不应该再产生diff + }, + }, + }) +} diff --git a/volcengine/tos/bucket_policy/resource_volcengine_tos_bucket_policy.go b/volcengine/tos/bucket_policy/resource_volcengine_tos_bucket_policy.go index 6b923ab9..775dd65a 100644 --- a/volcengine/tos/bucket_policy/resource_volcengine_tos_bucket_policy.go +++ b/volcengine/tos/bucket_policy/resource_volcengine_tos_bucket_policy.go @@ -119,7 +119,7 @@ func resourceVolcengineTosBucketPolicyCreate(d *schema.ResourceData, meta interf tosBucketService := NewTosBucketPolicyService(meta.(*ve.SdkClient)) err = ve.DefaultDispatcher().Create(tosBucketService, d, ResourceVolcengineTosBucketPolicy()) if err != nil { - return fmt.Errorf("error on creating tos bucket %q, %s", d.Id(), err) + return fmt.Errorf("error on creating tos bucket policy %q, %s", d.Id(), err) } return resourceVolcengineTosBucketPolicyRead(d, meta) } @@ -128,7 +128,7 @@ func resourceVolcengineTosBucketPolicyRead(d *schema.ResourceData, meta interfac tosBucketService := NewTosBucketPolicyService(meta.(*ve.SdkClient)) err = ve.DefaultDispatcher().Read(tosBucketService, d, ResourceVolcengineTosBucketPolicy()) if err != nil { - return fmt.Errorf("error on reading tos bucket %q, %s", d.Id(), err) + return fmt.Errorf("error on reading tos bucket policy %q, %s", d.Id(), err) } return err } @@ -137,7 +137,7 @@ func resourceVolcengineTosBucketPolicyUpdate(d *schema.ResourceData, meta interf tosBucketService := NewTosBucketPolicyService(meta.(*ve.SdkClient)) err = ve.DefaultDispatcher().Update(tosBucketService, d, ResourceVolcengineTosBucketPolicy()) if err != nil { - return fmt.Errorf("error on updating tos bucket %q, %s", d.Id(), err) + return fmt.Errorf("error on updating tos bucket policy %q, %s", d.Id(), err) } return resourceVolcengineTosBucketPolicyRead(d, meta) } @@ -146,7 +146,7 @@ func resourceVolcengineTosBucketPolicyDelete(d *schema.ResourceData, meta interf tosBucketService := NewTosBucketPolicyService(meta.(*ve.SdkClient)) err = ve.DefaultDispatcher().Delete(tosBucketService, d, ResourceVolcengineTosBucketPolicy()) if err != nil { - return fmt.Errorf("error on deleting tos bucket %q, %s", d.Id(), err) + return fmt.Errorf("error on deleting tos bucket policy %q, %s", d.Id(), err) } return err } diff --git a/volcengine/tos/object/resource_volcengine_tos_object.go b/volcengine/tos/object/resource_volcengine_tos_object.go index 95bb8e3b..90a9c209 100644 --- a/volcengine/tos/object/resource_volcengine_tos_object.go +++ b/volcengine/tos/object/resource_volcengine_tos_object.go @@ -171,7 +171,7 @@ func resourceVolcengineTosObjectCreate(d *schema.ResourceData, meta interface{}) tosBucketService := NewTosObjectService(meta.(*ve.SdkClient)) err = ve.DefaultDispatcher().Create(tosBucketService, d, ResourceVolcengineTosObject()) if err != nil { - return fmt.Errorf("error on creating tos bucket %q, %s", d.Id(), err) + return fmt.Errorf("error on creating tos object %q, %s", d.Id(), err) } return resourceVolcengineTosObjectRead(d, meta) } @@ -180,7 +180,7 @@ func resourceVolcengineTosObjectRead(d *schema.ResourceData, meta interface{}) ( tosBucketService := NewTosObjectService(meta.(*ve.SdkClient)) err = ve.DefaultDispatcher().Read(tosBucketService, d, ResourceVolcengineTosObject()) if err != nil { - return fmt.Errorf("error on reading tos bucket %q, %s", d.Id(), err) + return fmt.Errorf("error on reading tos object %q, %s", d.Id(), err) } return err } @@ -189,7 +189,7 @@ func resourceVolcengineTosObjectUpdate(d *schema.ResourceData, meta interface{}) tosBucketService := NewTosObjectService(meta.(*ve.SdkClient)) err = ve.DefaultDispatcher().Update(tosBucketService, d, ResourceVolcengineTosObject()) if err != nil { - return fmt.Errorf("error on updating tos bucket %q, %s", d.Id(), err) + return fmt.Errorf("error on updating tos object %q, %s", d.Id(), err) } return resourceVolcengineTosObjectRead(d, meta) } @@ -198,7 +198,7 @@ func resourceVolcengineTosObjectDelete(d *schema.ResourceData, meta interface{}) tosBucketService := NewTosObjectService(meta.(*ve.SdkClient)) err = ve.DefaultDispatcher().Delete(tosBucketService, d, ResourceVolcengineTosObject()) if err != nil { - return fmt.Errorf("error on deleting tos bucket %q, %s", d.Id(), err) + return fmt.Errorf("error on deleting tos object %q, %s", d.Id(), err) } return err } diff --git a/volcengine/vpn/customer_gateway/data_source_volcengine_customer_gateways_test.go b/volcengine/vpn/customer_gateway/data_source_volcengine_customer_gateways_test.go new file mode 100644 index 00000000..f4281dd3 --- /dev/null +++ b/volcengine/vpn/customer_gateway/data_source_volcengine_customer_gateways_test.go @@ -0,0 +1,44 @@ +package customer_gateway_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/vpn/customer_gateway" + "testing" +) + +const testAccVolcengineCustomerGatewaysDatasourceConfig = ` +resource "volcengine_customer_gateway" "foo" { + ip_address = "192.0.1.3" + customer_gateway_name = "acc-test" + description = "acc-test" + project_name = "default" +} +data "volcengine_customer_gateways" "foo"{ + ids = ["${volcengine_customer_gateway.foo.id}"] +} +` + +func TestAccVolcengineCustomerGatewaysDatasource_Basic(t *testing.T) { + resourceName := "data.volcengine_customer_gateways.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &customer_gateway.VolcengineCustomerGatewayService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineCustomerGatewaysDatasourceConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(acc.ResourceId, "customer_gateways.#", "1"), + ), + }, + }, + }) +} diff --git a/volcengine/vpn/customer_gateway/resource_volcengine_customer_gateway_test.go b/volcengine/vpn/customer_gateway/resource_volcengine_customer_gateway_test.go new file mode 100644 index 00000000..45f5da0f --- /dev/null +++ b/volcengine/vpn/customer_gateway/resource_volcengine_customer_gateway_test.go @@ -0,0 +1,104 @@ +package customer_gateway_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/vpn/customer_gateway" + "testing" +) + +const testAccVolcengineCustomerGatewayCreateConfig = ` +resource "volcengine_customer_gateway" "foo" { + ip_address = "192.0.1.3" + customer_gateway_name = "acc-test" + description = "acc-test" + project_name = "default" +} +` + +const testAccVolcengineCustomerGatewayUpdateConfig = ` +resource "volcengine_customer_gateway" "foo" { + customer_gateway_name = "acc-test1" + description = "acc-test1" + ip_address = "192.0.1.3" + project_name = "default" +} +` + +func TestAccVolcengineCustomerGatewayResource_Basic(t *testing.T) { + resourceName := "volcengine_customer_gateway.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &customer_gateway.VolcengineCustomerGatewayService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineCustomerGatewayCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "customer_gateway_name", "acc-test"), + resource.TestCheckResourceAttr(acc.ResourceId, "description", "acc-test"), + resource.TestCheckResourceAttr(acc.ResourceId, "ip_address", "192.0.1.3"), + resource.TestCheckResourceAttr(acc.ResourceId, "project_name", "default"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccVolcengineCustomerGatewayResource_Update(t *testing.T) { + resourceName := "volcengine_customer_gateway.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &customer_gateway.VolcengineCustomerGatewayService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineCustomerGatewayCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "customer_gateway_name", "acc-test"), + resource.TestCheckResourceAttr(acc.ResourceId, "description", "acc-test"), + resource.TestCheckResourceAttr(acc.ResourceId, "ip_address", "192.0.1.3"), + resource.TestCheckResourceAttr(acc.ResourceId, "project_name", "default"), + ), + }, + { + Config: testAccVolcengineCustomerGatewayUpdateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "customer_gateway_name", "acc-test1"), + resource.TestCheckResourceAttr(acc.ResourceId, "description", "acc-test1"), + resource.TestCheckResourceAttr(acc.ResourceId, "ip_address", "192.0.1.3"), + resource.TestCheckResourceAttr(acc.ResourceId, "project_name", "default"), + ), + }, + { + Config: testAccVolcengineCustomerGatewayUpdateConfig, + PlanOnly: true, + ExpectNonEmptyPlan: false, // 修改之后,不应该再产生diff + }, + }, + }) +} diff --git a/volcengine/vpn/vpn_connection/data_source_volcengine_vpn_connections_test.go b/volcengine/vpn/vpn_connection/data_source_volcengine_vpn_connections_test.go new file mode 100644 index 00000000..b46adc26 --- /dev/null +++ b/volcengine/vpn/vpn_connection/data_source_volcengine_vpn_connections_test.go @@ -0,0 +1,95 @@ +package vpn_connection_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/vpn/vpn_connection" + "testing" +) + +const testAccVolcengineVpnConnectionsDatasourceConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_vpn_gateway" "foo" { + vpc_id = "${volcengine_vpc.foo.id}" + subnet_id = "${volcengine_subnet.foo.id}" + bandwidth = 20 + vpn_gateway_name = "acc-test" + description = "acc-test" + period = 2 + project_name = "default" +} + +resource "volcengine_customer_gateway" "foo" { + ip_address = "192.0.1.3" + customer_gateway_name = "acc-test" + description = "acc-test" + project_name = "default" +} + +resource "volcengine_vpn_connection" "foo" { + vpn_connection_name = "acc-tf-test" + description = "acc-tf-test" + vpn_gateway_id = "${volcengine_vpn_gateway.foo.id}" + customer_gateway_id = "${volcengine_customer_gateway.foo.id}" + local_subnet = ["192.168.0.0/22"] + remote_subnet = ["192.161.0.0/20"] + dpd_action = "none" + nat_traversal = true + ike_config_psk = "acctest@!3" + ike_config_version = "ikev1" + ike_config_mode = "main" + ike_config_enc_alg = "aes" + ike_config_auth_alg = "md5" + ike_config_dh_group = "group2" + ike_config_lifetime = 9000 + ike_config_local_id = "acc_test" + ike_config_remote_id = "acc_test" + ipsec_config_enc_alg = "aes" + ipsec_config_auth_alg = "sha256" + ipsec_config_dh_group = "group2" + ipsec_config_lifetime = 9000 + project_name = "default" +} + +data "volcengine_vpn_connections" "foo"{ + ids = ["${volcengine_vpn_connection.foo.id}"] +} +` + +func TestAccVolcengineVpnConnectionsDatasource_Basic(t *testing.T) { + resourceName := "data.volcengine_vpn_connections.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &vpn_connection.VolcengineVpnConnectionService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineVpnConnectionsDatasourceConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(acc.ResourceId, "vpn_connections.#", "1"), + ), + }, + }, + }) +} diff --git a/volcengine/vpn/vpn_connection/resource_volcengine_vpn_connection_test.go b/volcengine/vpn/vpn_connection/resource_volcengine_vpn_connection_test.go new file mode 100644 index 00000000..a3d4bbb5 --- /dev/null +++ b/volcengine/vpn/vpn_connection/resource_volcengine_vpn_connection_test.go @@ -0,0 +1,253 @@ +package vpn_connection_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/vpn/vpn_connection" + "testing" +) + +const testAccVolcengineVpnConnectionCreateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_vpn_gateway" "foo" { + vpc_id = "${volcengine_vpc.foo.id}" + subnet_id = "${volcengine_subnet.foo.id}" + bandwidth = 20 + vpn_gateway_name = "acc-test" + description = "acc-test" + period = 2 + project_name = "default" +} + +resource "volcengine_customer_gateway" "foo" { + ip_address = "192.0.1.3" + customer_gateway_name = "acc-test" + description = "acc-test" + project_name = "default" +} + +resource "volcengine_vpn_connection" "foo" { + vpn_connection_name = "acc-tf-test" + description = "acc-tf-test" + vpn_gateway_id = "${volcengine_vpn_gateway.foo.id}" + customer_gateway_id = "${volcengine_customer_gateway.foo.id}" + local_subnet = ["192.168.0.0/22"] + remote_subnet = ["192.161.0.0/20"] + dpd_action = "none" + nat_traversal = true + ike_config_psk = "acctest@!3" + ike_config_version = "ikev1" + ike_config_mode = "main" + ike_config_enc_alg = "aes" + ike_config_auth_alg = "md5" + ike_config_dh_group = "group2" + ike_config_lifetime = 9000 + ike_config_local_id = "acc_test" + ike_config_remote_id = "acc_test" + ipsec_config_enc_alg = "aes" + ipsec_config_auth_alg = "sha256" + ipsec_config_dh_group = "group2" + ipsec_config_lifetime = 9000 + project_name = "default" + log_enabled = false +} + +` + +const testAccVolcengineVpnConnectionUpdateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_vpn_gateway" "foo" { + vpc_id = "${volcengine_vpc.foo.id}" + subnet_id = "${volcengine_subnet.foo.id}" + bandwidth = 20 + vpn_gateway_name = "acc-test" + description = "acc-test" + period = 2 + project_name = "default" +} + +resource "volcengine_customer_gateway" "foo" { + ip_address = "192.0.1.3" + customer_gateway_name = "acc-test" + description = "acc-test" + project_name = "default" +} + +resource "volcengine_vpn_connection" "foo" { + vpn_connection_name = "acc-tf-test1" + description = "acc-tf-test1" + vpn_gateway_id = "${volcengine_vpn_gateway.foo.id}" + customer_gateway_id = "${volcengine_customer_gateway.foo.id}" + local_subnet = ["192.168.0.0/22"] + remote_subnet = ["192.161.0.0/20"] + dpd_action = "clear" + nat_traversal = true + ike_config_psk = "acctest@!31" + ike_config_version = "ikev1" + ike_config_mode = "main" + ike_config_enc_alg = "aes" + ike_config_auth_alg = "md5" + ike_config_dh_group = "group2" + ike_config_lifetime = 9000 + ike_config_local_id = "acc_test" + ike_config_remote_id = "acc_test" + ipsec_config_enc_alg = "aes" + ipsec_config_auth_alg = "sha256" + ipsec_config_dh_group = "group1" + ipsec_config_lifetime = 10000 + project_name = "default" + log_enabled = true +} + +` + +func TestAccVolcengineVpnConnectionResource_Basic(t *testing.T) { + resourceName := "volcengine_vpn_connection.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &vpn_connection.VolcengineVpnConnectionService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineVpnConnectionCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "description", "acc-tf-test"), + resource.TestCheckResourceAttr(acc.ResourceId, "dpd_action", "none"), + resource.TestCheckResourceAttr(acc.ResourceId, "ike_config_auth_alg", "md5"), + resource.TestCheckResourceAttr(acc.ResourceId, "ike_config_dh_group", "group2"), + resource.TestCheckResourceAttr(acc.ResourceId, "ike_config_enc_alg", "aes"), + resource.TestCheckResourceAttr(acc.ResourceId, "ike_config_lifetime", "9000"), + resource.TestCheckResourceAttr(acc.ResourceId, "ike_config_local_id", "acc_test"), + resource.TestCheckResourceAttr(acc.ResourceId, "ike_config_mode", "main"), + resource.TestCheckResourceAttr(acc.ResourceId, "ike_config_psk", "acctest@!3"), + resource.TestCheckResourceAttr(acc.ResourceId, "ike_config_remote_id", "acc_test"), + resource.TestCheckResourceAttr(acc.ResourceId, "ike_config_version", "ikev1"), + resource.TestCheckResourceAttr(acc.ResourceId, "ipsec_config_auth_alg", "sha256"), + resource.TestCheckResourceAttr(acc.ResourceId, "ipsec_config_dh_group", "group2"), + resource.TestCheckResourceAttr(acc.ResourceId, "ipsec_config_enc_alg", "aes"), + resource.TestCheckResourceAttr(acc.ResourceId, "ipsec_config_lifetime", "9000"), + resource.TestCheckResourceAttr(acc.ResourceId, "log_enabled", "false"), + resource.TestCheckResourceAttr(acc.ResourceId, "nat_traversal", "true"), + resource.TestCheckResourceAttr(acc.ResourceId, "project_name", "default"), + resource.TestCheckResourceAttr(acc.ResourceId, "vpn_connection_name", "acc-tf-test"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccVolcengineVpnConnectionResource_Update(t *testing.T) { + resourceName := "volcengine_vpn_connection.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &vpn_connection.VolcengineVpnConnectionService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineVpnConnectionCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "description", "acc-tf-test"), + resource.TestCheckResourceAttr(acc.ResourceId, "dpd_action", "none"), + resource.TestCheckResourceAttr(acc.ResourceId, "ike_config_auth_alg", "md5"), + resource.TestCheckResourceAttr(acc.ResourceId, "ike_config_dh_group", "group2"), + resource.TestCheckResourceAttr(acc.ResourceId, "ike_config_enc_alg", "aes"), + resource.TestCheckResourceAttr(acc.ResourceId, "ike_config_lifetime", "9000"), + resource.TestCheckResourceAttr(acc.ResourceId, "ike_config_local_id", "acc_test"), + resource.TestCheckResourceAttr(acc.ResourceId, "ike_config_mode", "main"), + resource.TestCheckResourceAttr(acc.ResourceId, "ike_config_psk", "acctest@!3"), + resource.TestCheckResourceAttr(acc.ResourceId, "ike_config_remote_id", "acc_test"), + resource.TestCheckResourceAttr(acc.ResourceId, "ike_config_version", "ikev1"), + resource.TestCheckResourceAttr(acc.ResourceId, "ipsec_config_auth_alg", "sha256"), + resource.TestCheckResourceAttr(acc.ResourceId, "ipsec_config_dh_group", "group2"), + resource.TestCheckResourceAttr(acc.ResourceId, "ipsec_config_enc_alg", "aes"), + resource.TestCheckResourceAttr(acc.ResourceId, "ipsec_config_lifetime", "9000"), + resource.TestCheckResourceAttr(acc.ResourceId, "log_enabled", "false"), + resource.TestCheckResourceAttr(acc.ResourceId, "nat_traversal", "true"), + resource.TestCheckResourceAttr(acc.ResourceId, "project_name", "default"), + resource.TestCheckResourceAttr(acc.ResourceId, "vpn_connection_name", "acc-tf-test"), + ), + }, + { + Config: testAccVolcengineVpnConnectionUpdateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "description", "acc-tf-test1"), + resource.TestCheckResourceAttr(acc.ResourceId, "dpd_action", "clear"), + resource.TestCheckResourceAttr(acc.ResourceId, "ike_config_auth_alg", "md5"), + resource.TestCheckResourceAttr(acc.ResourceId, "ike_config_dh_group", "group2"), + resource.TestCheckResourceAttr(acc.ResourceId, "ike_config_enc_alg", "aes"), + resource.TestCheckResourceAttr(acc.ResourceId, "ike_config_lifetime", "9000"), + resource.TestCheckResourceAttr(acc.ResourceId, "ike_config_local_id", "acc_test"), + resource.TestCheckResourceAttr(acc.ResourceId, "ike_config_mode", "main"), + resource.TestCheckResourceAttr(acc.ResourceId, "ike_config_psk", "acctest@!31"), + resource.TestCheckResourceAttr(acc.ResourceId, "ike_config_remote_id", "acc_test"), + resource.TestCheckResourceAttr(acc.ResourceId, "ike_config_version", "ikev1"), + resource.TestCheckResourceAttr(acc.ResourceId, "ipsec_config_auth_alg", "sha256"), + resource.TestCheckResourceAttr(acc.ResourceId, "ipsec_config_dh_group", "group1"), + resource.TestCheckResourceAttr(acc.ResourceId, "ipsec_config_enc_alg", "aes"), + resource.TestCheckResourceAttr(acc.ResourceId, "ipsec_config_lifetime", "10000"), + resource.TestCheckResourceAttr(acc.ResourceId, "log_enabled", "true"), + resource.TestCheckResourceAttr(acc.ResourceId, "nat_traversal", "true"), + resource.TestCheckResourceAttr(acc.ResourceId, "project_name", "default"), + resource.TestCheckResourceAttr(acc.ResourceId, "vpn_connection_name", "acc-tf-test1"), + ), + }, + { + Config: testAccVolcengineVpnConnectionUpdateConfig, + PlanOnly: true, + ExpectNonEmptyPlan: false, // 修改之后,不应该再产生diff + }, + }, + }) +} diff --git a/volcengine/vpn/vpn_gateway/data_source_volcengine_vpn_gateways_test.go b/volcengine/vpn/vpn_gateway/data_source_volcengine_vpn_gateways_test.go new file mode 100644 index 00000000..f255000b --- /dev/null +++ b/volcengine/vpn/vpn_gateway/data_source_volcengine_vpn_gateways_test.go @@ -0,0 +1,64 @@ +package vpn_gateway_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/vpn/vpn_gateway" + "testing" +) + +const testAccVolcengineVpnGatewaysDatasourceConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_vpn_gateway" "foo" { + vpc_id = "${volcengine_vpc.foo.id}" + subnet_id = "${volcengine_subnet.foo.id}" + bandwidth = 20 + vpn_gateway_name = "acc-test" + description = "acc-test" + period = 2 + project_name = "default" +} + + +data "volcengine_vpn_gateways" "foo"{ + ids = ["${volcengine_vpn_gateway.foo.id}"] +} +` + +func TestAccVolcengineVpnGatewaysDatasource_Basic(t *testing.T) { + resourceName := "data.volcengine_vpn_gateways.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &vpn_gateway.VolcengineVpnGatewayService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineVpnGatewaysDatasourceConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(acc.ResourceId, "vpn_gateways.#", "1"), + ), + }, + }, + }) +} diff --git a/volcengine/vpn/vpn_gateway/resource_volcengine_vpn_gateway_test.go b/volcengine/vpn/vpn_gateway/resource_volcengine_vpn_gateway_test.go new file mode 100644 index 00000000..9f3ade35 --- /dev/null +++ b/volcengine/vpn/vpn_gateway/resource_volcengine_vpn_gateway_test.go @@ -0,0 +1,148 @@ +package vpn_gateway_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/vpn/vpn_gateway" + "testing" +) + +const testAccVolcengineVpnGatewayCreateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_vpn_gateway" "foo" { + vpc_id = "${volcengine_vpc.foo.id}" + subnet_id = "${volcengine_subnet.foo.id}" + bandwidth = 20 + vpn_gateway_name = "acc-test" + description = "acc-test" + period = 2 + project_name = "default" +} + +` + +const testAccVolcengineVpnGatewayUpdateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_vpn_gateway" "foo" { + vpc_id = "${volcengine_vpc.foo.id}" + subnet_id = "${volcengine_subnet.foo.id}" + bandwidth = 50 + vpn_gateway_name = "acc-test1" + description = "acc-test1" + period = 2 + project_name = "default" +} + +` + +func TestAccVolcengineVpnGatewayResource_Basic(t *testing.T) { + resourceName := "volcengine_vpn_gateway.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &vpn_gateway.VolcengineVpnGatewayService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineVpnGatewayCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "bandwidth", "20"), + resource.TestCheckResourceAttr(acc.ResourceId, "billing_type", "PrePaid"), + resource.TestCheckResourceAttr(acc.ResourceId, "description", "acc-test"), + resource.TestCheckResourceAttr(acc.ResourceId, "period", "2"), + resource.TestCheckResourceAttr(acc.ResourceId, "project_name", "default"), + resource.TestCheckResourceAttr(acc.ResourceId, "vpn_gateway_name", "acc-test"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccVolcengineVpnGatewayResource_Update(t *testing.T) { + resourceName := "volcengine_vpn_gateway.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &vpn_gateway.VolcengineVpnGatewayService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineVpnGatewayCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "bandwidth", "20"), + resource.TestCheckResourceAttr(acc.ResourceId, "billing_type", "PrePaid"), + resource.TestCheckResourceAttr(acc.ResourceId, "description", "acc-test"), + resource.TestCheckResourceAttr(acc.ResourceId, "period", "2"), + resource.TestCheckResourceAttr(acc.ResourceId, "project_name", "default"), + resource.TestCheckResourceAttr(acc.ResourceId, "vpn_gateway_name", "acc-test"), + ), + }, + { + Config: testAccVolcengineVpnGatewayUpdateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "bandwidth", "50"), + resource.TestCheckResourceAttr(acc.ResourceId, "billing_type", "PrePaid"), + resource.TestCheckResourceAttr(acc.ResourceId, "description", "acc-test1"), + resource.TestCheckResourceAttr(acc.ResourceId, "period", "2"), + resource.TestCheckResourceAttr(acc.ResourceId, "project_name", "default"), + resource.TestCheckResourceAttr(acc.ResourceId, "vpn_gateway_name", "acc-test1"), + ), + }, + { + Config: testAccVolcengineVpnGatewayUpdateConfig, + PlanOnly: true, + ExpectNonEmptyPlan: false, // 修改之后,不应该再产生diff + }, + }, + }) +} diff --git a/volcengine/vpn/vpn_gateway/service_volcengine_vpn_gateway.go b/volcengine/vpn/vpn_gateway/service_volcengine_vpn_gateway.go index 3eda46dc..b1e0aefc 100644 --- a/volcengine/vpn/vpn_gateway/service_volcengine_vpn_gateway.go +++ b/volcengine/vpn/vpn_gateway/service_volcengine_vpn_gateway.go @@ -177,7 +177,7 @@ func (s *VolcengineVpnGatewayService) RefreshResourceState(resourceData *schema. func (VolcengineVpnGatewayService) WithResourceResponseHandlers(v map[string]interface{}) []ve.ResourceResponseHandler { handler := func() (map[string]interface{}, map[string]ve.ResponseConvert, error) { - if v["BillingType"].(float64) == 1 { + if v["BillingType"].(float64) == 1 && strings.Contains(v["ExpiredTime"].(string), "+") { ct, _ := time.Parse("2006-01-02T15:04:05", v["CreationTime"].(string)[0:strings.Index(v["CreationTime"].(string), "+")]) et, _ := time.Parse("2006-01-02T15:04:05", v["ExpiredTime"].(string)[0:strings.Index(v["ExpiredTime"].(string), "+")]) y := et.Year() - ct.Year() diff --git a/volcengine/vpn/vpn_gateway_route/data_source_volcengine_vpn_gateway_routes_test.go b/volcengine/vpn/vpn_gateway_route/data_source_volcengine_vpn_gateway_routes_test.go new file mode 100644 index 00000000..61d1555f --- /dev/null +++ b/volcengine/vpn/vpn_gateway_route/data_source_volcengine_vpn_gateway_routes_test.go @@ -0,0 +1,102 @@ +package vpn_gateway_route_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/vpn/vpn_gateway_route" + "testing" +) + +const testAccVolcengineVpnGatewayRoutesDatasourceConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_vpn_gateway" "foo" { + vpc_id = "${volcengine_vpc.foo.id}" + subnet_id = "${volcengine_subnet.foo.id}" + bandwidth = 20 + vpn_gateway_name = "acc-test" + description = "acc-test" + period = 2 + project_name = "default" +} + +resource "volcengine_customer_gateway" "foo" { + ip_address = "192.0.1.3" + customer_gateway_name = "acc-test" + description = "acc-test" + project_name = "default" +} + +resource "volcengine_vpn_connection" "foo" { + vpn_connection_name = "acc-tf-test" + description = "acc-tf-test" + vpn_gateway_id = "${volcengine_vpn_gateway.foo.id}" + customer_gateway_id = "${volcengine_customer_gateway.foo.id}" + local_subnet = ["192.168.0.0/22"] + remote_subnet = ["192.161.0.0/20"] + dpd_action = "none" + nat_traversal = true + ike_config_psk = "acctest@!3" + ike_config_version = "ikev1" + ike_config_mode = "main" + ike_config_enc_alg = "aes" + ike_config_auth_alg = "md5" + ike_config_dh_group = "group2" + ike_config_lifetime = 9000 + ike_config_local_id = "acc_test" + ike_config_remote_id = "acc_test" + ipsec_config_enc_alg = "aes" + ipsec_config_auth_alg = "sha256" + ipsec_config_dh_group = "group2" + ipsec_config_lifetime = 9000 + project_name = "default" + log_enabled = false +} + +resource "volcengine_vpn_gateway_route" "foo" { + vpn_gateway_id = "${volcengine_vpn_gateway.foo.id}" + destination_cidr_block = "192.168.0.0/20" + next_hop_id = "${volcengine_vpn_connection.foo.id}" +} + +data "volcengine_vpn_gateway_routes" "foo"{ + ids = ["${volcengine_vpn_gateway_route.foo.id}"] +} +` + +func TestAccVolcengineVpnGatewayRoutesDatasource_Basic(t *testing.T) { + resourceName := "data.volcengine_vpn_gateway_routes.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &vpn_gateway_route.VolcengineVpnGatewayRouteService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineVpnGatewayRoutesDatasourceConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(acc.ResourceId, "vpn_gateway_routes.#", "1"), + ), + }, + }, + }) +} diff --git a/volcengine/vpn/vpn_gateway_route/resource_volcengine_vpn_gateway_route_test.go b/volcengine/vpn/vpn_gateway_route/resource_volcengine_vpn_gateway_route_test.go new file mode 100644 index 00000000..b4586ec2 --- /dev/null +++ b/volcengine/vpn/vpn_gateway_route/resource_volcengine_vpn_gateway_route_test.go @@ -0,0 +1,204 @@ +package vpn_gateway_route_test + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/vpn/vpn_gateway_route" + "testing" +) + +const testAccVolcengineVpnGatewayRouteCreateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_vpn_gateway" "foo" { + vpc_id = "${volcengine_vpc.foo.id}" + subnet_id = "${volcengine_subnet.foo.id}" + bandwidth = 20 + vpn_gateway_name = "acc-test" + description = "acc-test" + period = 2 + project_name = "default" +} + +resource "volcengine_customer_gateway" "foo" { + ip_address = "192.0.1.3" + customer_gateway_name = "acc-test" + description = "acc-test" + project_name = "default" +} + +resource "volcengine_vpn_connection" "foo" { + vpn_connection_name = "acc-tf-test" + description = "acc-tf-test" + vpn_gateway_id = "${volcengine_vpn_gateway.foo.id}" + customer_gateway_id = "${volcengine_customer_gateway.foo.id}" + local_subnet = ["192.168.0.0/22"] + remote_subnet = ["192.161.0.0/20"] + dpd_action = "none" + nat_traversal = true + ike_config_psk = "acctest@!3" + ike_config_version = "ikev1" + ike_config_mode = "main" + ike_config_enc_alg = "aes" + ike_config_auth_alg = "md5" + ike_config_dh_group = "group2" + ike_config_lifetime = 9000 + ike_config_local_id = "acc_test" + ike_config_remote_id = "acc_test" + ipsec_config_enc_alg = "aes" + ipsec_config_auth_alg = "sha256" + ipsec_config_dh_group = "group2" + ipsec_config_lifetime = 9000 + project_name = "default" + log_enabled = false +} + +resource "volcengine_vpn_gateway_route" "foo" { + vpn_gateway_id = "${volcengine_vpn_gateway.foo.id}" + destination_cidr_block = "192.168.0.0/20" + next_hop_id = "${volcengine_vpn_connection.foo.id}" +} + +` + +const testAccVolcengineVpnGatewayRouteUpdateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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}" +} + +resource "volcengine_vpn_gateway" "foo" { + vpc_id = "${volcengine_vpc.foo.id}" + subnet_id = "${volcengine_subnet.foo.id}" + bandwidth = 20 + vpn_gateway_name = "acc-test" + description = "acc-test" + period = 2 + project_name = "default" +} + +resource "volcengine_customer_gateway" "foo" { + ip_address = "192.0.1.3" + customer_gateway_name = "acc-test" + description = "acc-test" + project_name = "default" +} + +resource "volcengine_vpn_connection" "foo" { + vpn_connection_name = "acc-tf-test" + description = "acc-tf-test" + vpn_gateway_id = "${volcengine_vpn_gateway.foo.id}" + customer_gateway_id = "${volcengine_customer_gateway.foo.id}" + local_subnet = ["192.168.0.0/22"] + remote_subnet = ["192.161.0.0/20"] + dpd_action = "none" + nat_traversal = true + ike_config_psk = "acctest@!3" + ike_config_version = "ikev1" + ike_config_mode = "main" + ike_config_enc_alg = "aes" + ike_config_auth_alg = "md5" + ike_config_dh_group = "group2" + ike_config_lifetime = 9000 + ike_config_local_id = "acc_test" + ike_config_remote_id = "acc_test" + ipsec_config_enc_alg = "aes" + ipsec_config_auth_alg = "sha256" + ipsec_config_dh_group = "group2" + ipsec_config_lifetime = 9000 + project_name = "default" + log_enabled = false +} + +resource "volcengine_vpn_gateway_route" "foo" { + vpn_gateway_id = "${volcengine_vpn_gateway.foo.id}" + destination_cidr_block = "192.168.0.0/20" + next_hop_id = "${volcengine_vpn_connection.foo.id}" +} + +` + +func TestAccVolcengineVpnGatewayRouteResource_Basic(t *testing.T) { + resourceName := "volcengine_vpn_gateway_route.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &vpn_gateway_route.VolcengineVpnGatewayRouteService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineVpnGatewayRouteCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "destination_cidr_block", "192.168.0.0/20"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccVolcengineVpnGatewayRouteResource_Update(t *testing.T) { + resourceName := "volcengine_vpn_gateway_route.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + Svc: &vpn_gateway_route.VolcengineVpnGatewayRouteService{}, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineVpnGatewayRouteCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "destination_cidr_block", "192.168.0.0/20"), + ), + }, + { + Config: testAccVolcengineVpnGatewayRouteUpdateConfig, + PlanOnly: true, + ExpectNonEmptyPlan: false, // 修改之后,不应该再产生diff + }, + }, + }) +} diff --git a/website/docs/d/customer_gateways.html.markdown b/website/docs/d/customer_gateways.html.markdown index 01ea11c1..e5a7ba3b 100644 --- a/website/docs/d/customer_gateways.html.markdown +++ b/website/docs/d/customer_gateways.html.markdown @@ -10,8 +10,14 @@ description: |- Use this data source to query detailed information of customer gateways ## Example Usage ```hcl +resource "volcengine_customer_gateway" "foo" { + ip_address = "192.0.1.3" + customer_gateway_name = "acc-test" + description = "acc-test" + project_name = "default" +} data "volcengine_customer_gateways" "foo" { - ids = ["cgw-2d68c4zglycjk58ozfe96norh"] + ids = [volcengine_customer_gateway.foo.id] } ``` ## Argument Reference diff --git a/website/docs/d/dnat_entries.html.markdown b/website/docs/d/dnat_entries.html.markdown index 54dbfd60..9f6caa1f 100644 --- a/website/docs/d/dnat_entries.html.markdown +++ b/website/docs/d/dnat_entries.html.markdown @@ -10,7 +10,62 @@ description: |- Use this data source to query detailed information of dnat entries ## Example Usage ```hcl -data "volcengine_dnat_entries" "default" { +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_nat_gateway" "foo" { + vpc_id = volcengine_vpc.foo.id + subnet_id = volcengine_subnet.foo.id + spec = "Small" + nat_gateway_name = "acc-test-ng" + description = "acc-test" + billing_type = "PostPaid" + project_name = "default" + tags { + key = "k1" + value = "v1" + } +} + +resource "volcengine_eip_address" "foo" { + name = "acc-test-eip" + description = "acc-test" + bandwidth = 1 + billing_type = "PostPaidByBandwidth" + isp = "BGP" +} + +resource "volcengine_eip_associate" "foo" { + allocation_id = volcengine_eip_address.foo.id + instance_id = volcengine_nat_gateway.foo.id + instance_type = "Nat" +} + +resource "volcengine_dnat_entry" "foo" { + dnat_entry_name = "acc-test-dnat-entry" + external_ip = volcengine_eip_address.foo.eip_address + external_port = 80 + internal_ip = "172.16.0.10" + internal_port = 80 + nat_gateway_id = volcengine_nat_gateway.foo.id + protocol = "tcp" + depends_on = [volcengine_eip_associate.foo] +} + +data "volcengine_dnat_entries" "foo" { + ids = [volcengine_dnat_entry.foo.id] } ``` ## Argument Reference diff --git a/website/docs/d/nat_gateways.html.markdown b/website/docs/d/nat_gateways.html.markdown index 9c0edb6c..fb539d55 100644 --- a/website/docs/d/nat_gateways.html.markdown +++ b/website/docs/d/nat_gateways.html.markdown @@ -10,8 +10,38 @@ description: |- Use this data source to query detailed information of nat gateways ## Example Usage ```hcl -data "volcengine_nat_gateways" "default" { - ids = ["ngw-2743w1f6iqby87fap8tvm9kop", "ngw-274gwbqe340zk7fap8spkzo7x"] +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_nat_gateway" "foo" { + vpc_id = volcengine_vpc.foo.id + subnet_id = volcengine_subnet.foo.id + spec = "Small" + nat_gateway_name = "acc-test-ng-${count.index}" + description = "acc-test" + billing_type = "PostPaid" + project_name = "default" + tags { + key = "k1" + value = "v1" + } + count = 3 +} + +data "volcengine_nat_gateways" "foo" { + ids = volcengine_nat_gateway.foo[*].id } ``` ## Argument Reference diff --git a/website/docs/d/scaling_activities.html.markdown b/website/docs/d/scaling_activities.html.markdown index bbe0044e..89d9157e 100644 --- a/website/docs/d/scaling_activities.html.markdown +++ b/website/docs/d/scaling_activities.html.markdown @@ -10,8 +10,109 @@ description: |- Use this data source to query detailed information of scaling activities ## Example Usage ```hcl -data "volcengine_scaling_activities" "default" { - scaling_group_id = "scg-ybqm0b6kcigh9zu9ce6t" +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = volcengine_vpc.foo.id +} + + +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_ecs_key_pair" "foo" { + description = "acc-test-2" + key_pair_name = "acc-test-key-pair-name" +} + +resource "volcengine_ecs_launch_template" "foo" { + description = "acc-test-desc" + eip_bandwidth = 200 + eip_billing_type = "PostPaidByBandwidth" + eip_isp = "BGP" + host_name = "acc-hostname" + image_id = data.volcengine_images.foo.images[0].image_id + instance_charge_type = "PostPaid" + instance_name = "acc-instance-name" + instance_type_id = "ecs.g1.large" + key_pair_name = volcengine_ecs_key_pair.foo.key_pair_name + launch_template_name = "acc-test-template" + network_interfaces { + subnet_id = volcengine_subnet.foo.id + security_group_ids = [volcengine_security_group.foo.id] + } + volumes { + volume_type = "ESSD_PL0" + size = 50 + delete_with_instance = true + } +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + subnet_ids = [volcengine_subnet.foo.id] + multi_az_policy = "BALANCE" + desire_instance_number = -1 + min_instance_number = 0 + max_instance_number = 10 + instance_terminate_policy = "OldestInstance" + default_cooldown = 10 + launch_template_id = volcengine_ecs_launch_template.foo.id + launch_template_version = "Default" +} + +resource "volcengine_scaling_group_enabler" "foo" { + scaling_group_id = volcengine_scaling_group.foo.id +} + +resource "volcengine_ecs_instance" "foo" { + count = 3 + instance_name = "acc-test-ecs-${count.index}" + description = "acc-test" + host_name = "tf-acc-test" + image_id = data.volcengine_images.foo.images[0].image_id + instance_type = "ecs.g1.large" + password = "93f0cb0614Aab12" + instance_charge_type = "PostPaid" + system_volume_type = "ESSD_PL0" + system_volume_size = 40 + subnet_id = volcengine_subnet.foo.id + security_group_ids = [volcengine_security_group.foo.id] +} + +resource "volcengine_scaling_instance_attachment" "foo" { + count = length(volcengine_ecs_instance.foo) + instance_id = volcengine_ecs_instance.foo[count.index].id + scaling_group_id = volcengine_scaling_group.foo.id + entrusted = true + + depends_on = [ + volcengine_scaling_group_enabler.foo + ] +} + +data "volcengine_scaling_activities" "foo" { + scaling_group_id = volcengine_scaling_group.foo.id + depends_on = [ + volcengine_scaling_instance_attachment.foo + ] } ``` ## Argument Reference diff --git a/website/docs/d/scaling_configurations.html.markdown b/website/docs/d/scaling_configurations.html.markdown index b06c9438..01d5595e 100644 --- a/website/docs/d/scaling_configurations.html.markdown +++ b/website/docs/d/scaling_configurations.html.markdown @@ -10,8 +10,61 @@ description: |- Use this data source to query detailed information of scaling configurations ## Example Usage ```hcl -data "volcengine_scaling_configurations" "default" { - ids = ["scc-ybrurj4uw6gh9zecj327"] +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = volcengine_vpc.foo.id +} + +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + 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 +} + +resource "volcengine_scaling_configuration" "foo" { + count = 3 + image_id = data.volcengine_images.foo.images[0].image_id + instance_name = "acc-test-instance" + instance_types = ["ecs.g1.large"] + password = "93f0cb0614Aab12" + scaling_configuration_name = "acc-test-scaling-config-${count.index}" + scaling_group_id = volcengine_scaling_group.foo.id + security_group_ids = [volcengine_security_group.foo.id] + volumes { + volume_type = "ESSD_PL0" + size = 50 + delete_with_instance = true + } +} + +data "volcengine_scaling_configurations" "foo" { + ids = volcengine_scaling_configuration.foo[*].id } ``` ## Argument Reference diff --git a/website/docs/d/scaling_groups.html.markdown b/website/docs/d/scaling_groups.html.markdown index 4b0b11fa..222fc2db 100644 --- a/website/docs/d/scaling_groups.html.markdown +++ b/website/docs/d/scaling_groups.html.markdown @@ -10,8 +10,45 @@ description: |- Use this data source to query detailed information of scaling groups ## Example Usage ```hcl +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_scaling_group" "foo" { + count = 3 + scaling_group_name = "acc-test-scaling-group-${count.index}" + subnet_ids = [volcengine_subnet.foo.id] + multi_az_policy = "BALANCE" + desire_instance_number = 0 + min_instance_number = 0 + max_instance_number = 10 + instance_terminate_policy = "OldestInstance" + default_cooldown = 30 + + tags { + key = "k2" + value = "v2" + } + + tags { + key = "k1" + value = "v1" + } +} + data "volcengine_scaling_groups" "default" { - ids = ["scg-ybru8pazhgl8j1di4tyd"] + ids = volcengine_scaling_group.foo[*].id } ``` ## Argument Reference diff --git a/website/docs/d/scaling_instances.html.markdown b/website/docs/d/scaling_instances.html.markdown index d3d2e722..b9b75276 100644 --- a/website/docs/d/scaling_instances.html.markdown +++ b/website/docs/d/scaling_instances.html.markdown @@ -10,11 +10,107 @@ description: |- Use this data source to query detailed information of scaling instances ## Example Usage ```hcl -data "volcengine_scaling_instances" "default" { - scaling_group_id = "scg-ybtawtznszgh9yv8agcp" - ids = ["i-ybzl4u5uogl8j07hgcbg", "i-ybyncrcpzpgh9zmlct0w", "i-ybyncrcpzogh9z4ax9tv"] - scaling_configuration_id = "scc-ybtawzucw95pkgon0wst" - status = "InService" +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = volcengine_vpc.foo.id +} + + +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_ecs_key_pair" "foo" { + description = "acc-test-2" + key_pair_name = "acc-test-key-pair-name" +} + +resource "volcengine_ecs_launch_template" "foo" { + description = "acc-test-desc" + eip_bandwidth = 200 + eip_billing_type = "PostPaidByBandwidth" + eip_isp = "BGP" + host_name = "acc-hostname" + image_id = data.volcengine_images.foo.images[0].image_id + instance_charge_type = "PostPaid" + instance_name = "acc-instance-name" + instance_type_id = "ecs.g1.large" + key_pair_name = volcengine_ecs_key_pair.foo.key_pair_name + launch_template_name = "acc-test-template" + network_interfaces { + subnet_id = volcengine_subnet.foo.id + security_group_ids = [volcengine_security_group.foo.id] + } + volumes { + volume_type = "ESSD_PL0" + size = 50 + delete_with_instance = true + } +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + subnet_ids = [volcengine_subnet.foo.id] + multi_az_policy = "BALANCE" + desire_instance_number = -1 + min_instance_number = 0 + max_instance_number = 10 + instance_terminate_policy = "OldestInstance" + default_cooldown = 10 + launch_template_id = volcengine_ecs_launch_template.foo.id + launch_template_version = "Default" +} + +resource "volcengine_scaling_group_enabler" "foo" { + scaling_group_id = volcengine_scaling_group.foo.id +} + +resource "volcengine_ecs_instance" "foo" { + count = 3 + instance_name = "acc-test-ecs-${count.index}" + description = "acc-test" + host_name = "tf-acc-test" + image_id = data.volcengine_images.foo.images[0].image_id + instance_type = "ecs.g1.large" + password = "93f0cb0614Aab12" + instance_charge_type = "PostPaid" + system_volume_type = "ESSD_PL0" + system_volume_size = 40 + subnet_id = volcengine_subnet.foo.id + security_group_ids = [volcengine_security_group.foo.id] +} + +resource "volcengine_scaling_instance_attachment" "foo" { + count = length(volcengine_ecs_instance.foo) + instance_id = volcengine_ecs_instance.foo[count.index].id + scaling_group_id = volcengine_scaling_group.foo.id + entrusted = true + + depends_on = [ + volcengine_scaling_group_enabler.foo + ] +} + +data "volcengine_scaling_instances" "foo" { + scaling_group_id = volcengine_scaling_group.foo.id + ids = volcengine_scaling_instance_attachment.foo[*].instance_id } ``` ## Argument Reference diff --git a/website/docs/d/scaling_lifecycle_hooks.html.markdown b/website/docs/d/scaling_lifecycle_hooks.html.markdown index 0799dc40..fa61bf4d 100644 --- a/website/docs/d/scaling_lifecycle_hooks.html.markdown +++ b/website/docs/d/scaling_lifecycle_hooks.html.markdown @@ -10,8 +10,44 @@ description: |- Use this data source to query detailed information of scaling lifecycle hooks ## Example Usage ```hcl -data "volcengine_scaling_lifecycle_hooks" "default" { - scaling_group_id = "scg-ybru8pazhgl8j1di4tyd" +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +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 + instance_terminate_policy = "OldestInstance" + default_cooldown = 10 +} + +resource "volcengine_scaling_lifecycle_hook" "foo" { + count = 3 + lifecycle_hook_name = "acc-test-lifecycle-${count.index}" + lifecycle_hook_policy = "CONTINUE" + lifecycle_hook_timeout = 30 + lifecycle_hook_type = "SCALE_IN" + scaling_group_id = volcengine_scaling_group.foo.id +} + +data "volcengine_scaling_lifecycle_hooks" "foo" { + ids = volcengine_scaling_lifecycle_hook.foo[*].lifecycle_hook_id + scaling_group_id = volcengine_scaling_group.foo.id } ``` ## Argument Reference diff --git a/website/docs/d/scaling_policies.html.markdown b/website/docs/d/scaling_policies.html.markdown index da20b7a2..ae78ce6b 100644 --- a/website/docs/d/scaling_policies.html.markdown +++ b/website/docs/d/scaling_policies.html.markdown @@ -10,9 +10,52 @@ description: |- Use this data source to query detailed information of scaling policies ## Example Usage ```hcl -data "volcengine_scaling_policies" "default" { - scaling_group_id = "scg-ybqm0b6kcigh9zu9ce6t" - ids = ["sp-ybruzckr8bgh9zrxw29v"] +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + 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 +} + +resource "volcengine_scaling_policy" "foo" { + count = 3 + active = false + scaling_group_id = volcengine_scaling_group.foo.id + scaling_policy_name = "acc-tf-sg-policy-test-${count.index}" + scaling_policy_type = "Alarm" + adjustment_type = "QuantityChangeInCapacity" + adjustment_value = 100 + cooldown = 10 + alarm_policy_rule_type = "Static" + alarm_policy_evaluation_count = 1 + alarm_policy_condition_metric_name = "Instance_CpuBusy_Avg" + alarm_policy_condition_metric_unit = "Percent" + alarm_policy_condition_comparison_operator = "=" + alarm_policy_condition_threshold = 100 +} + +data "volcengine_scaling_policies" "foo" { + ids = volcengine_scaling_policy.foo[*].scaling_policy_id + scaling_group_id = volcengine_scaling_group.foo.id } ``` ## Argument Reference diff --git a/website/docs/d/snat_entries.html.markdown b/website/docs/d/snat_entries.html.markdown index 6f21c941..288addb1 100644 --- a/website/docs/d/snat_entries.html.markdown +++ b/website/docs/d/snat_entries.html.markdown @@ -10,8 +10,67 @@ description: |- Use this data source to query detailed information of snat entries ## Example Usage ```hcl -data "volcengine_snat_entries" "default" { - ids = ["snat-274zl8b1kxzb47fap8u35uune"] +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_nat_gateway" "foo" { + vpc_id = volcengine_vpc.foo.id + subnet_id = volcengine_subnet.foo.id + spec = "Small" + nat_gateway_name = "acc-test-ng" + description = "acc-test" + billing_type = "PostPaid" + project_name = "default" + tags { + key = "k1" + value = "v1" + } +} + +resource "volcengine_eip_address" "foo" { + name = "acc-test-eip" + description = "acc-test" + bandwidth = 1 + billing_type = "PostPaidByBandwidth" + isp = "BGP" +} + +resource "volcengine_eip_associate" "foo" { + allocation_id = volcengine_eip_address.foo.id + instance_id = volcengine_nat_gateway.foo.id + instance_type = "Nat" +} + +resource "volcengine_snat_entry" "foo1" { + snat_entry_name = "acc-test-snat-entry" + nat_gateway_id = volcengine_nat_gateway.foo.id + eip_id = volcengine_eip_address.foo.id + source_cidr = "172.16.0.0/24" + depends_on = ["volcengine_eip_associate.foo"] +} + +resource "volcengine_snat_entry" "foo2" { + snat_entry_name = "acc-test-snat-entry" + nat_gateway_id = volcengine_nat_gateway.foo.id + eip_id = volcengine_eip_address.foo.id + source_cidr = "172.16.0.0/16" + depends_on = ["volcengine_eip_associate.foo"] +} + +data "volcengine_snat_entries" "foo" { + ids = [volcengine_snat_entry.foo1.id, volcengine_snat_entry.foo2.id] } ``` ## Argument Reference diff --git a/website/docs/d/volumes.html.markdown b/website/docs/d/volumes.html.markdown index c9fd444f..f4c5ee71 100644 --- a/website/docs/d/volumes.html.markdown +++ b/website/docs/d/volumes.html.markdown @@ -10,8 +10,23 @@ description: |- Use this data source to query detailed information of volumes ## Example Usage ```hcl -data "volcengine_volumes" "default" { - ids = ["vol-3tzg6y5imn3b9fchkedb"] +data "volcengine_zones" "foo" { +} + +resource "volcengine_volume" "foo" { + volume_name = "acc-test-volume-${count.index}" + volume_type = "ESSD_PL0" + description = "acc-test" + kind = "data" + size = 60 + zone_id = data.volcengine_zones.foo.zones[0].id + volume_charge_type = "PostPaid" + project_name = "default" + count = 3 +} + +data "volcengine_volumes" "foo" { + ids = volcengine_volume.foo[*].id } ``` ## Argument Reference diff --git a/website/docs/d/vpn_connections.html.markdown b/website/docs/d/vpn_connections.html.markdown index de7e38f8..2f7f2d56 100644 --- a/website/docs/d/vpn_connections.html.markdown +++ b/website/docs/d/vpn_connections.html.markdown @@ -10,8 +10,62 @@ description: |- Use this data source to query detailed information of vpn connections ## Example Usage ```hcl -data "volcengine_vpn_connections" "default" { - ids = ["vgc-2d5wwids8cdts58ozfe63k2uq"] +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-test-subnet" + cidr_block = "172.16.0.0/24" + zone_id = "cn-beijing-a" + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_vpn_gateway" "foo" { + vpc_id = volcengine_vpc.foo.id + subnet_id = volcengine_subnet.foo.id + bandwidth = 20 + vpn_gateway_name = "acc-test" + description = "acc-test" + period = 2 + project_name = "default" +} + +resource "volcengine_customer_gateway" "foo" { + ip_address = "192.0.1.3" + customer_gateway_name = "acc-test" + description = "acc-test" + project_name = "default" +} + +resource "volcengine_vpn_connection" "foo" { + vpn_connection_name = "acc-tf-test" + description = "acc-tf-test" + vpn_gateway_id = volcengine_vpn_gateway.foo.id + customer_gateway_id = volcengine_customer_gateway.foo.id + local_subnet = ["192.168.0.0/22"] + remote_subnet = ["192.161.0.0/20"] + dpd_action = "none" + nat_traversal = true + ike_config_psk = "acctest@!3" + ike_config_version = "ikev1" + ike_config_mode = "main" + ike_config_enc_alg = "aes" + ike_config_auth_alg = "md5" + ike_config_dh_group = "group2" + ike_config_lifetime = 9000 + ike_config_local_id = "acc_test" + ike_config_remote_id = "acc_test" + ipsec_config_enc_alg = "aes" + ipsec_config_auth_alg = "sha256" + ipsec_config_dh_group = "group2" + ipsec_config_lifetime = 9000 + project_name = "default" +} + +data "volcengine_vpn_connections" "foo" { + ids = [volcengine_vpn_connection.foo.id] } ``` ## Argument Reference diff --git a/website/docs/d/vpn_gateway_routes.html.markdown b/website/docs/d/vpn_gateway_routes.html.markdown index 6a733727..a13e77e1 100644 --- a/website/docs/d/vpn_gateway_routes.html.markdown +++ b/website/docs/d/vpn_gateway_routes.html.markdown @@ -10,8 +10,69 @@ description: |- Use this data source to query detailed information of vpn gateway routes ## Example Usage ```hcl -data "volcengine_vpn_gateway_routes" "default" { - ids = ["vgr-2byssu52dktts2dx0ee90r5hp]"] +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-test-subnet" + cidr_block = "172.16.0.0/24" + zone_id = "cn-beijig-a" + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_vpn_gateway" "foo" { + vpc_id = volcengine_vpc.foo.id + subnet_id = volcengine_subnet.foo.id + bandwidth = 20 + vpn_gateway_name = "acc-test" + description = "acc-test" + period = 2 + project_name = "default" +} + +resource "volcengine_customer_gateway" "foo" { + ip_address = "192.0.1.3" + customer_gateway_name = "acc-test" + description = "acc-test" + project_name = "default" +} + +resource "volcengine_vpn_connection" "foo" { + vpn_connection_name = "acc-tf-test" + description = "acc-tf-test" + vpn_gateway_id = volcengine_vpn_gateway.foo.id + customer_gateway_id = volcengine_customer_gateway.foo.id + local_subnet = ["192.168.0.0/22"] + remote_subnet = ["192.161.0.0/20"] + dpd_action = "none" + nat_traversal = true + ike_config_psk = "acctest@!3" + ike_config_version = "ikev1" + ike_config_mode = "main" + ike_config_enc_alg = "aes" + ike_config_auth_alg = "md5" + ike_config_dh_group = "group2" + ike_config_lifetime = 9000 + ike_config_local_id = "acc_test" + ike_config_remote_id = "acc_test" + ipsec_config_enc_alg = "aes" + ipsec_config_auth_alg = "sha256" + ipsec_config_dh_group = "group2" + ipsec_config_lifetime = 9000 + project_name = "default" + log_enabled = false +} + +resource "volcengine_vpn_gateway_route" "foo" { + vpn_gateway_id = volcengine_vpn_gateway.foo.id + destination_cidr_block = "192.168.0.0/20" + next_hop_id = volcengine_vpn_connection.foo.id +} + +data "volcengine_vpn_gateway_routes" "foo" { + ids = [volcengine_vpn_gateway_route.foo.id] } ``` ## Argument Reference diff --git a/website/docs/d/vpn_gateways.html.markdown b/website/docs/d/vpn_gateways.html.markdown index fa60f3d9..babb7f24 100644 --- a/website/docs/d/vpn_gateways.html.markdown +++ b/website/docs/d/vpn_gateways.html.markdown @@ -10,8 +10,30 @@ description: |- Use this data source to query detailed information of vpn gateways ## Example Usage ```hcl -data "volcengine_vpn_gateways" "default" { - ids = ["vgw-2c012ea9fm5mo2dx0efxg46qi"] +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-test-subnet" + cidr_block = "172.16.0.0/24" + zone_id = "cn-beijing-a" + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_vpn_gateway" "foo" { + vpc_id = volcengine_vpc.foo.id + subnet_id = volcengine_subnet.foo.id + bandwidth = 20 + vpn_gateway_name = "acc-test" + description = "acc-test" + period = 2 + project_name = "default" +} + +data "volcengine_vpn_gateways" "foo" { + ids = [volcengine_vpn_gateway.foo.id] } ``` ## Argument Reference diff --git a/website/docs/r/customer_gateway.html.markdown b/website/docs/r/customer_gateway.html.markdown index e35a2645..00dfb813 100644 --- a/website/docs/r/customer_gateway.html.markdown +++ b/website/docs/r/customer_gateway.html.markdown @@ -12,8 +12,8 @@ Provides a resource to manage customer gateway ```hcl resource "volcengine_customer_gateway" "foo" { ip_address = "192.0.1.3" - customer_gateway_name = "tf-test" - description = "tf-test" + customer_gateway_name = "acc-test" + description = "acc-test" project_name = "default" } ``` diff --git a/website/docs/r/dnat_entry.html.markdown b/website/docs/r/dnat_entry.html.markdown index df5f5a6a..2fb50c5f 100644 --- a/website/docs/r/dnat_entry.html.markdown +++ b/website/docs/r/dnat_entry.html.markdown @@ -10,14 +10,58 @@ description: |- Provides a resource to manage dnat entry ## Example Usage ```hcl +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_nat_gateway" "foo" { + vpc_id = volcengine_vpc.foo.id + subnet_id = volcengine_subnet.foo.id + spec = "Small" + nat_gateway_name = "acc-test-ng" + description = "acc-test" + billing_type = "PostPaid" + project_name = "default" + tags { + key = "k1" + value = "v1" + } +} + +resource "volcengine_eip_address" "foo" { + name = "acc-test-eip" + description = "acc-test" + bandwidth = 1 + billing_type = "PostPaidByBandwidth" + isp = "BGP" +} + +resource "volcengine_eip_associate" "foo" { + allocation_id = volcengine_eip_address.foo.id + instance_id = volcengine_nat_gateway.foo.id + instance_type = "Nat" +} + resource "volcengine_dnat_entry" "foo" { - nat_gateway_id = "ngw-imw3aej7e96o8gbssxkfbybv" - external_ip = "10.249.186.68" - external_port = "23" - internal_ip = "193.168.1.1" - internal_port = "24" + dnat_entry_name = "acc-test-dnat-entry" + external_ip = volcengine_eip_address.foo.eip_address + external_port = 80 + internal_ip = "172.16.0.10" + internal_port = 80 + nat_gateway_id = volcengine_nat_gateway.foo.id protocol = "tcp" - dnat_entry_name = "terraform-test2" + depends_on = [volcengine_eip_associate.foo] } ``` ## Argument Reference diff --git a/website/docs/r/nat_gateway.html.markdown b/website/docs/r/nat_gateway.html.markdown index 425db2fc..c87f12fb 100644 --- a/website/docs/r/nat_gateway.html.markdown +++ b/website/docs/r/nat_gateway.html.markdown @@ -14,14 +14,33 @@ in [Volcengine Console](https://console.volcengine.com/finance/unsubscribe/),wh use 'terraform state rm ${resourceId}' to remove. ## Example Usage ```hcl +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + resource "volcengine_nat_gateway" "foo" { - vpc_id = "vpc-im67wjcikxkw8gbssx8ufpj8" - subnet_id = "subnet-im67x70vxla88gbssz1hy1z2" - spec = "Medium" - nat_gateway_name = "tf-auto-demo-1" + vpc_id = volcengine_vpc.foo.id + subnet_id = volcengine_subnet.foo.id + spec = "Small" + nat_gateway_name = "acc-test-ng" + description = "acc-test" billing_type = "PostPaid" - description = "This nat gateway auto-created by terraform. " project_name = "default" + tags { + key = "k1" + value = "v1" + } } ``` ## Argument Reference diff --git a/website/docs/r/scaling_configuration.html.markdown b/website/docs/r/scaling_configuration.html.markdown index 7a6ae524..8025ac1a 100644 --- a/website/docs/r/scaling_configuration.html.markdown +++ b/website/docs/r/scaling_configuration.html.markdown @@ -14,10 +14,47 @@ in [Volcengine Console](https://console.volcengine.com/finance/unsubscribe/),wh use 'terraform state rm ${resourceId}' to remove. ## Example Usage ```hcl +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = volcengine_vpc.foo.id +} + +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + 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 +} + resource "volcengine_scaling_configuration" "foo" { scaling_configuration_name = "tf-test" - scaling_group_id = "scg-ycinx27x25gh9y31p0fy" - image_id = "image-ycgud4t4hxgso0e27bdl" + scaling_group_id = volcengine_scaling_group.foo.id + image_id = data.volcengine_images.foo.images[0].image_id instance_types = ["ecs.g2i.large"] instance_name = "tf-test" instance_description = "" @@ -32,10 +69,10 @@ resource "volcengine_scaling_configuration" "foo" { } volumes { volume_type = "ESSD_PL0" - size = 20 + size = 50 delete_with_instance = true } - security_group_ids = ["sg-2fepz3c793g1s59gp67y21r34"] + security_group_ids = [volcengine_security_group.foo.id] eip_bandwidth = 10 eip_isp = "ChinaMobile" eip_billing_type = "PostPaidByBandwidth" diff --git a/website/docs/r/scaling_configuration_attachment.html.markdown b/website/docs/r/scaling_configuration_attachment.html.markdown index 180b48f9..722e8e73 100644 --- a/website/docs/r/scaling_configuration_attachment.html.markdown +++ b/website/docs/r/scaling_configuration_attachment.html.markdown @@ -10,8 +10,60 @@ description: |- Provides a resource to manage scaling configuration attachment ## Example Usage ```hcl -resource "volcengine_scaling_configuration_attachment" "foo1" { - scaling_configuration_id = "scc-ybrurj4uw6gh9zecj327" +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = volcengine_vpc.foo.id +} + +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + 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 +} + +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"] + password = "93f0cb0614Aab12" + scaling_configuration_name = "acc-test-scaling-config" + scaling_group_id = volcengine_scaling_group.foo.id + security_group_ids = [volcengine_security_group.foo.id] + volumes { + volume_type = "ESSD_PL0" + size = 50 + delete_with_instance = true + } +} + +resource "volcengine_scaling_configuration_attachment" "foo" { + scaling_configuration_id = volcengine_scaling_configuration.foo.id } ``` ## Argument Reference diff --git a/website/docs/r/scaling_group.html.markdown b/website/docs/r/scaling_group.html.markdown index b2a04a65..3c0b1799 100644 --- a/website/docs/r/scaling_group.html.markdown +++ b/website/docs/r/scaling_group.html.markdown @@ -10,19 +10,40 @@ description: |- Provides a resource to manage scaling group ## Example Usage ```hcl +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + resource "volcengine_scaling_group" "foo" { - scaling_group_name = "test-tf" - subnet_ids = ["subnet-2fe79j7c8o5c059gp68ksxr93"] + count = 3 + scaling_group_name = "acc-test-scaling-group-${count.index}" + subnet_ids = [volcengine_subnet.foo.id] multi_az_policy = "BALANCE" desire_instance_number = 0 min_instance_number = 0 - max_instance_number = 1 + max_instance_number = 10 instance_terminate_policy = "OldestInstance" - default_cooldown = 10 - project_name = "default" + default_cooldown = 30 + + tags { + key = "k2" + value = "v2" + } + tags { - key = "tf-key1" - value = "tf-value1" + key = "k1" + value = "v1" } } ``` diff --git a/website/docs/r/scaling_instance_attachment.html.markdown b/website/docs/r/scaling_instance_attachment.html.markdown index 35158ca6..89941091 100644 --- a/website/docs/r/scaling_instance_attachment.html.markdown +++ b/website/docs/r/scaling_instance_attachment.html.markdown @@ -10,12 +10,100 @@ description: |- Provides a resource to manage scaling instance attachment ## Example Usage ```hcl +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = volcengine_vpc.foo.id +} + + +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_ecs_key_pair" "foo" { + description = "acc-test-2" + key_pair_name = "acc-test-key-pair-name" +} + +resource "volcengine_ecs_launch_template" "foo" { + description = "acc-test-desc" + eip_bandwidth = 200 + eip_billing_type = "PostPaidByBandwidth" + eip_isp = "BGP" + host_name = "acc-hostname" + image_id = data.volcengine_images.foo.images[0].image_id + instance_charge_type = "PostPaid" + instance_name = "acc-instance-name" + instance_type_id = "ecs.g1.large" + key_pair_name = volcengine_ecs_key_pair.foo.key_pair_name + launch_template_name = "acc-test-template" + network_interfaces { + subnet_id = volcengine_subnet.foo.id + security_group_ids = [volcengine_security_group.foo.id] + } + volumes { + volume_type = "ESSD_PL0" + size = 50 + delete_with_instance = true + } +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + subnet_ids = [volcengine_subnet.foo.id] + multi_az_policy = "BALANCE" + desire_instance_number = -1 + min_instance_number = 0 + max_instance_number = 1 + instance_terminate_policy = "OldestInstance" + default_cooldown = 10 + launch_template_id = volcengine_ecs_launch_template.foo.id + launch_template_version = "Default" +} + +resource "volcengine_scaling_group_enabler" "foo" { + scaling_group_id = volcengine_scaling_group.foo.id +} + +resource "volcengine_ecs_instance" "foo" { + instance_name = "acc-test-ecs" + description = "acc-test" + host_name = "tf-acc-test" + image_id = data.volcengine_images.foo.images[0].image_id + instance_type = "ecs.g1.large" + password = "93f0cb0614Aab12" + instance_charge_type = "PostPaid" + system_volume_type = "ESSD_PL0" + system_volume_size = 40 + subnet_id = volcengine_subnet.foo.id + security_group_ids = [volcengine_security_group.foo.id] +} + resource "volcengine_scaling_instance_attachment" "foo" { - scaling_group_id = "scg-yc23rtcea88hcchybf8g" - instance_id = "i-yc23soxj50gsnz7rxnjp" - delete_type = "Remove" + instance_id = volcengine_ecs_instance.foo.id + scaling_group_id = volcengine_scaling_group.foo.id entrusted = true - detach_option = "none" + + depends_on = [ + volcengine_scaling_group_enabler.foo + ] } ``` ## Argument Reference @@ -24,7 +112,7 @@ The following arguments are supported: * `scaling_group_id` - (Required, ForceNew) The id of the scaling group. * `delete_type` - (Optional) The type of delete activity. Valid values: Remove, Detach. Default value is Remove. * `detach_option` - (Optional) Whether to cancel the association of the instance with the load balancing and public network IP. Valid values: both, none. Default value is both. -* `entrusted` - (Optional) Whether to host the instance to a scaling group. Default value is false. +* `entrusted` - (Optional, ForceNew) Whether to host the instance to a scaling group. Default value is false. ## Attributes Reference In addition to all arguments above, the following attributes are exported: diff --git a/website/docs/r/scaling_lifecycle_hook.html.markdown b/website/docs/r/scaling_lifecycle_hook.html.markdown index dcf9e905..67a6dfe3 100644 --- a/website/docs/r/scaling_lifecycle_hook.html.markdown +++ b/website/docs/r/scaling_lifecycle_hook.html.markdown @@ -10,12 +10,38 @@ description: |- Provides a resource to manage scaling lifecycle hook ## Example Usage ```hcl +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +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 + instance_terminate_policy = "OldestInstance" + default_cooldown = 10 +} + resource "volcengine_scaling_lifecycle_hook" "foo" { - scaling_group_id = "scg-ybru8pazhgl8j1di4tyd" - lifecycle_hook_name = "tf-test" + lifecycle_hook_name = "acc-test-lifecycle" + lifecycle_hook_policy = "CONTINUE" lifecycle_hook_timeout = 30 lifecycle_hook_type = "SCALE_IN" - lifecycle_hook_policy = "CONTINUE" + scaling_group_id = volcengine_scaling_group.foo.id } ``` ## Argument Reference diff --git a/website/docs/r/scaling_policy.html.markdown b/website/docs/r/scaling_policy.html.markdown index 22c1072d..bb8e8a79 100644 --- a/website/docs/r/scaling_policy.html.markdown +++ b/website/docs/r/scaling_policy.html.markdown @@ -10,18 +10,40 @@ description: |- Provides a resource to manage scaling policy ## Example Usage ```hcl +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_scaling_group" "foo" { + scaling_group_name = "acc-test-scaling-group" + 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 +} + resource "volcengine_scaling_policy" "foo" { active = false - scaling_group_id = "scg-ybqm0b6kcigh9zu9ce6t" - scaling_policy_name = "tf-test" + scaling_group_id = volcengine_scaling_group.foo.id + scaling_policy_name = "acc-tf-sg-policy-test" scaling_policy_type = "Alarm" adjustment_type = "QuantityChangeInCapacity" adjustment_value = 100 cooldown = 10 - scheduled_policy_launch_time = "2022-07-09T09:59Z" - scheduled_policy_recurrence_end_time = "2022-07-24T09:25Z" - scheduled_policy_recurrence_type = "Daily" - scheduled_policy_recurrence_value = 10 alarm_policy_rule_type = "Static" alarm_policy_evaluation_count = 1 alarm_policy_condition_metric_name = "Instance_CpuBusy_Avg" @@ -60,6 +82,7 @@ When the value of the ScheduledPolicy.RecurrenceType parameter is Cron, it means ## Attributes Reference In addition to all arguments above, the following attributes are exported: * `id` - ID of the resource. +* `scaling_policy_id` - The id of the scaling policy. * `status` - The status of the scaling policy. Valid values: Active, InActive. diff --git a/website/docs/r/snat_entry.html.markdown b/website/docs/r/snat_entry.html.markdown index 136e916d..d362eadb 100644 --- a/website/docs/r/snat_entry.html.markdown +++ b/website/docs/r/snat_entry.html.markdown @@ -10,11 +10,55 @@ description: |- Provides a resource to manage snat entry ## Example Usage ```hcl +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_nat_gateway" "foo" { + vpc_id = volcengine_vpc.foo.id + subnet_id = volcengine_subnet.foo.id + spec = "Small" + nat_gateway_name = "acc-test-ng" + description = "acc-test" + billing_type = "PostPaid" + project_name = "default" + tags { + key = "k1" + value = "v1" + } +} + +resource "volcengine_eip_address" "foo" { + name = "acc-test-eip" + description = "acc-test" + bandwidth = 1 + billing_type = "PostPaidByBandwidth" + isp = "BGP" +} + +resource "volcengine_eip_associate" "foo" { + allocation_id = volcengine_eip_address.foo.id + instance_id = volcengine_nat_gateway.foo.id + instance_type = "Nat" +} + resource "volcengine_snat_entry" "foo" { - nat_gateway_id = "ngw-2743w1f6iqby87fap8tvm9kop" - subnet_id = "subnet-2744i7u9alnnk7fap8tkq8aft" - eip_id = "eip-274zlae117nr47fap8tzl24v4" - snat_entry_name = "tf-test-up" + snat_entry_name = "acc-test-snat-entry" + nat_gateway_id = volcengine_nat_gateway.foo.id + eip_id = volcengine_eip_address.foo.id + source_cidr = "172.16.0.0/24" + depends_on = ["volcengine_eip_associate.foo"] } ``` ## Argument Reference diff --git a/website/docs/r/volume.html.markdown b/website/docs/r/volume.html.markdown index a89182d3..bc36a83d 100644 --- a/website/docs/r/volume.html.markdown +++ b/website/docs/r/volume.html.markdown @@ -14,29 +14,74 @@ in [Volcengine Console](https://console.volcengine.com/finance/unsubscribe/),wh use 'terraform state rm ${resourceId}' to remove. ## Example Usage ```hcl -resource "volcengine_volume" "foo" { - volume_name = "terraform-test" - zone_id = "cn-xx-a" - volume_type = "ESSD_PL0" - kind = "data" - size = 40 - volume_charge_type = "PostPaid" - project_name = "default" +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 } -resource "volcengine_volume_attach" "foo" { - volume_id = volcengine_volume.foo.id - instance_id = "i-yc8pfhbafwijutv6s1fv" +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = volcengine_vpc.foo.id } -resource "volcengine_volume" "foo2" { - volume_name = "terraform-test3" - zone_id = "cn-beijing-b" +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_ecs_instance" "foo" { + instance_name = "acc-test-ecs" + description = "acc-test" + host_name = "tf-acc-test" + image_id = data.volcengine_images.foo.images[0].image_id + instance_type = "ecs.g1.large" + password = "93f0cb0614Aab12" + instance_charge_type = "PrePaid" + period = 1 + system_volume_type = "ESSD_PL0" + system_volume_size = 40 + subnet_id = volcengine_subnet.foo.id + security_group_ids = [volcengine_security_group.foo.id] + project_name = "default" + tags { + key = "k1" + value = "v1" + } +} + +resource "volcengine_volume" "PreVolume" { + volume_name = "acc-test-volume" + volume_type = "ESSD_PL0" + description = "acc-test" + kind = "data" + size = 40 + zone_id = data.volcengine_zones.foo.zones[0].id + volume_charge_type = "PrePaid" + instance_id = volcengine_ecs_instance.foo.id + project_name = "default" + delete_with_instance = true +} + +resource "volcengine_volume" "PostVolume" { + volume_name = "acc-test-volume" volume_type = "ESSD_PL0" + description = "acc-test" kind = "data" size = 40 - volume_charge_type = "PrePaid" - instance_id = "i-yc8pfhbafwijutv6s1fv" + zone_id = data.volcengine_zones.foo.zones[0].id + volume_charge_type = "PostPaid" + project_name = "default" } ``` ## Argument Reference @@ -49,6 +94,7 @@ The following arguments are supported: * `delete_with_instance` - (Optional) Delete Volume with Attached Instance. * `description` - (Optional) The description of the Volume. * `instance_id` - (Optional, ForceNew) The ID of the instance to which the created volume is automatically attached. Please note this field needs to ask the system administrator to apply for a whitelist. +When use this field to attach ecs instance, the attached volume cannot be deleted by terraform, please use `terraform state rm volcengine_volume.resource_name` command to remove it from terraform state file and management. * `project_name` - (Optional) The ProjectName of the Volume. * `volume_charge_type` - (Optional) The charge type of the Volume, the value is `PostPaid` or `PrePaid`. The `PrePaid` volume cannot be detached. Cannot convert `PrePaid` volume to `PostPaid`.Please note that `PrePaid` type needs to ask the system administrator to apply for a whitelist. diff --git a/website/docs/r/volume_attach.html.markdown b/website/docs/r/volume_attach.html.markdown index 6cfccfc4..d6052814 100644 --- a/website/docs/r/volume_attach.html.markdown +++ b/website/docs/r/volume_attach.html.markdown @@ -10,16 +10,72 @@ description: |- Provides a resource to manage volume attach ## Example Usage ```hcl +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +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 +} + +resource "volcengine_security_group" "foo" { + security_group_name = "acc-test-security-group" + vpc_id = volcengine_vpc.foo.id +} + +data "volcengine_images" "foo" { + os_type = "Linux" + visibility = "public" + instance_type_id = "ecs.g1.large" +} + +resource "volcengine_ecs_instance" "foo" { + instance_name = "acc-test-ecs" + description = "acc-test" + host_name = "tf-acc-test" + image_id = data.volcengine_images.foo.images[0].image_id + instance_type = "ecs.g1.large" + password = "93f0cb0614Aab12" + instance_charge_type = "PostPaid" + system_volume_type = "ESSD_PL0" + system_volume_size = 40 + subnet_id = volcengine_subnet.foo.id + security_group_ids = [volcengine_security_group.foo.id] + project_name = "default" + tags { + key = "k1" + value = "v1" + } +} + +resource "volcengine_volume" "foo" { + volume_name = "acc-test-volume" + volume_type = "ESSD_PL0" + description = "acc-test" + kind = "data" + size = 40 + zone_id = data.volcengine_zones.foo.zones[0].id + volume_charge_type = "PostPaid" + project_name = "default" +} + resource "volcengine_volume_attach" "foo" { - volume_id = "vol-3tzl52wubz3b9fciw7ev" - instance_id = "i-4ay59ww7dq8dt9c29hd4" + instance_id = volcengine_ecs_instance.foo.id + volume_id = volcengine_volume.foo.id } ``` ## Argument Reference The following arguments are supported: * `instance_id` - (Required, ForceNew) The Id of Instance. * `volume_id` - (Required, ForceNew) The Id of Volume. -* `delete_with_instance` - (Optional) Delete Volume with Attached Instance. +* `delete_with_instance` - (Optional) Delete Volume with Attached Instance.It is not recommended to use this field. If used, please ensure that the value of this field is consistent with the value of `delete_with_instance` in volcengine_volume. ## Attributes Reference In addition to all arguments above, the following attributes are exported: diff --git a/website/docs/r/vpn_connection.html.markdown b/website/docs/r/vpn_connection.html.markdown index 28fa6781..0d31dbca 100644 --- a/website/docs/r/vpn_connection.html.markdown +++ b/website/docs/r/vpn_connection.html.markdown @@ -10,24 +10,53 @@ description: |- Provides a resource to manage vpn connection ## Example Usage ```hcl +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-test-subnet" + cidr_block = "172.16.0.0/24" + zone_id = "cn-beijing-a" + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_vpn_gateway" "foo" { + vpc_id = volcengine_vpc.foo.id + subnet_id = volcengine_subnet.foo.id + bandwidth = 20 + vpn_gateway_name = "acc-test" + description = "acc-test" + period = 2 + project_name = "default" +} + +resource "volcengine_customer_gateway" "foo" { + ip_address = "192.0.1.3" + customer_gateway_name = "acc-test" + description = "acc-test" + project_name = "default" +} + resource "volcengine_vpn_connection" "foo" { - vpn_connection_name = "tf-test" - description = "tf-test" - vpn_gateway_id = "vgw-2feq19gnyc9hc59gp68914u6o" - customer_gateway_id = "cgw-12ayj1s157gn417q7y29bixqy" + vpn_connection_name = "acc-tf-test" + description = "acc-tf-test" + vpn_gateway_id = volcengine_vpn_gateway.foo.id + customer_gateway_id = volcengine_customer_gateway.foo.id local_subnet = ["192.168.0.0/22"] remote_subnet = ["192.161.0.0/20"] dpd_action = "none" nat_traversal = true - ike_config_psk = "tftest@!3" + ike_config_psk = "acctest@!3" ike_config_version = "ikev1" ike_config_mode = "main" ike_config_enc_alg = "aes" ike_config_auth_alg = "md5" ike_config_dh_group = "group2" ike_config_lifetime = 9000 - ike_config_local_id = "tf_test" - ike_config_remote_id = "tf_test" + ike_config_local_id = "acc_test" + ike_config_remote_id = "acc_test" ipsec_config_enc_alg = "aes" ipsec_config_auth_alg = "sha256" ipsec_config_dh_group = "group2" diff --git a/website/docs/r/vpn_gateway.html.markdown b/website/docs/r/vpn_gateway.html.markdown index 5240f82b..a28eb7f9 100644 --- a/website/docs/r/vpn_gateway.html.markdown +++ b/website/docs/r/vpn_gateway.html.markdown @@ -14,13 +14,25 @@ in [Volcengine Console](https://console.volcengine.com/finance/unsubscribe/),wh use 'terraform state rm ${resourceId}' to remove. ## Example Usage ```hcl +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-test-subnet" + cidr_block = "172.16.0.0/24" + zone_id = "cn-beijing-a" + vpc_id = volcengine_vpc.foo.id +} + resource "volcengine_vpn_gateway" "foo" { - vpc_id = "vpc-12b31m7z2kc8w17q7y2fih9ts" - subnet_id = "subnet-12bh8g2d7fshs17q7y2nx82uk" - bandwidth = 20 - vpn_gateway_name = "tf-test" - description = "tf-test" - period = 2 + vpc_id = volcengine_vpc.foo.id + subnet_id = volcengine_subnet.foo.id + bandwidth = 50 + vpn_gateway_name = "acc-test1" + description = "acc-test1" + period = 7 project_name = "default" } ``` diff --git a/website/docs/r/vpn_gateway_route.html.markdown b/website/docs/r/vpn_gateway_route.html.markdown index cf3f0161..938d597d 100644 --- a/website/docs/r/vpn_gateway_route.html.markdown +++ b/website/docs/r/vpn_gateway_route.html.markdown @@ -10,10 +10,65 @@ description: |- Provides a resource to manage vpn gateway route ## Example Usage ```hcl +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-test-subnet" + cidr_block = "172.16.0.0/24" + zone_id = "cn-beijing-a" + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_vpn_gateway" "foo" { + vpc_id = volcengine_vpc.foo.id + subnet_id = volcengine_subnet.foo.id + bandwidth = 20 + vpn_gateway_name = "acc-test" + description = "acc-test" + period = 2 + project_name = "default" +} + +resource "volcengine_customer_gateway" "foo" { + ip_address = "192.0.1.3" + customer_gateway_name = "acc-test" + description = "acc-test" + project_name = "default" +} + +resource "volcengine_vpn_connection" "foo" { + vpn_connection_name = "acc-tf-test" + description = "acc-tf-test" + vpn_gateway_id = volcengine_vpn_gateway.foo.id + customer_gateway_id = volcengine_customer_gateway.foo.id + local_subnet = ["192.168.0.0/22"] + remote_subnet = ["192.161.0.0/20"] + dpd_action = "none" + nat_traversal = true + ike_config_psk = "acctest@!3" + ike_config_version = "ikev1" + ike_config_mode = "main" + ike_config_enc_alg = "aes" + ike_config_auth_alg = "md5" + ike_config_dh_group = "group2" + ike_config_lifetime = 9000 + ike_config_local_id = "acc_test" + ike_config_remote_id = "acc_test" + ipsec_config_enc_alg = "aes" + ipsec_config_auth_alg = "sha256" + ipsec_config_dh_group = "group2" + ipsec_config_lifetime = 9000 + project_name = "default" + log_enabled = false +} + resource "volcengine_vpn_gateway_route" "foo" { - vpn_gateway_id = "vgw-2c012ea9fm5mo2dx0efxg46qi" + vpn_gateway_id = volcengine_vpn_gateway.foo.id destination_cidr_block = "192.168.0.0/20" - next_hop_id = "vgc-2d5ww3ww2lwcg58ozfe61ppc3" + next_hop_id = volcengine_vpn_connection.foo.id } ``` ## Argument Reference