From f58687bd0f38e7dd53c7a2daca1b60bd8090a2cb Mon Sep 17 00:00:00 2001 From: tongyiming <1290863722@qq.com> Date: Mon, 5 Feb 2024 14:44:40 +0800 Subject: [PATCH] fix lighthouse import (#2508) * fix lighthouse import * import set default * update * fix update && fix unittest * add changelog --------- Co-authored-by: mikatong --- .changelog/2508.txt | 3 + .../resource_tc_lighthouse_instance.go | 39 +++++++++---- .../resource_tc_lighthouse_instance_test.go | 57 +++---------------- .../docs/r/lighthouse_instance.html.markdown | 5 +- 4 files changed, 44 insertions(+), 60 deletions(-) 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 diff --git a/tencentcloud/services/lighthouse/resource_tc_lighthouse_instance.go b/tencentcloud/services/lighthouse/resource_tc_lighthouse_instance.go index bbfccb32bb..1b338be0ac 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": { @@ -44,7 +49,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 +66,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 +212,18 @@ func ResourceTencentCloudLighthouseInstance() *schema.Resource { Computed: true, Description: "Firewall template ID. If this parameter is not specified, the default firewall policy is used.", }, + "public_addresses": { + Type: schema.TypeList, + Elem: &schema.Schema{Type: schema.TypeString}, + Computed: true, + Description: "Public addresses.", + }, + "private_addresses": { + Type: schema.TypeList, + Elem: &schema.Schema{Type: schema.TypeString}, + Computed: true, + Description: "Private addresses.", + }, }, } } @@ -259,7 +277,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 +424,14 @@ func resourceTencentCloudLighthouseInstanceRead(d *schema.ResourceData, meta int _ = d.Set("zone", instance.Zone) } + if len(instance.PublicAddresses) > 0 { + _ = d.Set("public_addresses", instance.PublicAddresses) + } + + if len(instance.PrivateAddresses) > 0 { + _ = d.Set("private_addresses", instance.PrivateAddresses) + } + return nil } @@ -557,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 bd1c2702ea..a37f2a4736 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{ { @@ -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 } ` diff --git a/website/docs/r/lighthouse_instance.html.markdown b/website/docs/r/lighthouse_instance.html.markdown index 57033a4f8d..0323b39c87 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_addresses` - Private addresses. +* `public_addresses` - Public addresses. ## Import