mirror of https://github.com/hashicorp/packer
[azure-chroot] Updating parameter `exlude_from_latest` to `exclude_from_latest` (#10034)
parent
61c6085651
commit
809f38be3a
@ -0,0 +1,41 @@
|
||||
{
|
||||
"variables": {
|
||||
"client_id": "{{env `ARM_CLIENT_ID`}}",
|
||||
"client_secret": "{{env `ARM_CLIENT_SECRET`}}",
|
||||
"subscription_id": "{{env `ARM_SUBSCRIPTION_ID`}}",
|
||||
"resource_group": "{{env `ARM_IMAGE_RESOURCEGROUP_ID`}}",
|
||||
"gallery_name": "{{env `ARM_GALLERY_NAME`}}"
|
||||
},
|
||||
"builders": [{
|
||||
"type": "azure-chroot",
|
||||
|
||||
"client_id": "{{user `client_id`}}",
|
||||
"client_secret": "{{user `client_secret`}}",
|
||||
"subscription_id": "{{user `subscription_id`}}",
|
||||
|
||||
"source": "Canonical:UbuntuServer:20.04-LTS:latest",
|
||||
|
||||
"shared_image_destination": {
|
||||
"resource_group": "{{user `resource_group`}}",
|
||||
"gallery_name": "{{user `gallery_name`}}",
|
||||
"image_name": "MyUbuntuOSImage",
|
||||
"image_version": "1.0.0",
|
||||
"exclude_from_latest": false,
|
||||
"target_regions": [
|
||||
{
|
||||
"name": "eastus",
|
||||
"replicas": "1",
|
||||
"storage_account_type": "standard_zrs"
|
||||
}
|
||||
]
|
||||
}
|
||||
}],
|
||||
"provisioners": [{
|
||||
"inline": [
|
||||
"apt update",
|
||||
"apt upgrade -y"
|
||||
],
|
||||
"inline_shebang": "/bin/sh -x",
|
||||
"type": "shell"
|
||||
}]
|
||||
}
|
||||
@ -0,0 +1,70 @@
|
||||
package fix
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
|
||||
// FixerAzureExcludeFromLatest fix the spelling of "exclude_from_latest"
|
||||
// template in an Azure builder
|
||||
type FixerAzureExcludeFromLatest struct{}
|
||||
|
||||
func (FixerAzureExcludeFromLatest) DeprecatedOptions() []string {
|
||||
return []string{"exlude_from_latest"}
|
||||
}
|
||||
|
||||
func (FixerAzureExcludeFromLatest) 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 !strings.HasPrefix(builderType, "azure-chroot") {
|
||||
continue
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(builderType, "azure-chroot") {
|
||||
continue
|
||||
}
|
||||
|
||||
sharedImageDestination, ok := builder["shared_image_destination"].(map[string]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
excludeFromLatest, ok := sharedImageDestination["exlude_from_latest"]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
sharedImageDestination["exclude_from_latest"] = excludeFromLatest
|
||||
delete(sharedImageDestination, "exlude_from_latest")
|
||||
|
||||
builder["shared_image_destination"] = sharedImageDestination
|
||||
}
|
||||
|
||||
input["builders"] = tpl.Builders
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (FixerAzureExcludeFromLatest) Synopsis() string {
|
||||
return `Changes "exlude_from_latest" to "exclude_from_latest" in Azure builders.`
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
package fix
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFixerAzureExcludeFromLatest(t *testing.T) {
|
||||
var _ Fixer = new(FixerAzureExcludeFromLatest)
|
||||
}
|
||||
|
||||
func TestFixerAzureExcludeFromLatest_Fix_exlude_from_latest(t *testing.T) {
|
||||
cases := []struct {
|
||||
Input map[string]interface{}
|
||||
Expected map[string]interface{}
|
||||
}{
|
||||
// No shared_image_destination field
|
||||
{
|
||||
Input: map[string]interface{}{
|
||||
"type": "azure-chroot",
|
||||
},
|
||||
|
||||
Expected: map[string]interface{}{
|
||||
"type": "azure-chroot",
|
||||
},
|
||||
},
|
||||
|
||||
// exlude_from_latest field
|
||||
{
|
||||
Input: map[string]interface{}{
|
||||
"type": "azure-chroot",
|
||||
"shared_image_destination": map[string]interface{}{
|
||||
"exlude_from_latest": "false",
|
||||
},
|
||||
},
|
||||
|
||||
Expected: map[string]interface{}{
|
||||
"type": "azure-chroot",
|
||||
"shared_image_destination": map[string]interface{}{
|
||||
"exclude_from_latest": "false",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
var f FixerAzureExcludeFromLatest
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue