Skip to content

Commit 49af7ad

Browse files
tongyimingmikatong
andauthored
fix loginsettings update (#2155)
* fix loginsettings update * add changelog --------- Co-authored-by: mikatong <mikatong@tencent.com>
1 parent 62d007c commit 49af7ad

File tree

9 files changed

+1055
-929
lines changed

9 files changed

+1055
-929
lines changed

.changelog/2155.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
resource/tencentcloud_as_scaling_config: fix `key_ids` can not modify
3+
```

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ require (
2828
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/api v1.0.285
2929
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apigateway v1.0.736
3030
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apm v1.0.624
31-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.655
31+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.756
3232
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cam v1.0.409
3333
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cat v1.0.520
3434
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cbs v1.0.591

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apm v1.0.624 h1:AXDRZPP
780780
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apm v1.0.624/go.mod h1:ONtHJxQQsy6nuRdsnGj6X9G5/+a+EJdt1EtckvyVIS4=
781781
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.655 h1:6UbJtqoDPCcqvax/KFu6Yfj7kMw+0k3QSlqx2N2+c/g=
782782
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.655/go.mod h1:oObEUtcSyaZ/T6z1KMEdR2C/DXL0rSMKG31qamYH4vw=
783+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.756 h1:dx4aBdOWIqAUDQw9A6lU10EAaLpLwI2WRPVbuQgxzck=
784+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.756/go.mod h1:lwWeh6aHg6GlttTMp+VIVtpZOtmpP6DQnnYWpyYW37Y=
783785
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cam v1.0.409 h1:ToZpNh78SVdKakkeR9YV1a65tjtC4NJl+hrJqTuhO3g=
784786
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cam v1.0.409/go.mod h1:U24yUxCDruJLayOsP/onO2E/7+9ljeNsNO+phu+PeiM=
785787
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cat v1.0.520 h1:n4FN0PI+1MVWi+RGQbD/cElXjquZQK0K1h1Z1nNWNWw=

tencentcloud/resource_tc_as_scaling_config.go

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -587,14 +587,19 @@ func resourceTencentCloudAsScalingConfigRead(d *schema.ResourceData, meta interf
587587
_ = d.Set("cam_role_name", *config.CamRoleName)
588588

589589
if config.HostNameSettings != nil {
590+
isEmptySettings := true
590591
settings := map[string]interface{}{}
591592
if config.HostNameSettings.HostName != nil {
593+
isEmptySettings = false
592594
settings["host_name"] = config.HostNameSettings.HostName
593595
}
594596
if config.HostNameSettings.HostNameStyle != nil {
597+
isEmptySettings = false
595598
settings["host_name_style"] = config.HostNameSettings.HostNameStyle
596599
}
597-
_ = d.Set("host_name_settings", []interface{}{settings})
600+
if !isEmptySettings {
601+
_ = d.Set("host_name_settings", []interface{}{settings})
602+
}
598603
}
599604

600605
if config.InstanceNameSettings != nil {
@@ -705,23 +710,6 @@ func resourceTencentCloudAsScalingConfigUpdate(d *schema.ResourceData, meta inte
705710
request.InternetAccessible.PublicIpAssigned = &publicIpAssigned
706711
}
707712

708-
request.LoginSettings = &as.LoginSettings{}
709-
if v, ok := d.GetOk("password"); ok {
710-
request.LoginSettings.Password = helper.String(v.(string))
711-
}
712-
if v, ok := d.GetOk("key_ids"); ok {
713-
keyIds := v.([]interface{})
714-
request.LoginSettings.KeyIds = make([]*string, 0, len(keyIds))
715-
for i := range keyIds {
716-
keyId := keyIds[i].(string)
717-
request.LoginSettings.KeyIds = append(request.LoginSettings.KeyIds, &keyId)
718-
}
719-
}
720-
if v, ok := d.GetOk("keep_image_login"); ok {
721-
keepImageLogin := v.(bool)
722-
request.LoginSettings.KeepImageLogin = &keepImageLogin
723-
}
724-
725713
if v, ok := d.GetOk("security_group_ids"); ok {
726714
securityGroups := v.([]interface{})
727715
request.SecurityGroupIds = make([]*string, 0, len(securityGroups))
@@ -846,6 +834,34 @@ func resourceTencentCloudAsScalingConfigUpdate(d *schema.ResourceData, meta inte
846834
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
847835
}
848836

837+
loginSettingRequest := as.NewModifyLaunchConfigurationAttributesRequest()
838+
loginSettingRequest.LaunchConfigurationId = &configurationId
839+
loginSettingRequest.LoginSettings = &as.LoginSettings{}
840+
if v, ok := d.GetOk("password"); ok {
841+
loginSettingRequest.LoginSettings.Password = helper.String(v.(string))
842+
}
843+
if v, ok := d.GetOk("key_ids"); ok {
844+
keyIds := v.([]interface{})
845+
loginSettingRequest.LoginSettings.KeyIds = make([]*string, 0, len(keyIds))
846+
for i := range keyIds {
847+
keyId := keyIds[i].(string)
848+
loginSettingRequest.LoginSettings.KeyIds = append(loginSettingRequest.LoginSettings.KeyIds, &keyId)
849+
}
850+
}
851+
if v, ok := d.GetOk("keep_image_login"); ok {
852+
keepImageLogin := v.(bool)
853+
loginSettingRequest.LoginSettings.KeepImageLogin = &keepImageLogin
854+
}
855+
loginSettingResponse, err := meta.(*TencentCloudClient).apiV3Conn.UseAsClient().ModifyLaunchConfigurationAttributes(loginSettingRequest)
856+
if err != nil {
857+
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
858+
logId, loginSettingRequest.GetAction(), loginSettingRequest.ToJsonString(), err.Error())
859+
return err
860+
} else {
861+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
862+
logId, loginSettingRequest.GetAction(), loginSettingRequest.ToJsonString(), loginSettingResponse.ToJsonString())
863+
}
864+
849865
return nil
850866
}
851867

tencentcloud/resource_tc_as_scaling_config_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,30 @@ func TestAccTencentCloudAsScalingConfig_basic(t *testing.T) {
8181
})
8282
}
8383

84+
func TestAccTencentCloudAsScalingConfig_loginSettings(t *testing.T) {
85+
resource.Test(t, resource.TestCase{
86+
PreCheck: func() { testAccPreCheck(t) },
87+
Providers: testAccProviders,
88+
CheckDestroy: testAccCheckAsScalingConfigDestroy,
89+
Steps: []resource.TestStep{
90+
{
91+
Config: testAccAsScalingConfigLoginSetting("skey-58gbxolb"),
92+
Check: resource.ComposeAggregateTestCheckFunc(
93+
testAccCheckAsScalingConfigExists("tencentcloud_as_scaling_config.login_setting"),
94+
resource.TestCheckResourceAttr("tencentcloud_as_scaling_config.login_setting", "key_ids.0", "skey-58gbxolb"),
95+
),
96+
},
97+
{
98+
Config: testAccAsScalingConfigLoginSetting("skey-i55cwgvl"),
99+
Check: resource.ComposeAggregateTestCheckFunc(
100+
testAccCheckAsScalingConfigExists("tencentcloud_as_scaling_config.login_setting"),
101+
resource.TestCheckResourceAttr("tencentcloud_as_scaling_config.login_setting", "key_ids.0", "skey-i55cwgvl"),
102+
),
103+
},
104+
},
105+
})
106+
}
107+
84108
func TestAccTencentCloudAsScalingConfig_full(t *testing.T) {
85109
t.Parallel()
86110
resource.Test(t, resource.TestCase{
@@ -345,3 +369,15 @@ resource "tencentcloud_as_scaling_config" "launch_configuration" {
345369
}
346370
`
347371
}
372+
373+
func testAccAsScalingConfigLoginSetting(keyId string) string {
374+
return fmt.Sprintf(`
375+
resource "tencentcloud_as_scaling_config" "login_setting" {
376+
configuration_name = "test-as-login-setting"
377+
image_id = "img-2lr9q49h"
378+
instance_types = ["S5.SMALL2"]
379+
instance_charge_type = "POSTPAID_BY_HOUR"
380+
key_ids = ["%s"]
381+
}
382+
`, keyId)
383+
}

0 commit comments

Comments
 (0)