diff --git a/tencentcloud/data_source_tc_nat_gateway_snats_test.go b/tencentcloud/data_source_tc_nat_gateway_snats_test.go index 774103a2c7..545dae4dae 100644 --- a/tencentcloud/data_source_tc_nat_gateway_snats_test.go +++ b/tencentcloud/data_source_tc_nat_gateway_snats_test.go @@ -16,11 +16,11 @@ func TestAccTencentCloudNatGatewaySnatsDataSource(t *testing.T) { Config: testAccTencentCloudNatGatewaySnatsDataSourceConfig_basic, Check: resource.ComposeTestCheckFunc( testAccCheckTencentCloudDataSourceID("data.tencentcloud_nat_gateway_snats.snat"), - resource.TestCheckResourceAttr("data.tencentcloud_nat_gateway_snats.snat", "nats.#", "2"), - resource.TestCheckResourceAttr("data.tencentcloud_nat_gateway_snats.snat", "nats.0.resource_type", "SUBNET"), - resource.TestCheckResourceAttr("data.tencentcloud_nat_gateway_snats.snat", "nats.1.resource_type", "NETWORKINTERFACE"), - resource.TestCheckResourceAttr("data.tencentcloud_nat_gateway_snats.snat", "nats.0.description", "terraform test"), - resource.TestCheckResourceAttr("data.tencentcloud_nat_gateway_snats.snat", "nats.1.description", "terraform test"), + resource.TestCheckResourceAttr("data.tencentcloud_nat_gateway_snats.snat", "snat_list.#", "2"), + resource.TestCheckResourceAttr("data.tencentcloud_nat_gateway_snats.snat", "snat_list.0.resource_type", "SUBNET"), + resource.TestCheckResourceAttr("data.tencentcloud_nat_gateway_snats.snat", "snat_list.1.resource_type", "NETWORKINTERFACE"), + resource.TestCheckResourceAttr("data.tencentcloud_nat_gateway_snats.snat", "snat_list.0.description", "terraform test"), + resource.TestCheckResourceAttr("data.tencentcloud_nat_gateway_snats.snat", "snat_list.1.description", "terraform test"), ), }, }, @@ -28,12 +28,15 @@ func TestAccTencentCloudNatGatewaySnatsDataSource(t *testing.T) { } const testAccTencentCloudNatGatewaySnatsDataSourceConfig_basic = ` -data "tencentcloud_availability_zones" "my_zones" {} - -data "tencentcloud_vpc" "my_vpc" { +data "tencentcloud_vpc_instances" "my_vpc" { name = "Default-VPC" } +data "tencentcloud_vpc_subnets" "my_subnet" { + vpc_id = data.tencentcloud_vpc_instances.my_vpc.instance_list.0.vpc_id + subnet_id = "subnet-4o0zd840" +} + data "tencentcloud_images" "my_image" { os_name = "centos" } @@ -41,7 +44,6 @@ data "tencentcloud_images" "my_image" { data "tencentcloud_instance_types" "my_instance_types" { cpu_core_count = 1 memory_size = 1 - availability_zone = data.tencentcloud_availability_zones.my_zones.zones.0.name } # Create EIP @@ -54,8 +56,8 @@ resource "tencentcloud_eip" "eip_test_dnat" { # Create NAT Gateway resource "tencentcloud_nat_gateway" "my_nat" { - vpc_id = data.tencentcloud_vpc.my_vpc.id - name = "terraform test" + vpc_id = data.tencentcloud_vpc_instances.my_vpc.instance_list.0.vpc_id + name = "terraform datasource test" max_concurrent = 3000000 bandwidth = 500 @@ -65,33 +67,12 @@ resource "tencentcloud_nat_gateway" "my_nat" { ] } -# Create route_table and entry -resource "tencentcloud_route_table" "my_route_table" { - vpc_id = data.tencentcloud_vpc.my_vpc.id - name = "terraform test" -} -resource "tencentcloud_route_table_entry" "my_route_entry" { - route_table_id = tencentcloud_route_table.my_route_table.id - destination_cidr_block = "10.0.0.0/8" - next_type = "NAT" - next_hub = tencentcloud_nat_gateway.my_nat.id -} - -# Create Subnet -resource "tencentcloud_subnet" "my_subnet" { - vpc_id = data.tencentcloud_vpc.my_vpc.id - name = "terraform test" - cidr_block = "172.16.128.0/20" - availability_zone = data.tencentcloud_availability_zones.my_zones.zones.0.name - route_table_id = tencentcloud_route_table.my_route_table.id -} - # Subnet Nat gateway snat resource "tencentcloud_nat_gateway_snat" "my_subnet_snat" { nat_gateway_id = tencentcloud_nat_gateway.my_nat.id resource_type = "SUBNET" - subnet_id = tencentcloud_subnet.my_subnet.id - subnet_cidr_block = tencentcloud_subnet.my_subnet.cidr_block + subnet_id = data.tencentcloud_vpc_subnets.my_subnet.instance_list.0.subnet_id + subnet_cidr_block = data.tencentcloud_vpc_subnets.my_subnet.instance_list.0.cidr_block description = "terraform test" public_ip_addr = [ tencentcloud_eip.eip_dev_dnat.public_ip, @@ -99,33 +80,6 @@ resource "tencentcloud_nat_gateway_snat" "my_subnet_snat" { ] } -# Create instance -resource "tencentcloud_instance" "my_instance" { - instance_name = "terraform test" - availability_zone = data.tencentcloud_availability_zones.my_zones.zones.0.name - image_id = data.tencentcloud_images.my_image.images.0.image_id - instance_type = data.tencentcloud_instance_types.my_instance_types.instance_types.0.instance_type - system_disk_type = "CLOUD_PREMIUM" - system_disk_size = 50 - hostname = "user" - project_id = 0 - vpc_id = data.tencentcloud_vpc.my_vpc.id - subnet_id = tencentcloud_subnet.my_subnet.id - //internet_max_bandwidth_out = 20 -} - -# NetWorkInterface Nat gateway snat -resource "tencentcloud_nat_gateway_snat" "my_instance_snat" { - nat_gateway_id = tencentcloud_nat_gateway.my_nat.id - resource_type = "NETWORKINTERFACE" - instance_id = tencentcloud_instance.my_instance.id - instance_private_ip_addr = tencentcloud_instance.my_instance.private_ip - description = "terraform test" - public_ip_addr = [ - tencentcloud_eip.eip_dev_dnat.public_ip, - ] -} - data "tencentcloud_nat_gateway_snats" "snat" { nat_gateway_id = tencentcloud_nat_gateway.my_nat.id } diff --git a/tencentcloud/resource_tc_monitor_binding_receiver_test.go b/tencentcloud/resource_tc_monitor_binding_receiver_test.go deleted file mode 100644 index 41d62c5888..0000000000 --- a/tencentcloud/resource_tc_monitor_binding_receiver_test.go +++ /dev/null @@ -1,160 +0,0 @@ -package tencentcloud - -import ( - "context" - "fmt" - "log" - "strconv" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" -) - -func TestAccTencentCloudMonitorBindingReceiverResource(t *testing.T) { - t.Parallel() - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckMonitorBindingReceiverDestroy, - Steps: []resource.TestStep{ - { - Config: testAccMonitorBindingReceiverInstance, - Check: resource.ComposeTestCheckFunc( - testAccCheckMonitorBindingReceiverExists("tencentcloud_monitor_binding_receiver.receiver"), - resource.TestCheckResourceAttrSet("tencentcloud_monitor_binding_receiver.receiver", "group_id"), - resource.TestCheckResourceAttr("tencentcloud_monitor_binding_receiver.receiver", "receivers.#", "1"), - resource.TestCheckResourceAttr("tencentcloud_monitor_binding_receiver.receiver", "receivers.0.start_time", "0"), - resource.TestCheckResourceAttr("tencentcloud_monitor_binding_receiver.receiver", "receivers.0.end_time", "86399"), - resource.TestCheckResourceAttr("tencentcloud_monitor_binding_receiver.receiver", "receivers.0.receiver_type", "group"), - resource.TestCheckResourceAttr("tencentcloud_monitor_binding_receiver.receiver", "receivers.0.receive_language", "en-US"), - resource.TestCheckResourceAttr("tencentcloud_monitor_binding_receiver.receiver", "receivers.0.notify_way.#", "1"), - resource.TestCheckResourceAttr("tencentcloud_monitor_binding_receiver.receiver", "receivers.0.notify_way.0", "SMS"), - resource.TestCheckResourceAttr("tencentcloud_monitor_binding_receiver.receiver", "receivers.0.receiver_group_list.#", "1"), - ), - }, - }, - }) -} - -func testAccCheckMonitorBindingReceiverDestroy(s *terraform.State) error { - - for _, rs := range s.RootModule().Resources { - if rs.Type != "tencentcloud_monitor_binding_receiver" { - continue - } - groupIdStr := rs.Primary.Attributes["group_id"] - - if groupIdStr == "" { - return fmt.Errorf("miss group_id[%v] ", groupIdStr) - } - groupId, err := strconv.ParseInt(groupIdStr, 10, 64) - if err != nil { - return fmt.Errorf("id [%d] is broken", groupId) - } - - logId := getLogId(contextNil) - ctx := context.WithValue(context.TODO(), logIdKey, logId) - - service := MonitorService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} - - info, err := service.DescribePolicyGroup(ctx, groupId) - if err != nil { - err = resource.Retry(readRetryTimeout, func() *resource.RetryError { - info, err = service.DescribePolicyGroup(ctx, groupId) - if err != nil { - return retryError(err) - } - return nil - }) - } - if err != nil { - return err - } - - if info != nil { - return fmt.Errorf("group %d found in DescribePolicyGroup", groupId) - } - log.Printf("[DEBUG]group and receivers %d delete ok", groupId) - - } - return nil -} - -func testAccCheckMonitorBindingReceiverExists(n string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - - if !ok { - return fmt.Errorf("resource %s not found", n) - } - groupIdStr := rs.Primary.Attributes["group_id"] - - if groupIdStr == "" { - return fmt.Errorf("miss group_id[%v] ", groupIdStr) - } - groupId, err := strconv.ParseInt(groupIdStr, 10, 64) - if err != nil { - return fmt.Errorf("id [%d] is broken", groupId) - } - logId := getLogId(contextNil) - ctx := context.WithValue(context.TODO(), logIdKey, logId) - - service := MonitorService{client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn} - - info, err := service.DescribePolicyGroup(ctx, groupId) - if err != nil { - err = resource.Retry(readRetryTimeout, func() *resource.RetryError { - info, err = service.DescribePolicyGroup(ctx, groupId) - if err != nil { - return retryError(err) - } - return nil - }) - } - if err != nil { - return err - } - if info == nil { - return fmt.Errorf("group %d not found in DescribePolicyGroup", groupId) - } - if len(info.ReceiverInfos) > 0 { - return nil - } else { - return fmt.Errorf("group %d not found receiver in DescribePolicyGroup", groupId) - } - } -} - -const testAccMonitorBindingReceiverInstance string = ` - -data "tencentcloud_cam_groups" "groups" { - -} - -resource "tencentcloud_monitor_policy_group" "group" { - group_name = "terraform_test" - policy_view_name = "cvm_device" - remark = "this is a test policy group" - conditions { - metric_id = 33 - alarm_notify_type = 1 - alarm_notify_period = 600 - calc_type = 1 - calc_value = 3 - calc_period = 300 - continue_period = 2 - } -} -resource "tencentcloud_monitor_binding_receiver" "receiver" { - group_id = tencentcloud_monitor_policy_group.group.id - receivers { - start_time = 0 - end_time = 86399 - notify_way = ["SMS"] - receiver_type = "group" - receiver_group_list = [data.tencentcloud_cam_groups.groups.group_list[0].group_id] - receive_language = "en-US" - } -} -` diff --git a/tencentcloud/resource_tc_nat_gateway_snat_test.go b/tencentcloud/resource_tc_nat_gateway_snat_test.go index b2d7a4354d..2970992a09 100644 --- a/tencentcloud/resource_tc_nat_gateway_snat_test.go +++ b/tencentcloud/resource_tc_nat_gateway_snat_test.go @@ -47,7 +47,14 @@ func testAccCheckNatGatewaySnatDestroy(s *terraform.State) error { if rs.Type != "tencentcloud_nat_gateway_snat" { continue } - err, result := service.DescribeNatGatewaySnats(contextNil, rs.Primary.ID, nil) + + if rs.Primary.ID == "" { + return fmt.Errorf("nat gateway snat id is not set") + } + + ids := strings.Split(rs.Primary.ID, FILED_SP) + + err, result := service.DescribeNatGatewaySnats(contextNil, ids[0], nil) if err != nil { log.Printf("[CRITAL]%s read nat gateway snat failed, reason:%s\n ", logId, err.Error()) return err @@ -89,12 +96,16 @@ func testAccCheckNatGatewaySnatExists(n string) resource.TestCheckFunc { } const testAccNatGatewaySnatConfig = ` -data "tencentcloud_availability_zones" "my_zones" {} -data "tencentcloud_vpc" "my_vpc" { +data "tencentcloud_vpc_instances" "my_vpc" { name = "Default-VPC" } +data "tencentcloud_vpc_subnets" "my_subnet" { + vpc_id = data.tencentcloud_vpc_instances.my_vpc.instance_list.0.vpc_id + subnet_id = "subnet-4o0zd840" +} + data "tencentcloud_images" "my_image" { os_name = "centos" } @@ -114,7 +125,7 @@ resource "tencentcloud_eip" "eip_test_dnat" { # Create NAT Gateway resource "tencentcloud_nat_gateway" "my_nat" { - vpc_id = data.tencentcloud_vpc.my_vpc.id + vpc_id = data.tencentcloud_vpc_instances.my_vpc.instance_list.0.vpc_id name = "terraform test" max_concurrent = 3000000 bandwidth = 500 @@ -125,33 +136,12 @@ resource "tencentcloud_nat_gateway" "my_nat" { ] } -# Create route_table and entry -resource "tencentcloud_route_table" "my_route_table" { - vpc_id = data.tencentcloud_vpc.my_vpc.id - name = "terraform test" -} -resource "tencentcloud_route_table_entry" "my_route_entry" { - route_table_id = tencentcloud_route_table.my_route_table.id - destination_cidr_block = "10.0.0.0/8" - next_type = "NAT" - next_hub = tencentcloud_nat_gateway.my_nat.id -} - -# Create Subnet -resource "tencentcloud_subnet" "my_subnet" { - vpc_id = data.tencentcloud_vpc.my_vpc.id - name = "terraform test" - cidr_block = "172.128.128.0/24" - availability_zone = data.tencentcloud_availability_zones.my_zones.zones.0.name - route_table_id = tencentcloud_route_table.my_route_table.id -} - # Subnet Nat gateway snat resource "tencentcloud_nat_gateway_snat" "my_subnet_snat" { nat_gateway_id = tencentcloud_nat_gateway.my_nat.id resource_type = "SUBNET" - subnet_id = tencentcloud_subnet.my_subnet.id - subnet_cidr_block = tencentcloud_subnet.my_subnet.cidr_block + subnet_id = data.tencentcloud_vpc_subnets.my_subnet.instance_list.0.subnet_id + subnet_cidr_block = data.tencentcloud_vpc_subnets.my_subnet.instance_list.0.cidr_block description = "terraform test" public_ip_addr = [ tencentcloud_eip.eip_dev_dnat.public_ip, @@ -160,12 +150,16 @@ resource "tencentcloud_nat_gateway_snat" "my_subnet_snat" { } ` const testAccNatGatewaySnatConfigUpdate = ` -data "tencentcloud_availability_zones" "my_zones" {} -data "tencentcloud_vpc" "my_vpc" { +data "tencentcloud_vpc_instances" "my_vpc" { name = "Default-VPC" } +data "tencentcloud_vpc_subnets" "my_subnet" { + vpc_id = data.tencentcloud_vpc_instances.my_vpc.instance_list.0.vpc_id + subnet_id = "subnet-4o0zd840" +} + data "tencentcloud_images" "my_image" { os_name = "centos" } @@ -185,7 +179,7 @@ resource "tencentcloud_eip" "eip_test_dnat" { # Create NAT Gateway resource "tencentcloud_nat_gateway" "my_nat" { - vpc_id = data.tencentcloud_vpc.my_vpc.id + vpc_id = data.tencentcloud_vpc_instances.my_vpc.instance_list.0.vpc_id name = "terraform test" max_concurrent = 3000000 bandwidth = 500 @@ -196,33 +190,12 @@ resource "tencentcloud_nat_gateway" "my_nat" { ] } -# Create route_table and entry -resource "tencentcloud_route_table" "my_route_table" { - vpc_id = data.tencentcloud_vpc.my_vpc.id - name = "terraform test" -} -resource "tencentcloud_route_table_entry" "my_route_entry" { - route_table_id = tencentcloud_route_table.my_route_table.id - destination_cidr_block = "10.0.0.0/8" - next_type = "NAT" - next_hub = tencentcloud_nat_gateway.my_nat.id -} - -# Create Subnet -resource "tencentcloud_subnet" "my_subnet" { - vpc_id = data.tencentcloud_vpc.my_vpc.id - name = "terraform test" - cidr_block = "172.16.128.0/24" - availability_zone = data.tencentcloud_availability_zones.my_zones.zones.0.name - route_table_id = tencentcloud_route_table.my_route_table.id -} - # Subnet Nat gateway snat resource "tencentcloud_nat_gateway_snat" "my_subnet_snat" { nat_gateway_id = tencentcloud_nat_gateway.my_nat.id resource_type = "SUBNET" - subnet_id = tencentcloud_subnet.my_subnet.id - subnet_cidr_block = tencentcloud_subnet.my_subnet.cidr_block + subnet_id = data.tencentcloud_vpc_subnets.my_subnet.instance_list.0.subnet_id + subnet_cidr_block = data.tencentcloud_vpc_subnets.my_subnet.instance_list.0.cidr_block description = "terraform test2" public_ip_addr = [ tencentcloud_eip.eip_dev_dnat.public_ip,