Skip to content

Commit

Permalink
fix loginsettings update (#2155)
Browse files Browse the repository at this point in the history
* fix loginsettings update

* add changelog

---------

Co-authored-by: mikatong <[email protected]>
  • Loading branch information
2 people authored and hellertang committed Oct 10, 2023
1 parent 61f4f3c commit 468ae32
Show file tree
Hide file tree
Showing 9 changed files with 1,055 additions and 929 deletions.
3 changes: 3 additions & 0 deletions .changelog/2155.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/tencentcloud_as_scaling_config: fix `key_ids` can not modify
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/api v1.0.285
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apigateway v1.0.736
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apm v1.0.624
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.655
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.756
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cam v1.0.409
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cat v1.0.520
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cbs v1.0.591
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apm v1.0.624 h1:AXDRZPP
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apm v1.0.624/go.mod h1:ONtHJxQQsy6nuRdsnGj6X9G5/+a+EJdt1EtckvyVIS4=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.655 h1:6UbJtqoDPCcqvax/KFu6Yfj7kMw+0k3QSlqx2N2+c/g=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.655/go.mod h1:oObEUtcSyaZ/T6z1KMEdR2C/DXL0rSMKG31qamYH4vw=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.756 h1:dx4aBdOWIqAUDQw9A6lU10EAaLpLwI2WRPVbuQgxzck=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.756/go.mod h1:lwWeh6aHg6GlttTMp+VIVtpZOtmpP6DQnnYWpyYW37Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cam v1.0.409 h1:ToZpNh78SVdKakkeR9YV1a65tjtC4NJl+hrJqTuhO3g=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cam v1.0.409/go.mod h1:U24yUxCDruJLayOsP/onO2E/7+9ljeNsNO+phu+PeiM=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cat v1.0.520 h1:n4FN0PI+1MVWi+RGQbD/cElXjquZQK0K1h1Z1nNWNWw=
Expand Down
52 changes: 34 additions & 18 deletions tencentcloud/resource_tc_as_scaling_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,14 +587,19 @@ func resourceTencentCloudAsScalingConfigRead(d *schema.ResourceData, meta interf
_ = d.Set("cam_role_name", *config.CamRoleName)

if config.HostNameSettings != nil {
isEmptySettings := true
settings := map[string]interface{}{}
if config.HostNameSettings.HostName != nil {
isEmptySettings = false
settings["host_name"] = config.HostNameSettings.HostName
}
if config.HostNameSettings.HostNameStyle != nil {
isEmptySettings = false
settings["host_name_style"] = config.HostNameSettings.HostNameStyle
}
_ = d.Set("host_name_settings", []interface{}{settings})
if !isEmptySettings {
_ = d.Set("host_name_settings", []interface{}{settings})
}
}

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

request.LoginSettings = &as.LoginSettings{}
if v, ok := d.GetOk("password"); ok {
request.LoginSettings.Password = helper.String(v.(string))
}
if v, ok := d.GetOk("key_ids"); ok {
keyIds := v.([]interface{})
request.LoginSettings.KeyIds = make([]*string, 0, len(keyIds))
for i := range keyIds {
keyId := keyIds[i].(string)
request.LoginSettings.KeyIds = append(request.LoginSettings.KeyIds, &keyId)
}
}
if v, ok := d.GetOk("keep_image_login"); ok {
keepImageLogin := v.(bool)
request.LoginSettings.KeepImageLogin = &keepImageLogin
}

if v, ok := d.GetOk("security_group_ids"); ok {
securityGroups := v.([]interface{})
request.SecurityGroupIds = make([]*string, 0, len(securityGroups))
Expand Down Expand Up @@ -846,6 +834,34 @@ func resourceTencentCloudAsScalingConfigUpdate(d *schema.ResourceData, meta inte
logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
}

loginSettingRequest := as.NewModifyLaunchConfigurationAttributesRequest()
loginSettingRequest.LaunchConfigurationId = &configurationId
loginSettingRequest.LoginSettings = &as.LoginSettings{}
if v, ok := d.GetOk("password"); ok {
loginSettingRequest.LoginSettings.Password = helper.String(v.(string))
}
if v, ok := d.GetOk("key_ids"); ok {
keyIds := v.([]interface{})
loginSettingRequest.LoginSettings.KeyIds = make([]*string, 0, len(keyIds))
for i := range keyIds {
keyId := keyIds[i].(string)
loginSettingRequest.LoginSettings.KeyIds = append(loginSettingRequest.LoginSettings.KeyIds, &keyId)
}
}
if v, ok := d.GetOk("keep_image_login"); ok {
keepImageLogin := v.(bool)
loginSettingRequest.LoginSettings.KeepImageLogin = &keepImageLogin
}
loginSettingResponse, err := meta.(*TencentCloudClient).apiV3Conn.UseAsClient().ModifyLaunchConfigurationAttributes(loginSettingRequest)
if err != nil {
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
logId, loginSettingRequest.GetAction(), loginSettingRequest.ToJsonString(), err.Error())
return err
} else {
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n",
logId, loginSettingRequest.GetAction(), loginSettingRequest.ToJsonString(), loginSettingResponse.ToJsonString())
}

return nil
}

Expand Down
36 changes: 36 additions & 0 deletions tencentcloud/resource_tc_as_scaling_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,30 @@ func TestAccTencentCloudAsScalingConfig_basic(t *testing.T) {
})
}

func TestAccTencentCloudAsScalingConfig_loginSettings(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAsScalingConfigDestroy,
Steps: []resource.TestStep{
{
Config: testAccAsScalingConfigLoginSetting("skey-58gbxolb"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAsScalingConfigExists("tencentcloud_as_scaling_config.login_setting"),
resource.TestCheckResourceAttr("tencentcloud_as_scaling_config.login_setting", "key_ids.0", "skey-58gbxolb"),
),
},
{
Config: testAccAsScalingConfigLoginSetting("skey-i55cwgvl"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAsScalingConfigExists("tencentcloud_as_scaling_config.login_setting"),
resource.TestCheckResourceAttr("tencentcloud_as_scaling_config.login_setting", "key_ids.0", "skey-i55cwgvl"),
),
},
},
})
}

func TestAccTencentCloudAsScalingConfig_full(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
Expand Down Expand Up @@ -345,3 +369,15 @@ resource "tencentcloud_as_scaling_config" "launch_configuration" {
}
`
}

func testAccAsScalingConfigLoginSetting(keyId string) string {
return fmt.Sprintf(`
resource "tencentcloud_as_scaling_config" "login_setting" {
configuration_name = "test-as-login-setting"
image_id = "img-2lr9q49h"
instance_types = ["S5.SMALL2"]
instance_charge_type = "POSTPAID_BY_HOUR"
key_ids = ["%s"]
}
`, keyId)
}
Loading

0 comments on commit 468ae32

Please sign in to comment.