Skip to content

Commit

Permalink
fix lighthouse import (#2508)
Browse files Browse the repository at this point in the history
* fix lighthouse import

* import set default

* update

* fix update && fix unittest

* add changelog

---------

Co-authored-by: mikatong <[email protected]>
  • Loading branch information
tongyiming and mikatong authored Feb 5, 2024
1 parent bea7f20 commit f58687b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 60 deletions.
3 changes: 3 additions & 0 deletions .changelog/2508.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_lighthouse_instance: support params `public_addresses` and `private_addresses`
```
39 changes: 29 additions & 10 deletions tencentcloud/services/lighthouse/resource_tc_lighthouse_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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": {
Expand All @@ -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": {
Expand Down Expand Up @@ -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.",
},
},
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand All @@ -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"},
},
},
Expand All @@ -80,15 +79,16 @@ func TestAccTencentCloudLighthouseInstanceResource_basic(t *testing.T) {

const testAccLighthouseInstance = `
data "tencentcloud_lighthouse_bundle" "bundle" {
zones = ["ap-guangzhou-3"]
}
resource "tencentcloud_lighthouse_firewall_template" "firewall_template" {
template_name="empty-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"
Expand All @@ -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"
Expand Down Expand Up @@ -130,41 +130,22 @@ 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" {
template_name="empty-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"
Expand All @@ -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"
Expand Down Expand Up @@ -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
}
`
5 changes: 3 additions & 2 deletions website/docs/r/lighthouse_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f58687b

Please sign in to comment.