From 4aea2efd0fea4365a8cdb375a35207ba1fcc19bc Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Wed, 21 Oct 2020 11:53:07 +0200 Subject: [PATCH] HCL2: fully name SSHTemporaryKeyPair fields so that they don't conflict and can be generated --- builder/googlecompute/config.hcl2spec.go | 4 +++- helper/communicator/config.go | 4 ++-- helper/communicator/config.hcl2spec.go | 12 +++++++----- helper/communicator/step_ssh_keygen.go | 4 ++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/builder/googlecompute/config.hcl2spec.go b/builder/googlecompute/config.hcl2spec.go index 900f4ceaa..133384a1f 100644 --- a/builder/googlecompute/config.hcl2spec.go +++ b/builder/googlecompute/config.hcl2spec.go @@ -24,7 +24,8 @@ type FlatConfig struct { SSHPassword *string `mapstructure:"ssh_password" cty:"ssh_password" hcl:"ssh_password"` SSHKeyPairName *string `mapstructure:"ssh_keypair_name" undocumented:"true" cty:"ssh_keypair_name" hcl:"ssh_keypair_name"` SSHTemporaryKeyPairName *string `mapstructure:"temporary_key_pair_name" undocumented:"true" cty:"temporary_key_pair_name" hcl:"temporary_key_pair_name"` - Bits *int `mapstructure:"temporary_key_pair_bits" cty:"temporary_key_pair_bits" hcl:"temporary_key_pair_bits"` + SSHTemporaryKeyPairType *string `mapstructure:"temporary_key_pair_type" cty:"temporary_key_pair_type" hcl:"temporary_key_pair_type"` + SSHTemporaryKeyPairBits *int `mapstructure:"temporary_key_pair_bits" cty:"temporary_key_pair_bits" hcl:"temporary_key_pair_bits"` SSHCiphers []string `mapstructure:"ssh_ciphers" cty:"ssh_ciphers" hcl:"ssh_ciphers"` SSHClearAuthorizedKeys *bool `mapstructure:"ssh_clear_authorized_keys" cty:"ssh_clear_authorized_keys" hcl:"ssh_clear_authorized_keys"` SSHKEXAlgos []string `mapstructure:"ssh_key_exchange_algorithms" cty:"ssh_key_exchange_algorithms" hcl:"ssh_key_exchange_algorithms"` @@ -145,6 +146,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "ssh_password": &hcldec.AttrSpec{Name: "ssh_password", Type: cty.String, Required: false}, "ssh_keypair_name": &hcldec.AttrSpec{Name: "ssh_keypair_name", Type: cty.String, Required: false}, "temporary_key_pair_name": &hcldec.AttrSpec{Name: "temporary_key_pair_name", Type: cty.String, Required: false}, + "temporary_key_pair_type": &hcldec.AttrSpec{Name: "temporary_key_pair_type", Type: cty.String, Required: false}, "temporary_key_pair_bits": &hcldec.AttrSpec{Name: "temporary_key_pair_bits", Type: cty.Number, Required: false}, "ssh_ciphers": &hcldec.AttrSpec{Name: "ssh_ciphers", Type: cty.List(cty.String), Required: false}, "ssh_clear_authorized_keys": &hcldec.AttrSpec{Name: "ssh_clear_authorized_keys", Type: cty.Bool, Required: false}, diff --git a/helper/communicator/config.go b/helper/communicator/config.go index 4e19b5037..f27cd2a76 100644 --- a/helper/communicator/config.go +++ b/helper/communicator/config.go @@ -195,7 +195,7 @@ type SSHTemporaryKeyPair struct { // // Specifies the type of key to create. The possible values are 'dsa', // 'ecdsa', 'ed25519', or 'rsa'. - Type string `mapstructure:"temporary_key_pair_type"` + SSHTemporaryKeyPairType string `mapstructure:"temporary_key_pair_type"` // Specifies the number of bits in the key to create. For RSA keys, the // minimum size is 1024 bits and the default is 4096 bits. Generally, 3072 // bits is considered sufficient. DSA keys must be exactly 1024 bits as @@ -204,7 +204,7 @@ type SSHTemporaryKeyPair struct { // bits. Attempting to use bit lengths other than these three values for // ECDSA keys will fail. Ed25519 keys have a fixed length and bits will be // ignored. - Bits int `mapstructure:"temporary_key_pair_bits"` + SSHTemporaryKeyPairBits int `mapstructure:"temporary_key_pair_bits"` } type WinRM struct { diff --git a/helper/communicator/config.hcl2spec.go b/helper/communicator/config.hcl2spec.go index 1430253b5..106a140db 100644 --- a/helper/communicator/config.hcl2spec.go +++ b/helper/communicator/config.hcl2spec.go @@ -17,7 +17,8 @@ type FlatConfig struct { SSHPassword *string `mapstructure:"ssh_password" cty:"ssh_password" hcl:"ssh_password"` SSHKeyPairName *string `mapstructure:"ssh_keypair_name" undocumented:"true" cty:"ssh_keypair_name" hcl:"ssh_keypair_name"` SSHTemporaryKeyPairName *string `mapstructure:"temporary_key_pair_name" undocumented:"true" cty:"temporary_key_pair_name" hcl:"temporary_key_pair_name"` - Bits *int `mapstructure:"temporary_key_pair_bits" cty:"temporary_key_pair_bits" hcl:"temporary_key_pair_bits"` + SSHTemporaryKeyPairType *string `mapstructure:"temporary_key_pair_type" cty:"temporary_key_pair_type" hcl:"temporary_key_pair_type"` + SSHTemporaryKeyPairBits *int `mapstructure:"temporary_key_pair_bits" cty:"temporary_key_pair_bits" hcl:"temporary_key_pair_bits"` SSHCiphers []string `mapstructure:"ssh_ciphers" cty:"ssh_ciphers" hcl:"ssh_ciphers"` SSHClearAuthorizedKeys *bool `mapstructure:"ssh_clear_authorized_keys" cty:"ssh_clear_authorized_keys" hcl:"ssh_clear_authorized_keys"` SSHKEXAlgos []string `mapstructure:"ssh_key_exchange_algorithms" cty:"ssh_key_exchange_algorithms" hcl:"ssh_key_exchange_algorithms"` @@ -79,6 +80,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "ssh_password": &hcldec.AttrSpec{Name: "ssh_password", Type: cty.String, Required: false}, "ssh_keypair_name": &hcldec.AttrSpec{Name: "ssh_keypair_name", Type: cty.String, Required: false}, "temporary_key_pair_name": &hcldec.AttrSpec{Name: "temporary_key_pair_name", Type: cty.String, Required: false}, + "temporary_key_pair_type": &hcldec.AttrSpec{Name: "temporary_key_pair_type", Type: cty.String, Required: false}, "temporary_key_pair_bits": &hcldec.AttrSpec{Name: "temporary_key_pair_bits", Type: cty.Number, Required: false}, "ssh_ciphers": &hcldec.AttrSpec{Name: "ssh_ciphers", Type: cty.List(cty.String), Required: false}, "ssh_clear_authorized_keys": &hcldec.AttrSpec{Name: "ssh_clear_authorized_keys", Type: cty.Bool, Required: false}, @@ -132,8 +134,8 @@ type FlatSSH struct { SSHPassword *string `mapstructure:"ssh_password" cty:"ssh_password" hcl:"ssh_password"` SSHKeyPairName *string `mapstructure:"ssh_keypair_name" undocumented:"true" cty:"ssh_keypair_name" hcl:"ssh_keypair_name"` SSHTemporaryKeyPairName *string `mapstructure:"temporary_key_pair_name" undocumented:"true" cty:"temporary_key_pair_name" hcl:"temporary_key_pair_name"` - Type *string `mapstructure:"temporary_key_pair_type" cty:"temporary_key_pair_type" hcl:"temporary_key_pair_type"` - Bits *int `mapstructure:"temporary_key_pair_bits" cty:"temporary_key_pair_bits" hcl:"temporary_key_pair_bits"` + SSHTemporaryKeyPairType *string `mapstructure:"temporary_key_pair_type" cty:"temporary_key_pair_type" hcl:"temporary_key_pair_type"` + SSHTemporaryKeyPairBits *int `mapstructure:"temporary_key_pair_bits" cty:"temporary_key_pair_bits" hcl:"temporary_key_pair_bits"` SSHCiphers []string `mapstructure:"ssh_ciphers" cty:"ssh_ciphers" hcl:"ssh_ciphers"` SSHClearAuthorizedKeys *bool `mapstructure:"ssh_clear_authorized_keys" cty:"ssh_clear_authorized_keys" hcl:"ssh_clear_authorized_keys"` SSHKEXAlgos []string `mapstructure:"ssh_key_exchange_algorithms" cty:"ssh_key_exchange_algorithms" hcl:"ssh_key_exchange_algorithms"` @@ -223,8 +225,8 @@ func (*FlatSSH) HCL2Spec() map[string]hcldec.Spec { // FlatSSHTemporaryKeyPair is an auto-generated flat version of SSHTemporaryKeyPair. // Where the contents of a field with a `mapstructure:,squash` tag are bubbled up. type FlatSSHTemporaryKeyPair struct { - Type *string `mapstructure:"temporary_key_pair_type" cty:"temporary_key_pair_type" hcl:"temporary_key_pair_type"` - Bits *int `mapstructure:"temporary_key_pair_bits" cty:"temporary_key_pair_bits" hcl:"temporary_key_pair_bits"` + SSHTemporaryKeyPairType *string `mapstructure:"temporary_key_pair_type" cty:"temporary_key_pair_type" hcl:"temporary_key_pair_type"` + SSHTemporaryKeyPairBits *int `mapstructure:"temporary_key_pair_bits" cty:"temporary_key_pair_bits" hcl:"temporary_key_pair_bits"` } // FlatMapstructure returns a new FlatSSHTemporaryKeyPair. diff --git a/helper/communicator/step_ssh_keygen.go b/helper/communicator/step_ssh_keygen.go index fe832a118..d05c488c8 100644 --- a/helper/communicator/step_ssh_keygen.go +++ b/helper/communicator/step_ssh_keygen.go @@ -35,7 +35,7 @@ func (s *StepSSHKeyGen) Run(ctx context.Context, state multistep.StateBag) multi return multistep.ActionContinue } - algorithm := s.SSHTemporaryKeyPair.Type + algorithm := s.SSHTemporaryKeyPair.SSHTemporaryKeyPairType if algorithm == "" { algorithm = sshkey.DSA.String() } @@ -47,7 +47,7 @@ func (s *StepSSHKeyGen) Run(ctx context.Context, state multistep.StateBag) multi } ui.Say(fmt.Sprintf("Creating temporary %s SSH key for instance...", a.String())) - pair, err := sshkey.GeneratePair(a, nil, s.Bits) + pair, err := sshkey.GeneratePair(a, nil, s.SSHTemporaryKeyPairBits) if err != nil { err := fmt.Errorf("Error creating temporary ssh key: %s", err) state.Put("error", err)