builder/amazon: Change shutdown_behaviour to shutdown_behavior
This commit is contained in:
parent
2f8bc086b0
commit
d3c2239b9e
|
@ -46,7 +46,7 @@ type RunConfig struct {
|
|||
UserDataFile string `mapstructure:"user_data_file"`
|
||||
WindowsPasswordTimeout time.Duration `mapstructure:"windows_password_timeout"`
|
||||
VpcId string `mapstructure:"vpc_id"`
|
||||
InstanceInitiatedShutdownBehavior string `mapstructure:"shutdown_behaviour"`
|
||||
InstanceInitiatedShutdownBehavior string `mapstructure:"shutdown_behavior"`
|
||||
|
||||
// Communicator settings
|
||||
Comm communicator.Config `mapstructure:",squash"`
|
||||
|
@ -106,7 +106,7 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
|
|||
if c.InstanceInitiatedShutdownBehavior == "" {
|
||||
c.InstanceInitiatedShutdownBehavior = "stop"
|
||||
} else if !reShutdownBehavior.MatchString(c.InstanceInitiatedShutdownBehavior) {
|
||||
errs = append(errs, fmt.Errorf("shutdown_behaviour only accepts 'stop' or 'terminate' values."))
|
||||
errs = append(errs, fmt.Errorf("shutdown_behavior only accepts 'stop' or 'terminate' values."))
|
||||
}
|
||||
|
||||
return errs
|
||||
|
|
|
@ -93,12 +93,12 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestBuilderPrepare_InvalidShutdownBehaviour(t *testing.T) {
|
||||
func TestBuilderPrepare_InvalidShutdownBehavior(t *testing.T) {
|
||||
var b Builder
|
||||
config := testConfig()
|
||||
|
||||
// Test good
|
||||
config["shutdown_behaviour"] = "terminate"
|
||||
config["shutdown_behavior"] = "terminate"
|
||||
warnings, err := b.Prepare(config)
|
||||
if len(warnings) > 0 {
|
||||
t.Fatalf("bad: %#v", warnings)
|
||||
|
@ -108,7 +108,7 @@ func TestBuilderPrepare_InvalidShutdownBehaviour(t *testing.T) {
|
|||
}
|
||||
|
||||
// Test good
|
||||
config["shutdown_behaviour"] = "stop"
|
||||
config["shutdown_behavior"] = "stop"
|
||||
warnings, err = b.Prepare(config)
|
||||
if len(warnings) > 0 {
|
||||
t.Fatalf("bad: %#v", warnings)
|
||||
|
@ -118,7 +118,7 @@ func TestBuilderPrepare_InvalidShutdownBehaviour(t *testing.T) {
|
|||
}
|
||||
|
||||
// Test bad
|
||||
config["shutdown_behaviour"] = "foobar"
|
||||
config["shutdown_behavior"] = "foobar"
|
||||
warnings, err = b.Prepare(config)
|
||||
if len(warnings) > 0 {
|
||||
t.Fatalf("bad: %#v", warnings)
|
||||
|
|
|
@ -55,12 +55,12 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestBuilderPrepare_InvalidShutdownBehaviour(t *testing.T) {
|
||||
func TestBuilderPrepare_InvalidShutdownBehavior(t *testing.T) {
|
||||
var b Builder
|
||||
config := testConfig()
|
||||
|
||||
// Test good
|
||||
config["shutdown_behaviour"] = "terminate"
|
||||
config["shutdown_behavior"] = "terminate"
|
||||
warnings, err := b.Prepare(config)
|
||||
if len(warnings) > 0 {
|
||||
t.Fatalf("bad: %#v", warnings)
|
||||
|
@ -70,7 +70,7 @@ func TestBuilderPrepare_InvalidShutdownBehaviour(t *testing.T) {
|
|||
}
|
||||
|
||||
// Test good
|
||||
config["shutdown_behaviour"] = "stop"
|
||||
config["shutdown_behavior"] = "stop"
|
||||
warnings, err = b.Prepare(config)
|
||||
if len(warnings) > 0 {
|
||||
t.Fatalf("bad: %#v", warnings)
|
||||
|
@ -80,7 +80,7 @@ func TestBuilderPrepare_InvalidShutdownBehaviour(t *testing.T) {
|
|||
}
|
||||
|
||||
// Test bad
|
||||
config["shutdown_behaviour"] = "foobar"
|
||||
config["shutdown_behavior"] = "foobar"
|
||||
warnings, err = b.Prepare(config)
|
||||
if len(warnings) > 0 {
|
||||
t.Fatalf("bad: %#v", warnings)
|
||||
|
|
22
fix/fixer.go
22
fix/fixer.go
|
@ -20,16 +20,17 @@ var FixerOrder []string
|
|||
|
||||
func init() {
|
||||
Fixers = map[string]Fixer{
|
||||
"iso-md5": new(FixerISOMD5),
|
||||
"createtime": new(FixerCreateTime),
|
||||
"pp-vagrant-override": new(FixerVagrantPPOverride),
|
||||
"virtualbox-gaattach": new(FixerVirtualBoxGAAttach),
|
||||
"virtualbox-rename": new(FixerVirtualBoxRename),
|
||||
"vmware-rename": new(FixerVMwareRename),
|
||||
"parallels-headless": new(FixerParallelsHeadless),
|
||||
"parallels-deprecations": new(FixerParallelsDeprecations),
|
||||
"sshkeypath": new(FixerSSHKeyPath),
|
||||
"manifest-filename": new(FixerManifestFilename),
|
||||
"iso-md5": new(FixerISOMD5),
|
||||
"createtime": new(FixerCreateTime),
|
||||
"pp-vagrant-override": new(FixerVagrantPPOverride),
|
||||
"virtualbox-gaattach": new(FixerVirtualBoxGAAttach),
|
||||
"virtualbox-rename": new(FixerVirtualBoxRename),
|
||||
"vmware-rename": new(FixerVMwareRename),
|
||||
"parallels-headless": new(FixerParallelsHeadless),
|
||||
"parallels-deprecations": new(FixerParallelsDeprecations),
|
||||
"sshkeypath": new(FixerSSHKeyPath),
|
||||
"manifest-filename": new(FixerManifestFilename),
|
||||
"amazon-shutdown_behavior": new(FixerAmazonShutdownBehavior),
|
||||
}
|
||||
|
||||
FixerOrder = []string{
|
||||
|
@ -43,5 +44,6 @@ func init() {
|
|||
"parallels-deprecations",
|
||||
"sshkeypath",
|
||||
"manifest-filename",
|
||||
"amazon-shutdown_behavior",
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package fix
|
||||
|
||||
import (
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
|
||||
// FixerAmazonShutdownBehavior fix the spelling of "shutdown_behavior"
|
||||
// template in a Amazon builder
|
||||
type FixerAmazonShutdownBehavior struct{}
|
||||
|
||||
func (FixerAmazonShutdownBehavior) Fix(input map[string]interface{}) (map[string]interface{}, error) {
|
||||
// The type we'll decode into; we only care about builders
|
||||
type template struct {
|
||||
Builders []map[string]interface{}
|
||||
}
|
||||
|
||||
// Decode the input into our structure, if we can
|
||||
var tpl template
|
||||
if err := mapstructure.Decode(input, &tpl); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, builder := range tpl.Builders {
|
||||
builderTypeRaw, ok := builder["type"]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
builderType, ok := builderTypeRaw.(string)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
if builderType != "amazon-ebs" && builderType != "amazon-ebsvolume" && builderType != "amazon-instance" && builderType != "amazon-chroot" {
|
||||
continue
|
||||
}
|
||||
|
||||
shutdownBehavior, ok := builder["shutdown_behaviour"]
|
||||
|
||||
if ok {
|
||||
builder["shutdown_behavior"] = shutdownBehavior
|
||||
delete(builder, "shutdown_behaviour")
|
||||
}
|
||||
}
|
||||
|
||||
input["builders"] = tpl.Builders
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (FixerAmazonShutdownBehavior) Synopsis() string {
|
||||
return `Changes "shutdown_behaviour" to "shutdown_behavior" in Amazon builders.`
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package fix
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFixerAmazonShutdownBehavior(t *testing.T) {
|
||||
var _ Fixer = new(FixerAmazonShutdownBehavior)
|
||||
}
|
||||
|
||||
func TestFixerAmazonShutdownBehavior_Fix_shutdown_behaviour(t *testing.T) {
|
||||
cases := []struct {
|
||||
Input map[string]interface{}
|
||||
Expected map[string]interface{}
|
||||
}{
|
||||
// No shutdown_behaviour field
|
||||
{
|
||||
Input: map[string]interface{}{
|
||||
"type": "amazon-ebs",
|
||||
},
|
||||
|
||||
Expected: map[string]interface{}{
|
||||
"type": "amazon-ebs",
|
||||
},
|
||||
},
|
||||
|
||||
// shutdown_behaviour field
|
||||
{
|
||||
Input: map[string]interface{}{
|
||||
"type": "amazon-ebs",
|
||||
"shutdown_behaviour": "stop",
|
||||
},
|
||||
|
||||
Expected: map[string]interface{}{
|
||||
"type": "amazon-ebs",
|
||||
"shutdown_behavior": "stop",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
var f FixerAmazonShutdownBehavior
|
||||
|
||||
input := map[string]interface{}{
|
||||
"builders": []map[string]interface{}{tc.Input},
|
||||
}
|
||||
|
||||
expected := map[string]interface{}{
|
||||
"builders": []map[string]interface{}{tc.Expected},
|
||||
}
|
||||
|
||||
output, err := f.Fix(input)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(output, expected) {
|
||||
t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -114,7 +114,7 @@ builder.
|
|||
described above. Note that if this is specified, you must omit the
|
||||
`security_group_id`.
|
||||
|
||||
- `shutdown_behaviour` (string) - Automatically terminate instances on shutdown
|
||||
- `shutdown_behavior` (string) - Automatically terminate instances on shutdown
|
||||
incase packer exits ungracefully. Possible values are `stop` and `terminate`.
|
||||
Defaults to `stop`.
|
||||
|
||||
|
|
|
@ -192,7 +192,7 @@ builder.
|
|||
described above. Note that if this is specified, you must omit the
|
||||
`security_group_id`.
|
||||
|
||||
- `shutdown_behaviour` (string) - Automatically terminate instances on shutdown
|
||||
- `shutdown_behavior` (string) - Automatically terminate instances on shutdown
|
||||
incase packer exits ungracefully. Possible values are "stop" and "terminate",
|
||||
default is `stop`.
|
||||
|
||||
|
@ -301,10 +301,6 @@ builder.
|
|||
- `windows_password_timeout` (string) - The timeout for waiting for a Windows
|
||||
password for Windows instances. Defaults to 20 minutes. Example value: `10m`
|
||||
|
||||
- `shutdown_behaviour` (string) - Automatically terminate instances on shutdown
|
||||
incase packer exits ungracefully. Possible values are `stop` and `terminate`,
|
||||
|
||||
|
||||
## Basic Example
|
||||
|
||||
Here is a basic example. You will need to provide access keys, and may need to change the AMI IDs according to what images exist at the time the template is run:
|
||||
|
|
|
@ -122,7 +122,7 @@ builder.
|
|||
|
||||
- `ssh_ip_version` (string) - The IP version to use for SSH connections, valid
|
||||
values are `4` and `6`. Useful on dual stacked instances where the default
|
||||
behaviour is to connect via whichever IP address is returned first from the
|
||||
behavior is to connect via whichever IP address is returned first from the
|
||||
OpenStack API.
|
||||
|
||||
- `ssh_keypair_name` (string) - If specified, this is the key that will be
|
||||
|
|
|
@ -63,12 +63,12 @@ Optional Parameters:
|
|||
- `ssh_host_key_file` (string) - The SSH key that will be used to run the SSH
|
||||
server on the host machine to forward commands to the target machine. Ansible
|
||||
connects to this server and will validate the identity of the server using
|
||||
the system known_hosts. The default behaviour is to generate and use a
|
||||
the system known_hosts. The default behavior is to generate and use a
|
||||
onetime key. Host key checking is disabled via the
|
||||
`ANSIBLE_HOST_KEY_CHECKING` environment variable if the key is generated.
|
||||
|
||||
- `ssh_authorized_key_file` (string) - The SSH public key of the Ansible
|
||||
`ssh_user`. The default behaviour is to generate and use a onetime key. If
|
||||
`ssh_user`. The default behavior is to generate and use a onetime key. If
|
||||
this key is generated, the corresponding private key is passed to
|
||||
`ansible-playbook` with the `--private-key` option.
|
||||
|
||||
|
|
Loading…
Reference in New Issue