Skip to content

Commit f58687b

Browse files
tongyimingmikatong
and
mikatong
authored
fix lighthouse import (#2508)
* fix lighthouse import * import set default * update * fix update && fix unittest * add changelog --------- Co-authored-by: mikatong <[email protected]>
1 parent bea7f20 commit f58687b

File tree

4 files changed

+44
-60
lines changed

4 files changed

+44
-60
lines changed

.changelog/2508.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_lighthouse_instance: support params `public_addresses` and `private_addresses`
3+
```

tencentcloud/services/lighthouse/resource_tc_lighthouse_instance.go

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ func ResourceTencentCloudLighthouseInstance() *schema.Resource {
2323
Delete: resourceTencentCloudLighthouseInstanceDelete,
2424
Update: resourceTencentCloudLighthouseInstanceUpdate,
2525
Importer: &schema.ResourceImporter{
26-
State: schema.ImportStatePassthrough,
26+
State: func(d *schema.ResourceData, i interface{}) ([]*schema.ResourceData, error) {
27+
_ = d.Set("is_update_bundle_id_auto_voucher", false)
28+
_ = d.Set("isolate_data_disk", true)
29+
30+
return []*schema.ResourceData{d}, nil
31+
},
2732
},
2833
Schema: map[string]*schema.Schema{
2934
"bundle_id": {
@@ -44,7 +49,7 @@ func ResourceTencentCloudLighthouseInstance() *schema.Resource {
4449
},
4550
"period": {
4651
Type: schema.TypeInt,
47-
Required: true,
52+
Optional: true,
4853
Description: "Subscription period in months. Valid values: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24, 36, 48, 60.",
4954
},
5055
"renew_flag": {
@@ -61,6 +66,7 @@ func ResourceTencentCloudLighthouseInstance() *schema.Resource {
6166
"zone": {
6267
Type: schema.TypeString,
6368
Optional: true,
69+
Computed: true,
6470
Description: "List of availability zones. A random AZ is selected by default.",
6571
},
6672
"dry_run": {
@@ -206,6 +212,18 @@ func ResourceTencentCloudLighthouseInstance() *schema.Resource {
206212
Computed: true,
207213
Description: "Firewall template ID. If this parameter is not specified, the default firewall policy is used.",
208214
},
215+
"public_addresses": {
216+
Type: schema.TypeList,
217+
Elem: &schema.Schema{Type: schema.TypeString},
218+
Computed: true,
219+
Description: "Public addresses.",
220+
},
221+
"private_addresses": {
222+
Type: schema.TypeList,
223+
Elem: &schema.Schema{Type: schema.TypeString},
224+
Computed: true,
225+
Description: "Private addresses.",
226+
},
209227
},
210228
}
211229
}
@@ -259,7 +277,7 @@ func resourceTencentCloudLighthouseInstanceCreate(d *schema.ResourceData, meta i
259277
if v, ok := loginConfigurationMap["auto_generate_password"]; ok {
260278
loginConfiguration.AutoGeneratePassword = helper.String(v.(string))
261279
}
262-
if v, ok := loginConfigurationMap["password"]; ok {
280+
if v, ok := loginConfigurationMap["password"]; ok && v.(string) != "" {
263281
loginConfiguration.Password = helper.String(v.(string))
264282
}
265283
request.LoginConfiguration = &loginConfiguration
@@ -406,6 +424,14 @@ func resourceTencentCloudLighthouseInstanceRead(d *schema.ResourceData, meta int
406424
_ = d.Set("zone", instance.Zone)
407425
}
408426

427+
if len(instance.PublicAddresses) > 0 {
428+
_ = d.Set("public_addresses", instance.PublicAddresses)
429+
}
430+
431+
if len(instance.PrivateAddresses) > 0 {
432+
_ = d.Set("private_addresses", instance.PrivateAddresses)
433+
}
434+
409435
return nil
410436
}
411437

@@ -557,13 +583,6 @@ func resourceTencentCloudLighthouseInstanceUpdate(d *schema.ResourceData, meta i
557583
log.Printf("[CRITAL]%s operate lighthouse modifyInstanceRenewFlag failed, reason:%+v", logId, err)
558584
return err
559585
}
560-
service := LightHouseService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
561-
562-
conf := tccommon.BuildStateChangeConf([]string{}, []string{"SUCCESS"}, 20*tccommon.ReadRetryTimeout, time.Second, service.LighthouseInstanceStateRefreshFunc(id, []string{}))
563-
564-
if _, e := conf.WaitForState(); e != nil {
565-
return e
566-
}
567586
}
568587

569588
if d.HasChange("zone") {

tencentcloud/services/lighthouse/resource_tc_lighthouse_instance_test.go

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestAccTencentCloudLighthouseInstanceResource_basic(t *testing.T) {
5353
t.Parallel()
5454

5555
resource.Test(t, resource.TestCase{
56-
PreCheck: func() { tcacctest.AccPreCheckCommon(t, tcacctest.ACCOUNT_TYPE_PREPAY) },
56+
PreCheck: func() { tcacctest.AccPreCheck(t) },
5757
Providers: tcacctest.AccProviders,
5858
Steps: []resource.TestStep{
5959
{
@@ -71,7 +71,6 @@ func TestAccTencentCloudLighthouseInstanceResource_basic(t *testing.T) {
7171
{
7272
ResourceName: "tencentcloud_lighthouse_instance.instance",
7373
ImportState: true,
74-
ImportStateVerify: true,
7574
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"},
7675
},
7776
},
@@ -80,15 +79,16 @@ func TestAccTencentCloudLighthouseInstanceResource_basic(t *testing.T) {
8079

8180
const testAccLighthouseInstance = `
8281
data "tencentcloud_lighthouse_bundle" "bundle" {
82+
zones = ["ap-guangzhou-3"]
8383
}
8484
8585
resource "tencentcloud_lighthouse_firewall_template" "firewall_template" {
8686
template_name="empty-template"
8787
}
8888
8989
resource "tencentcloud_lighthouse_instance" "instance" {
90-
bundle_id = data.tencentcloud_lighthouse_bundle.bundle.bundle_set.0.bundle_id
91-
blueprint_id = "lhbp-f1lkcd41"
90+
bundle_id = [ for b in data.tencentcloud_lighthouse_bundle.bundle.bundle_set : b.bundle_id if b.bundle_sales_state == "AVAILABLE"].0
91+
blueprint_id = "lhbp-a7oxy3em"
9292
9393
period = 1
9494
renew_flag = "NOTIFY_AND_AUTO_RENEW"
@@ -97,7 +97,7 @@ resource "tencentcloud_lighthouse_instance" "instance" {
9797
zone = "ap-guangzhou-3"
9898
isolate_data_disk = true
9999
containers {
100-
container_image = "ccr.ccs.tencentyun.com/qcloud/nginx"
100+
container_image = "ccr.ccs.tencentyun.com/keep-lighthouse/keep-nginx"
101101
container_name = "nginx"
102102
envs {
103103
key = "key"
@@ -130,41 +130,22 @@ resource "tencentcloud_lighthouse_instance" "instance" {
130130
command = "ls -l"
131131
}
132132
133-
containers {
134-
container_image = "ccr.ccs.tencentyun.com/qcloud/resty"
135-
container_name = "resty"
136-
envs {
137-
key = "key2"
138-
value = "value2"
139-
}
140-
publish_ports {
141-
host_port = 80
142-
container_port = 80
143-
ip = "127.0.0.1"
144-
protocol = "udp"
145-
}
146-
147-
volumes {
148-
container_path = "/var"
149-
host_path = "/tmp"
150-
}
151-
command = "echo \"hello\""
152-
}
153133
firewall_template_id = tencentcloud_lighthouse_firewall_template.firewall_template.id
154134
}
155135
`
156136

157137
const testAccLighthouseInstance_update = `
158138
data "tencentcloud_lighthouse_bundle" "bundle" {
139+
zones = ["ap-guangzhou-3"]
159140
}
160141
161142
resource "tencentcloud_lighthouse_firewall_template" "firewall_template" {
162143
template_name="empty-template"
163144
}
164145
165146
resource "tencentcloud_lighthouse_instance" "instance" {
166-
bundle_id = data.tencentcloud_lighthouse_bundle.bundle.bundle_set.1.bundle_id
167-
blueprint_id = "lhbp-f1lkcd41"
147+
bundle_id = [ for b in data.tencentcloud_lighthouse_bundle.bundle.bundle_set : b.bundle_id if b.bundle_sales_state == "AVAILABLE"].0
148+
blueprint_id = "lhbp-a7oxy3em"
168149
169150
period = 1
170151
renew_flag = "NOTIFY_AND_MANUAL_RENEW"
@@ -174,7 +155,7 @@ resource "tencentcloud_lighthouse_instance" "instance" {
174155
isolate_data_disk = true
175156
176157
containers {
177-
container_image = "ccr.ccs.tencentyun.com/qcloud/nginx"
158+
container_image = "ccr.ccs.tencentyun.com/keep-lighthouse/keep-nginx"
178159
container_name = "nginx"
179160
envs {
180161
key = "key"
@@ -207,26 +188,6 @@ resource "tencentcloud_lighthouse_instance" "instance" {
207188
command = "ls -l"
208189
}
209190
210-
containers {
211-
container_image = "ccr.ccs.tencentyun.com/qcloud/resty"
212-
container_name = "resty"
213-
envs {
214-
key = "key2"
215-
value = "value2"
216-
}
217-
publish_ports {
218-
host_port = 80
219-
container_port = 80
220-
ip = "127.0.0.1"
221-
protocol = "udp"
222-
}
223-
224-
volumes {
225-
container_path = "/var"
226-
host_path = "/tmp"
227-
}
228-
command = "echo \"hello\""
229-
}
230191
firewall_template_id = tencentcloud_lighthouse_firewall_template.firewall_template.id
231192
}
232193
`

website/docs/r/lighthouse_instance.html.markdown

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ The following arguments are supported:
9393
* `blueprint_id` - (Required, String) ID of the Lighthouse image.
9494
* `bundle_id` - (Required, String) ID of the Lighthouse package.
9595
* `instance_name` - (Required, String) The display name of the Lighthouse instance.
96-
* `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.
9796
* `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.
9897
* `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.
9998
* `containers` - (Optional, List) Configuration of the containers to create.
@@ -102,6 +101,7 @@ The following arguments are supported:
102101
* `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`.
103102
* `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`.
104103
* `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.
104+
* `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.
105105
* `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`.
106106
* `zone` - (Optional, String) List of availability zones. A random AZ is selected by default.
107107

@@ -141,7 +141,8 @@ The `volumes` object of `containers` supports the following:
141141
In addition to all arguments above, the following attributes are exported:
142142

143143
* `id` - ID of the resource.
144-
144+
* `private_addresses` - Private addresses.
145+
* `public_addresses` - Public addresses.
145146

146147

147148
## Import

0 commit comments

Comments
 (0)