From eeb5b0bda587192ba60c0804ba0a7a7ead133d74 Mon Sep 17 00:00:00 2001 From: Ujjwal Kumar Date: Sat, 17 Aug 2024 01:06:35 +0530 Subject: [PATCH 1/2] Added winrm_login_password support Signed-off-by: Ujjwal Kumar --- README.md | 1 + builder/ibmcloud/vpc/config.go | 2 ++ builder/ibmcloud/vpc/config.hcl2spec.go | 2 ++ builder/ibmcloud/vpc/winRM.go | 4 +++- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ef01828..eee001c 100644 --- a/README.md +++ b/README.md @@ -226,6 +226,7 @@ ssh_port | int | Optional | The port that SSH will be available on. Defaults to ssh_timeout | string | Optional | The time to wait for SSH to become available before timing out. The format of this value is a duration such as "5s" or "5m". ***Windows Communicator Variables*** | winrm_username | string | Optional | The username to use to connect to WinRM. +winrm_login_password | string | Optional | The password to use to connect to WinRM. (For custom windows images) winrm_port | int | Optional | The port that WinRM will be available on. Defaults to port 5986. winrm_timeout | string | Optional | The time to wait for WinRM to become available before timing out. winrm_insecure | bool | Optional | If true, do not check server certificate chain and host name. diff --git a/builder/ibmcloud/vpc/config.go b/builder/ibmcloud/vpc/config.go index b4206ed..3ed4dbc 100644 --- a/builder/ibmcloud/vpc/config.go +++ b/builder/ibmcloud/vpc/config.go @@ -45,6 +45,8 @@ type Config struct { VSIUserDataFile string `mapstructure:"vsi_user_data_file"` VSIUserDataString string `mapstructure:"vsi_user_data"` + WinRMLoginPassword string `mapstructure:"winrm_login_password"` + ImageName string `mapstructure:"image_name"` ImageTags []string `mapstructure:"tags"` diff --git a/builder/ibmcloud/vpc/config.hcl2spec.go b/builder/ibmcloud/vpc/config.hcl2spec.go index 2792a84..d74058c 100644 --- a/builder/ibmcloud/vpc/config.hcl2spec.go +++ b/builder/ibmcloud/vpc/config.hcl2spec.go @@ -91,6 +91,7 @@ type FlatConfig struct { VSIInterface *string `mapstructure:"vsi_interface" cty:"vsi_interface" hcl:"vsi_interface"` VSIUserDataFile *string `mapstructure:"vsi_user_data_file" cty:"vsi_user_data_file" hcl:"vsi_user_data_file"` VSIUserDataString *string `mapstructure:"vsi_user_data" cty:"vsi_user_data" hcl:"vsi_user_data"` + WinRMLoginPassword *string `mapstructure:"winrm_login_password" cty:"winrm_login_password" hcl:"winrm_login_password"` ImageName *string `mapstructure:"image_name" cty:"image_name" hcl:"image_name"` ImageTags []string `mapstructure:"tags" cty:"tags" hcl:"tags"` RawStateTimeout *string `mapstructure:"timeout" cty:"timeout" hcl:"timeout"` @@ -195,6 +196,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "vsi_interface": &hcldec.AttrSpec{Name: "vsi_interface", Type: cty.String, Required: false}, "vsi_user_data_file": &hcldec.AttrSpec{Name: "vsi_user_data_file", Type: cty.String, Required: false}, "vsi_user_data": &hcldec.AttrSpec{Name: "vsi_user_data", Type: cty.String, Required: false}, + "winrm_login_password": &hcldec.AttrSpec{Name: "winrm_login_password", Type: cty.String, Required: false}, "image_name": &hcldec.AttrSpec{Name: "image_name", Type: cty.String, Required: false}, "tags": &hcldec.AttrSpec{Name: "tags", Type: cty.List(cty.String), Required: false}, "timeout": &hcldec.AttrSpec{Name: "timeout", Type: cty.String, Required: false}, diff --git a/builder/ibmcloud/vpc/winRM.go b/builder/ibmcloud/vpc/winRM.go index 2d1a813..837974d 100644 --- a/builder/ibmcloud/vpc/winRM.go +++ b/builder/ibmcloud/vpc/winRM.go @@ -27,7 +27,9 @@ func winRMConfig(state multistep.StateBag) (*communicator.WinRMConfig, error) { return nil, nil } ui.Say(fmt.Sprintf("Successfully grabbed credentials for instance (ID: %s, IP: %s)", instanceID, config.Comm.WinRMHost)) - + if config.WinRMLoginPassword != "" { + password = config.WinRMLoginPassword + } // Configuring WinRM comm := communicator.WinRMConfig{ Username: username, From c334501e54a7a77f3a10db055f5499fe2b5e3522 Mon Sep 17 00:00:00 2001 From: Astha Jain Date: Wed, 21 Aug 2024 15:54:08 -0400 Subject: [PATCH 2/2] fixed winrm_password attribute --- README.md | 2 +- builder/ibmcloud/vpc/config.go | 2 -- builder/ibmcloud/vpc/config.hcl2spec.go | 2 -- builder/ibmcloud/vpc/winRM.go | 32 +++++++++++++++---------- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 32310ad..ec69823 100644 --- a/README.md +++ b/README.md @@ -225,7 +225,7 @@ ssh_port | int | Optional | The port that SSH will be available on. Defaults to ssh_timeout | string | Optional | The time to wait for SSH to become available before timing out. The format of this value is a duration such as "5s" or "5m". ***Windows Communicator Variables*** | winrm_username | string | Optional | The username to use to connect to WinRM. -winrm_login_password | string | Optional | The password to use to connect to WinRM. (For custom windows images) +winrm_password | string | Optional | The password to use to connect to WinRM. (For custom windows images) winrm_port | int | Optional | The port that WinRM will be available on. Defaults to port 5986. winrm_timeout | string | Optional | The time to wait for WinRM to become available before timing out. winrm_insecure | bool | Optional | If true, do not check server certificate chain and host name. diff --git a/builder/ibmcloud/vpc/config.go b/builder/ibmcloud/vpc/config.go index 3ed4dbc..b4206ed 100644 --- a/builder/ibmcloud/vpc/config.go +++ b/builder/ibmcloud/vpc/config.go @@ -45,8 +45,6 @@ type Config struct { VSIUserDataFile string `mapstructure:"vsi_user_data_file"` VSIUserDataString string `mapstructure:"vsi_user_data"` - WinRMLoginPassword string `mapstructure:"winrm_login_password"` - ImageName string `mapstructure:"image_name"` ImageTags []string `mapstructure:"tags"` diff --git a/builder/ibmcloud/vpc/config.hcl2spec.go b/builder/ibmcloud/vpc/config.hcl2spec.go index d74058c..2792a84 100644 --- a/builder/ibmcloud/vpc/config.hcl2spec.go +++ b/builder/ibmcloud/vpc/config.hcl2spec.go @@ -91,7 +91,6 @@ type FlatConfig struct { VSIInterface *string `mapstructure:"vsi_interface" cty:"vsi_interface" hcl:"vsi_interface"` VSIUserDataFile *string `mapstructure:"vsi_user_data_file" cty:"vsi_user_data_file" hcl:"vsi_user_data_file"` VSIUserDataString *string `mapstructure:"vsi_user_data" cty:"vsi_user_data" hcl:"vsi_user_data"` - WinRMLoginPassword *string `mapstructure:"winrm_login_password" cty:"winrm_login_password" hcl:"winrm_login_password"` ImageName *string `mapstructure:"image_name" cty:"image_name" hcl:"image_name"` ImageTags []string `mapstructure:"tags" cty:"tags" hcl:"tags"` RawStateTimeout *string `mapstructure:"timeout" cty:"timeout" hcl:"timeout"` @@ -196,7 +195,6 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "vsi_interface": &hcldec.AttrSpec{Name: "vsi_interface", Type: cty.String, Required: false}, "vsi_user_data_file": &hcldec.AttrSpec{Name: "vsi_user_data_file", Type: cty.String, Required: false}, "vsi_user_data": &hcldec.AttrSpec{Name: "vsi_user_data", Type: cty.String, Required: false}, - "winrm_login_password": &hcldec.AttrSpec{Name: "winrm_login_password", Type: cty.String, Required: false}, "image_name": &hcldec.AttrSpec{Name: "image_name", Type: cty.String, Required: false}, "tags": &hcldec.AttrSpec{Name: "tags", Type: cty.List(cty.String), Required: false}, "timeout": &hcldec.AttrSpec{Name: "timeout", Type: cty.String, Required: false}, diff --git a/builder/ibmcloud/vpc/winRM.go b/builder/ibmcloud/vpc/winRM.go index 837974d..0d8445f 100644 --- a/builder/ibmcloud/vpc/winRM.go +++ b/builder/ibmcloud/vpc/winRM.go @@ -16,20 +16,28 @@ func winRMConfig(state multistep.StateBag) (*communicator.WinRMConfig, error) { instanceData := state.Get("instance_data").(*vpcv1.Instance) instanceID := *instanceData.ID + var username, password string + var err error + + if config.Comm.WinRMPassword != "" { + username = config.Comm.WinRMUser + password = config.Comm.WinRMPassword + ui.Say(fmt.Sprintf("Setting provided winrm username and password (ID: %s, IP: %s)", instanceID, config.Comm.WinRMHost)) + + } else { + // Grabbing credentials for the instance + username, password, err = client.GrabCredentials(instanceID, state) + if err != nil { + err := fmt.Errorf("[ERROR] Error grabbing credentials: %s", err) + state.Put("error", err) + ui.Error(err.Error()) + // log.Fatalf(err.Error()) + return nil, nil + } + ui.Say(fmt.Sprintf("Successfully grabbed credentials for instance (ID: %s, IP: %s)", instanceID, config.Comm.WinRMHost)) - // Grabbing credentials for the instance - username, password, err := client.GrabCredentials(instanceID, state) - if err != nil { - err := fmt.Errorf("[ERROR] Error grabbing credentials: %s", err) - state.Put("error", err) - ui.Error(err.Error()) - // log.Fatalf(err.Error()) - return nil, nil - } - ui.Say(fmt.Sprintf("Successfully grabbed credentials for instance (ID: %s, IP: %s)", instanceID, config.Comm.WinRMHost)) - if config.WinRMLoginPassword != "" { - password = config.WinRMLoginPassword } + // Configuring WinRM comm := communicator.WinRMConfig{ Username: username,