From 3f64cc8e0915aa856e3d8606712002aa4e5ab0f8 Mon Sep 17 00:00:00 2001 From: mikatong Date: Tue, 30 Jan 2024 10:41:01 +0800 Subject: [PATCH 1/5] fix lighthouse import --- .../resource_tc_lighthouse_instance.go | 23 +++++++++++++++++-- .../resource_tc_lighthouse_instance_test.go | 2 +- .../docs/r/lighthouse_instance.html.markdown | 5 ++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/tencentcloud/services/lighthouse/resource_tc_lighthouse_instance.go b/tencentcloud/services/lighthouse/resource_tc_lighthouse_instance.go index bbfccb32bb..b65f1197bb 100644 --- a/tencentcloud/services/lighthouse/resource_tc_lighthouse_instance.go +++ b/tencentcloud/services/lighthouse/resource_tc_lighthouse_instance.go @@ -44,7 +44,7 @@ func ResourceTencentCloudLighthouseInstance() *schema.Resource { }, "period": { Type: schema.TypeInt, - Required: true, + Optional: true, Description: "Subscription period in months. Valid values: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24, 36, 48, 60.", }, "renew_flag": { @@ -61,6 +61,7 @@ func ResourceTencentCloudLighthouseInstance() *schema.Resource { "zone": { Type: schema.TypeString, Optional: true, + Computed: true, Description: "List of availability zones. A random AZ is selected by default.", }, "dry_run": { @@ -206,6 +207,16 @@ func ResourceTencentCloudLighthouseInstance() *schema.Resource { Computed: true, Description: "Firewall template ID. If this parameter is not specified, the default firewall policy is used.", }, + "public_address": { + Type: schema.TypeString, + Computed: true, + Description: "Public address.", + }, + "private_address": { + Type: schema.TypeString, + Computed: true, + Description: "Private address.", + }, }, } } @@ -259,7 +270,7 @@ func resourceTencentCloudLighthouseInstanceCreate(d *schema.ResourceData, meta i if v, ok := loginConfigurationMap["auto_generate_password"]; ok { loginConfiguration.AutoGeneratePassword = helper.String(v.(string)) } - if v, ok := loginConfigurationMap["password"]; ok { + if v, ok := loginConfigurationMap["password"]; ok && v.(string) != "" { loginConfiguration.Password = helper.String(v.(string)) } request.LoginConfiguration = &loginConfiguration @@ -406,6 +417,14 @@ func resourceTencentCloudLighthouseInstanceRead(d *schema.ResourceData, meta int _ = d.Set("zone", instance.Zone) } + if len(instance.PublicAddresses) > 0 { + _ = d.Set("public_address", instance.PublicAddresses[0]) + } + + if len(instance.PrivateAddresses) > 0 { + _ = d.Set("private_address", instance.PrivateAddresses[0]) + } + return nil } diff --git a/tencentcloud/services/lighthouse/resource_tc_lighthouse_instance_test.go b/tencentcloud/services/lighthouse/resource_tc_lighthouse_instance_test.go index bd1c2702ea..2e5cb7f7b1 100644 --- a/tencentcloud/services/lighthouse/resource_tc_lighthouse_instance_test.go +++ b/tencentcloud/services/lighthouse/resource_tc_lighthouse_instance_test.go @@ -53,7 +53,7 @@ func TestAccTencentCloudLighthouseInstanceResource_basic(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ - PreCheck: func() { tcacctest.AccPreCheckCommon(t, tcacctest.ACCOUNT_TYPE_PREPAY) }, + PreCheck: func() { tcacctest.AccPreCheck(t) }, Providers: tcacctest.AccProviders, Steps: []resource.TestStep{ { diff --git a/website/docs/r/lighthouse_instance.html.markdown b/website/docs/r/lighthouse_instance.html.markdown index 57033a4f8d..bad4fc2f05 100644 --- a/website/docs/r/lighthouse_instance.html.markdown +++ b/website/docs/r/lighthouse_instance.html.markdown @@ -93,7 +93,6 @@ The following arguments are supported: * `blueprint_id` - (Required, String) ID of the Lighthouse image. * `bundle_id` - (Required, String) ID of the Lighthouse package. * `instance_name` - (Required, String) The display name of the Lighthouse instance. -* `period` - (Required, Int) Subscription period in months. Valid values: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24, 36, 48, 60. * `renew_flag` - (Required, String) Auto-Renewal flag. Valid values: NOTIFY_AND_AUTO_RENEW: notify upon expiration and renew automatically; NOTIFY_AND_MANUAL_RENEW: notify upon expiration but do not renew automatically. You need to manually renew DISABLE_NOTIFY_AND_AUTO_RENEW: neither notify upon expiration nor renew automatically. Default value: NOTIFY_AND_MANUAL_RENEW. * `client_token` - (Optional, String) A unique string supplied by the client to ensure that the request is idempotent. Its maximum length is 64 ASCII characters. If this parameter is not specified, the idem-potency of the request cannot be guaranteed. * `containers` - (Optional, List) Configuration of the containers to create. @@ -102,6 +101,7 @@ The following arguments are supported: * `is_update_bundle_id_auto_voucher` - (Optional, Bool) Whether the voucher is deducted automatically when update bundle id. Value range: `true`: indicates automatic deduction of vouchers, `false`: does not automatically deduct vouchers. Default value: `false`. * `isolate_data_disk` - (Optional, Bool) Whether to return the mounted data disk. `true`: returns both the instance and the mounted data disk; `false`: returns the instance and no longer returns its mounted data disk. Default: `true`. * `login_configuration` - (Optional, List) Login password of the instance. It is only available for Windows instances. If it is not specified, it means that the user choose to set the login password after the instance creation. +* `period` - (Optional, Int) Subscription period in months. Valid values: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24, 36, 48, 60. * `permit_default_key_pair_login` - (Optional, String, **Deprecated**) It has been deprecated from version v1.81.8. Use `tencentcloud_lighthouse_key_pair_attachment` manage key pair. Whether to allow login using the default key pair. `YES`: allow login; `NO`: disable login. Default: `YES`. * `zone` - (Optional, String) List of availability zones. A random AZ is selected by default. @@ -141,7 +141,8 @@ The `volumes` object of `containers` supports the following: In addition to all arguments above, the following attributes are exported: * `id` - ID of the resource. - +* `private_address` - Private address. +* `public_address` - Public address. ## Import From d8d8effee48ca393796e247a1fcdc0b7e882fada Mon Sep 17 00:00:00 2001 From: mikatong Date: Tue, 30 Jan 2024 11:38:57 +0800 Subject: [PATCH 2/5] import set default --- .../services/lighthouse/resource_tc_lighthouse_instance.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tencentcloud/services/lighthouse/resource_tc_lighthouse_instance.go b/tencentcloud/services/lighthouse/resource_tc_lighthouse_instance.go index b65f1197bb..8dfdd5325c 100644 --- a/tencentcloud/services/lighthouse/resource_tc_lighthouse_instance.go +++ b/tencentcloud/services/lighthouse/resource_tc_lighthouse_instance.go @@ -23,7 +23,12 @@ func ResourceTencentCloudLighthouseInstance() *schema.Resource { Delete: resourceTencentCloudLighthouseInstanceDelete, Update: resourceTencentCloudLighthouseInstanceUpdate, Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, + State: func(d *schema.ResourceData, i interface{}) ([]*schema.ResourceData, error) { + _ = d.Set("is_update_bundle_id_auto_voucher", false) + _ = d.Set("isolate_data_disk", true) + + return []*schema.ResourceData{d}, nil + }, }, Schema: map[string]*schema.Schema{ "bundle_id": { From a38c42ff9c7a63cb3ee59569f381dce461b9dbfe Mon Sep 17 00:00:00 2001 From: mikatong Date: Tue, 30 Jan 2024 16:44:13 +0800 Subject: [PATCH 3/5] update --- .../resource_tc_lighthouse_instance.go | 18 ++++++++++-------- .../docs/r/lighthouse_instance.html.markdown | 4 ++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/tencentcloud/services/lighthouse/resource_tc_lighthouse_instance.go b/tencentcloud/services/lighthouse/resource_tc_lighthouse_instance.go index 8dfdd5325c..81ce9a7196 100644 --- a/tencentcloud/services/lighthouse/resource_tc_lighthouse_instance.go +++ b/tencentcloud/services/lighthouse/resource_tc_lighthouse_instance.go @@ -212,15 +212,17 @@ func ResourceTencentCloudLighthouseInstance() *schema.Resource { Computed: true, Description: "Firewall template ID. If this parameter is not specified, the default firewall policy is used.", }, - "public_address": { - Type: schema.TypeString, + "public_addresses": { + Type: schema.TypeList, + Elem: &schema.Schema{Type: schema.TypeString}, Computed: true, - Description: "Public address.", + Description: "Public addresses.", }, - "private_address": { - Type: schema.TypeString, + "private_addresses": { + Type: schema.TypeList, + Elem: &schema.Schema{Type: schema.TypeString}, Computed: true, - Description: "Private address.", + Description: "Private addresses.", }, }, } @@ -423,11 +425,11 @@ func resourceTencentCloudLighthouseInstanceRead(d *schema.ResourceData, meta int } if len(instance.PublicAddresses) > 0 { - _ = d.Set("public_address", instance.PublicAddresses[0]) + _ = d.Set("public_addresses", instance.PublicAddresses) } if len(instance.PrivateAddresses) > 0 { - _ = d.Set("private_address", instance.PrivateAddresses[0]) + _ = d.Set("private_addresses", instance.PrivateAddresses) } return nil diff --git a/website/docs/r/lighthouse_instance.html.markdown b/website/docs/r/lighthouse_instance.html.markdown index bad4fc2f05..0323b39c87 100644 --- a/website/docs/r/lighthouse_instance.html.markdown +++ b/website/docs/r/lighthouse_instance.html.markdown @@ -141,8 +141,8 @@ The `volumes` object of `containers` supports the following: In addition to all arguments above, the following attributes are exported: * `id` - ID of the resource. -* `private_address` - Private address. -* `public_address` - Public address. +* `private_addresses` - Private addresses. +* `public_addresses` - Public addresses. ## Import From db4b3c0865167e114487a665676313c851f84935 Mon Sep 17 00:00:00 2001 From: mikatong Date: Sun, 4 Feb 2024 15:11:42 +0800 Subject: [PATCH 4/5] fix update && fix unittest --- .../resource_tc_lighthouse_instance.go | 7 --- .../resource_tc_lighthouse_instance_test.go | 55 +++---------------- 2 files changed, 8 insertions(+), 54 deletions(-) diff --git a/tencentcloud/services/lighthouse/resource_tc_lighthouse_instance.go b/tencentcloud/services/lighthouse/resource_tc_lighthouse_instance.go index 81ce9a7196..1b338be0ac 100644 --- a/tencentcloud/services/lighthouse/resource_tc_lighthouse_instance.go +++ b/tencentcloud/services/lighthouse/resource_tc_lighthouse_instance.go @@ -583,13 +583,6 @@ func resourceTencentCloudLighthouseInstanceUpdate(d *schema.ResourceData, meta i log.Printf("[CRITAL]%s operate lighthouse modifyInstanceRenewFlag failed, reason:%+v", logId, err) return err } - service := LightHouseService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} - - conf := tccommon.BuildStateChangeConf([]string{}, []string{"SUCCESS"}, 20*tccommon.ReadRetryTimeout, time.Second, service.LighthouseInstanceStateRefreshFunc(id, []string{})) - - if _, e := conf.WaitForState(); e != nil { - return e - } } if d.HasChange("zone") { diff --git a/tencentcloud/services/lighthouse/resource_tc_lighthouse_instance_test.go b/tencentcloud/services/lighthouse/resource_tc_lighthouse_instance_test.go index 2e5cb7f7b1..a37f2a4736 100644 --- a/tencentcloud/services/lighthouse/resource_tc_lighthouse_instance_test.go +++ b/tencentcloud/services/lighthouse/resource_tc_lighthouse_instance_test.go @@ -71,7 +71,6 @@ func TestAccTencentCloudLighthouseInstanceResource_basic(t *testing.T) { { ResourceName: "tencentcloud_lighthouse_instance.instance", ImportState: true, - ImportStateVerify: true, ImportStateVerifyIgnore: []string{"is_update_bundle_id_auto_voucher", "period", "dry_run", "client_token", "login_configuration", "permit_default_key_pair_login", "isolate_data_disk", "containers", "firewall_template_id"}, }, }, @@ -80,6 +79,7 @@ func TestAccTencentCloudLighthouseInstanceResource_basic(t *testing.T) { const testAccLighthouseInstance = ` data "tencentcloud_lighthouse_bundle" "bundle" { + zones = ["ap-guangzhou-3"] } resource "tencentcloud_lighthouse_firewall_template" "firewall_template" { @@ -87,8 +87,8 @@ resource "tencentcloud_lighthouse_firewall_template" "firewall_template" { } resource "tencentcloud_lighthouse_instance" "instance" { - bundle_id = data.tencentcloud_lighthouse_bundle.bundle.bundle_set.0.bundle_id - blueprint_id = "lhbp-f1lkcd41" + bundle_id = [ for b in data.tencentcloud_lighthouse_bundle.bundle.bundle_set : b.bundle_id if b.bundle_sales_state == "AVAILABLE"].0 + blueprint_id = "lhbp-a7oxy3em" period = 1 renew_flag = "NOTIFY_AND_AUTO_RENEW" @@ -97,7 +97,7 @@ resource "tencentcloud_lighthouse_instance" "instance" { zone = "ap-guangzhou-3" isolate_data_disk = true containers { - container_image = "ccr.ccs.tencentyun.com/qcloud/nginx" + container_image = "ccr.ccs.tencentyun.com/keep-lighthouse/keep-nginx" container_name = "nginx" envs { key = "key" @@ -130,32 +130,13 @@ resource "tencentcloud_lighthouse_instance" "instance" { command = "ls -l" } - containers { - container_image = "ccr.ccs.tencentyun.com/qcloud/resty" - container_name = "resty" - envs { - key = "key2" - value = "value2" - } - publish_ports { - host_port = 80 - container_port = 80 - ip = "127.0.0.1" - protocol = "udp" - } - - volumes { - container_path = "/var" - host_path = "/tmp" - } - command = "echo \"hello\"" - } firewall_template_id = tencentcloud_lighthouse_firewall_template.firewall_template.id } ` const testAccLighthouseInstance_update = ` data "tencentcloud_lighthouse_bundle" "bundle" { + zones = ["ap-guangzhou-3"] } resource "tencentcloud_lighthouse_firewall_template" "firewall_template" { @@ -163,8 +144,8 @@ resource "tencentcloud_lighthouse_firewall_template" "firewall_template" { } resource "tencentcloud_lighthouse_instance" "instance" { - bundle_id = data.tencentcloud_lighthouse_bundle.bundle.bundle_set.1.bundle_id - blueprint_id = "lhbp-f1lkcd41" + bundle_id = [ for b in data.tencentcloud_lighthouse_bundle.bundle.bundle_set : b.bundle_id if b.bundle_sales_state == "AVAILABLE"].0 + blueprint_id = "lhbp-a7oxy3em" period = 1 renew_flag = "NOTIFY_AND_MANUAL_RENEW" @@ -174,7 +155,7 @@ resource "tencentcloud_lighthouse_instance" "instance" { isolate_data_disk = true containers { - container_image = "ccr.ccs.tencentyun.com/qcloud/nginx" + container_image = "ccr.ccs.tencentyun.com/keep-lighthouse/keep-nginx" container_name = "nginx" envs { key = "key" @@ -207,26 +188,6 @@ resource "tencentcloud_lighthouse_instance" "instance" { command = "ls -l" } - containers { - container_image = "ccr.ccs.tencentyun.com/qcloud/resty" - container_name = "resty" - envs { - key = "key2" - value = "value2" - } - publish_ports { - host_port = 80 - container_port = 80 - ip = "127.0.0.1" - protocol = "udp" - } - - volumes { - container_path = "/var" - host_path = "/tmp" - } - command = "echo \"hello\"" - } firewall_template_id = tencentcloud_lighthouse_firewall_template.firewall_template.id } ` From 7075e4adae87e12bb85f7912e33cedc8598722f5 Mon Sep 17 00:00:00 2001 From: mikatong Date: Sun, 4 Feb 2024 15:27:08 +0800 Subject: [PATCH 5/5] add changelog --- .changelog/2508.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/2508.txt diff --git a/.changelog/2508.txt b/.changelog/2508.txt new file mode 100644 index 0000000000..a1f50c970d --- /dev/null +++ b/.changelog/2508.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_lighthouse_instance: support params `public_addresses` and `private_addresses` +``` \ No newline at end of file