generated & docs

This commit is contained in:
Paul Meyer 2020-04-07 22:42:41 +00:00
parent 2240ead39c
commit 5c89d22fa2
13 changed files with 203 additions and 91 deletions

View File

@ -76,8 +76,6 @@ type Config struct {
// `/etc/resolv.conf`. You may need to do this if you're building an image that uses systemd.
CopyFiles []string `mapstructure:"copy_files"`
// The id of the temporary disk that will be created. Will be generated if not set.
TemporaryOSDiskID string `mapstructure:"temporary_os_disk_id"`
// Try to resize the OS disk to this size on the first copy. Disks can only be englarged. If not specified,
// the disk will keep its original size. Required when using `from_scratch`
OSDiskSizeGB int32 `mapstructure:"os_disk_size_gb"`
@ -87,23 +85,25 @@ type Config struct {
// The [cache type](https://docs.microsoft.com/en-us/rest/api/compute/images/createorupdate#cachingtypes)
// specified in the resulting image and for attaching it to the Packer VM. Defaults to `ReadOnly`
OSDiskCacheType string `mapstructure:"os_disk_cache_type"`
// The [Hyper-V generation type](https://docs.microsoft.com/en-us/rest/api/compute/images/createorupdate#hypervgenerationtypes) for Managed Image output.
// Defaults to `V1`.
ImageHyperVGeneration string `mapstructure:"image_hyperv_generation"`
// The id of the temporary disk that will be created. Will be generated if not set.
TemporaryOSDiskID string `mapstructure:"temporary_os_disk_id"`
// The id of the temporary snapshot that will be created. Will be generated if not set.
TemporaryOSDiskSnapshotID string `mapstructure:"temporary_os_disk_snapshot_id"`
// If set to `true`, leaves the temporary disks and snapshots behind in the Packer VM resource group. Defaults to `false`
SkipCleanup bool `mapstructure:"skip_cleanup"`
// The managed image to create using this build.
ImageResourceID string `mapstructure:"image_resource_id"`
// The shared image to create using this build.
SharedImageGalleryDestination SharedImageGalleryDestination `mapstructure:"shared_image_destination"`
// The [Hyper-V generation type](https://docs.microsoft.com/en-us/rest/api/compute/images/createorupdate#hypervgenerationtypes).
// Defaults to `V1`.
ImageHyperVGeneration string `mapstructure:"image_hyperv_generation"`
// If set to `true`, leaves the temporary disks and snapshots behind in the Packer VM resource group. Defaults to `false`
SkipCleanup bool `mapstructure:"skip_cleanup"`
ctx interpolate.Context
}
@ -120,7 +120,6 @@ func (c *Config) GetContext() interpolate.Context {
return c.ctx
}
// Builder is the Azure chroot builder
type Builder struct {
config Config
runner multistep.Runner

View File

@ -34,13 +34,15 @@ type FlatConfig struct {
PostMountCommands []string `mapstructure:"post_mount_commands" cty:"post_mount_commands"`
ChrootMounts [][]string `mapstructure:"chroot_mounts" cty:"chroot_mounts"`
CopyFiles []string `mapstructure:"copy_files" cty:"copy_files"`
TemporaryOSDiskName *string `mapstructure:"temporary_os_disk_name" cty:"temporary_os_disk_name"`
OSDiskSizeGB *int32 `mapstructure:"os_disk_size_gb" cty:"os_disk_size_gb"`
OSDiskStorageAccountType *string `mapstructure:"os_disk_storage_account_type" cty:"os_disk_storage_account_type"`
OSDiskCacheType *string `mapstructure:"os_disk_cache_type" cty:"os_disk_cache_type"`
OSDiskSkipCleanup *bool `mapstructure:"os_disk_skip_cleanup" cty:"os_disk_skip_cleanup"`
ImageResourceID *string `mapstructure:"image_resource_id" required:"true" cty:"image_resource_id"`
ImageHyperVGeneration *string `mapstructure:"image_hyperv_generation" cty:"image_hyperv_generation"`
TemporaryOSDiskID *string `mapstructure:"temporary_os_disk_id" cty:"temporary_os_disk_id"`
TemporaryOSDiskSnapshotID *string `mapstructure:"temporary_os_disk_snapshot_id" cty:"temporary_os_disk_snapshot_id"`
SkipCleanup *bool `mapstructure:"skip_cleanup" cty:"skip_cleanup"`
ImageResourceID *string `mapstructure:"image_resource_id" cty:"image_resource_id"`
SharedImageGalleryDestination *FlatSharedImageGalleryDestination `mapstructure:"shared_image_destination" cty:"shared_image_destination"`
}
// FlatMapstructure returns a new FlatConfig.
@ -80,13 +82,15 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
"post_mount_commands": &hcldec.AttrSpec{Name: "post_mount_commands", Type: cty.List(cty.String), Required: false},
"chroot_mounts": &hcldec.AttrSpec{Name: "chroot_mounts", Type: cty.List(cty.List(cty.String)), Required: false},
"copy_files": &hcldec.AttrSpec{Name: "copy_files", Type: cty.List(cty.String), Required: false},
"temporary_os_disk_name": &hcldec.AttrSpec{Name: "temporary_os_disk_name", Type: cty.String, Required: false},
"os_disk_size_gb": &hcldec.AttrSpec{Name: "os_disk_size_gb", Type: cty.Number, Required: false},
"os_disk_storage_account_type": &hcldec.AttrSpec{Name: "os_disk_storage_account_type", Type: cty.String, Required: false},
"os_disk_cache_type": &hcldec.AttrSpec{Name: "os_disk_cache_type", Type: cty.String, Required: false},
"os_disk_skip_cleanup": &hcldec.AttrSpec{Name: "os_disk_skip_cleanup", Type: cty.Bool, Required: false},
"image_resource_id": &hcldec.AttrSpec{Name: "image_resource_id", Type: cty.String, Required: false},
"image_hyperv_generation": &hcldec.AttrSpec{Name: "image_hyperv_generation", Type: cty.String, Required: false},
"temporary_os_disk_id": &hcldec.AttrSpec{Name: "temporary_os_disk_id", Type: cty.String, Required: false},
"temporary_os_disk_snapshot_id": &hcldec.AttrSpec{Name: "temporary_os_disk_snapshot_id", Type: cty.String, Required: false},
"skip_cleanup": &hcldec.AttrSpec{Name: "skip_cleanup", Type: cty.Bool, Required: false},
"image_resource_id": &hcldec.AttrSpec{Name: "image_resource_id", Type: cty.String, Required: false},
"shared_image_destination": &hcldec.BlockSpec{TypeName: "shared_image_destination", Nested: hcldec.ObjectSpec((*FlatSharedImageGalleryDestination)(nil).HCL2Spec())},
}
return s
}

View File

@ -1,5 +1,5 @@
//go:generate struct-markdown
//go:generate mapstructure-to-hcl2 -type SharedImageGalleryDestination
//go:generate mapstructure-to-hcl2 -type SharedImageGalleryDestination,TargetRegion
package chroot
@ -8,13 +8,13 @@ import (
"regexp"
)
// SharedImageGalleryDestination models an image version in a SIG
// that can be used as an source or destination for builders
// SharedImageGalleryDestination models an image version in a Shared
// Image Gallery that can be used as a destination.
type SharedImageGalleryDestination struct {
ResourceGroup string `mapstructure:"resource_group"`
GalleryName string `mapstructure:"gallery_name"`
ImageName string `mapstructure:"image_name"`
ImageVersion string `mapstructure:"image_version"`
ResourceGroup string `mapstructure:"resource_group" required:"true"`
GalleryName string `mapstructure:"gallery_name" required:"true"`
ImageName string `mapstructure:"image_name" required:"true"`
ImageVersion string `mapstructure:"image_version" required:"true"`
TargetRegions []TargetRegion `mapstructure:"target_regions"`
ExcludeFromLatest bool `mapstructure:"exlude_from_latest"`
@ -22,8 +22,8 @@ type SharedImageGalleryDestination struct {
// TargetRegion describes a region where the shared image should be replicated
type TargetRegion struct {
// Name of the region
Name string `mapstructure:"name"`
// Name of the Azure region
Name string `mapstructure:"name" required:"true"`
// Number of replicas in this region. Default: 1
ReplicaCount int32 `mapstructure:"replicas"`
// Storage account type: Standard_LRS or Standard_ZRS. Default: Standard_ZRS

View File

@ -0,0 +1,67 @@
// Code generated by "mapstructure-to-hcl2 -type SharedImageGalleryDestination,TargetRegion"; DO NOT EDIT.
package chroot
import (
"github.com/hashicorp/hcl/v2/hcldec"
"github.com/zclconf/go-cty/cty"
)
// FlatSharedImageGalleryDestination is an auto-generated flat version of SharedImageGalleryDestination.
// Where the contents of a field with a `mapstructure:,squash` tag are bubbled up.
type FlatSharedImageGalleryDestination struct {
ResourceGroup *string `mapstructure:"resource_group" required:"true" cty:"resource_group"`
GalleryName *string `mapstructure:"gallery_name" required:"true" cty:"gallery_name"`
ImageName *string `mapstructure:"image_name" required:"true" cty:"image_name"`
ImageVersion *string `mapstructure:"image_version" required:"true" cty:"image_version"`
TargetRegions []FlatTargetRegion `mapstructure:"target_regions" cty:"target_regions"`
ExcludeFromLatest *bool `mapstructure:"exlude_from_latest" cty:"exlude_from_latest"`
}
// FlatMapstructure returns a new FlatSharedImageGalleryDestination.
// FlatSharedImageGalleryDestination is an auto-generated flat version of SharedImageGalleryDestination.
// Where the contents a fields with a `mapstructure:,squash` tag are bubbled up.
func (*SharedImageGalleryDestination) FlatMapstructure() interface{ HCL2Spec() map[string]hcldec.Spec } {
return new(FlatSharedImageGalleryDestination)
}
// HCL2Spec returns the hcl spec of a SharedImageGalleryDestination.
// This spec is used by HCL to read the fields of SharedImageGalleryDestination.
// The decoded values from this spec will then be applied to a FlatSharedImageGalleryDestination.
func (*FlatSharedImageGalleryDestination) HCL2Spec() map[string]hcldec.Spec {
s := map[string]hcldec.Spec{
"resource_group": &hcldec.AttrSpec{Name: "resource_group", Type: cty.String, Required: false},
"gallery_name": &hcldec.AttrSpec{Name: "gallery_name", Type: cty.String, Required: false},
"image_name": &hcldec.AttrSpec{Name: "image_name", Type: cty.String, Required: false},
"image_version": &hcldec.AttrSpec{Name: "image_version", Type: cty.String, Required: false},
"target_regions": &hcldec.BlockListSpec{TypeName: "target_regions", Nested: hcldec.ObjectSpec((*FlatTargetRegion)(nil).HCL2Spec())},
"exlude_from_latest": &hcldec.AttrSpec{Name: "exlude_from_latest", Type: cty.Bool, Required: false},
}
return s
}
// FlatTargetRegion is an auto-generated flat version of TargetRegion.
// Where the contents of a field with a `mapstructure:,squash` tag are bubbled up.
type FlatTargetRegion struct {
Name *string `mapstructure:"name" required:"true" cty:"name"`
ReplicaCount *int32 `mapstructure:"replicas" cty:"replicas"`
StorageAccountType *string `mapstructure:"storage_account_type" cty:"storage_account_type"`
}
// FlatMapstructure returns a new FlatTargetRegion.
// FlatTargetRegion is an auto-generated flat version of TargetRegion.
// Where the contents a fields with a `mapstructure:,squash` tag are bubbled up.
func (*TargetRegion) FlatMapstructure() interface{ HCL2Spec() map[string]hcldec.Spec } {
return new(FlatTargetRegion)
}
// HCL2Spec returns the hcl spec of a TargetRegion.
// This spec is used by HCL to read the fields of TargetRegion.
// The decoded values from this spec will then be applied to a FlatTargetRegion.
func (*FlatTargetRegion) HCL2Spec() map[string]hcldec.Spec {
s := map[string]hcldec.Spec{
"name": &hcldec.AttrSpec{Name: "name", Type: cty.String, Required: false},
"replicas": &hcldec.AttrSpec{Name: "replicas", Type: cty.Number, Required: false},
"storage_account_type": &hcldec.AttrSpec{Name: "storage_account_type", Type: cty.String, Required: false},
}
return s
}

View File

@ -72,6 +72,20 @@ information.
@include 'builder/azure/chroot/Config-not-required.mdx'
#### Output options:
At least one of these options needs to be specified:
- `image_resource_id` (string) - The managed image to create using this build.
- `shared_image_destination` (object) - The shared image to create using this build.
Where `shared_image_destination` is an object with the following properties:
@include 'builder/azure/chroot/_SharedImageGalleryDestination-required.mdx
@include 'builder/azure/chroot/_SharedImageGalleryDestination-not-required.mdx
And `target_regions` is an array of objects with the following properties:
@include 'builder/azure/chroot/_TargetRegion-required.mdx
@include 'builder/azure/chroot/_TargetRegion-not-required.mdx
## Chroot Mounts
The `chroot_mounts` configuration can be used to mount specific devices within

View File

@ -31,9 +31,6 @@
provisioning. Defaults to `/etc/resolv.conf` so that DNS lookups work. Pass an empty list to skip copying
`/etc/resolv.conf`. You may need to do this if you're building an image that uses systemd.
- `temporary_os_disk_name` (string) - The name of the temporary disk that will be created in the resource group of the VM that Packer is
running on. Will be generated if not set.
- `os_disk_size_gb` (int32) - Try to resize the OS disk to this size on the first copy. Disks can only be englarged. If not specified,
the disk will keep its original size. Required when using `from_scratch`
@ -43,8 +40,16 @@
- `os_disk_cache_type` (string) - The [cache type](https://docs.microsoft.com/en-us/rest/api/compute/images/createorupdate#cachingtypes)
specified in the resulting image and for attaching it to the Packer VM. Defaults to `ReadOnly`
- `os_disk_skip_cleanup` (bool) - If set to `true`, leaves the temporary disk behind in the Packer VM resource group. Defaults to `false`
- `image_hyperv_generation` (string) - The [Hyper-V generation type](https://docs.microsoft.com/en-us/rest/api/compute/images/createorupdate#hypervgenerationtypes).
- `image_hyperv_generation` (string) - The [Hyper-V generation type](https://docs.microsoft.com/en-us/rest/api/compute/images/createorupdate#hypervgenerationtypes) for Managed Image output.
Defaults to `V1`.
- `temporary_os_disk_id` (string) - The id of the temporary disk that will be created. Will be generated if not set.
- `temporary_os_disk_snapshot_id` (string) - The id of the temporary snapshot that will be created. Will be generated if not set.
- `skip_cleanup` (bool) - If set to `true`, leaves the temporary disks and snapshots behind in the Packer VM resource group. Defaults to `false`
- `image_resource_id` (string) - The managed image to create using this build.
- `shared_image_destination` (SharedImageGalleryDestination) - The shared image to create using this build.

View File

@ -2,5 +2,3 @@
- `source` (string) - Either a managed disk resource ID or a publisher:offer:sku:version specifier for plaform image sources.
- `image_resource_id` (string) - The image to create using this build.

View File

@ -0,0 +1,4 @@
<!-- Code generated from the comments of the SharedImageGalleryDestination struct in builder/azure/chroot/shared_image_gallery_destination.go; DO NOT EDIT MANUALLY -->
- `target_regions` ([]TargetRegion) - Target Regions
- `exlude_from_latest` (bool) - Exclude From Latest

View File

@ -0,0 +1,6 @@
<!-- Code generated from the comments of the SharedImageGalleryDestination struct in builder/azure/chroot/shared_image_gallery_destination.go; DO NOT EDIT MANUALLY -->
- `resource_group` (string) - Resource Group
- `gallery_name` (string) - Gallery Name
- `image_name` (string) - Image Name
- `image_version` (string) - Image Version

View File

@ -0,0 +1,3 @@
<!-- Code generated from the comments of the SharedImageGalleryDestination struct in builder/azure/chroot/shared_image_gallery_destination.go; DO NOT EDIT MANUALLY -->
SharedImageGalleryDestination models an image version in a Shared
Image Gallery that can be used as a destination.

View File

@ -0,0 +1,6 @@
<!-- Code generated from the comments of the TargetRegion struct in builder/azure/chroot/shared_image_gallery_destination.go; DO NOT EDIT MANUALLY -->
- `replicas` (int32) - Number of replicas in this region. Default: 1
- `storage_account_type` (string) - Storage account type: Standard_LRS or Standard_ZRS. Default: Standard_ZRS

View File

@ -0,0 +1,4 @@
<!-- Code generated from the comments of the TargetRegion struct in builder/azure/chroot/shared_image_gallery_destination.go; DO NOT EDIT MANUALLY -->
- `name` (string) - Name of the Azure region

View File

@ -0,0 +1,2 @@
<!-- Code generated from the comments of the TargetRegion struct in builder/azure/chroot/shared_image_gallery_destination.go; DO NOT EDIT MANUALLY -->
TargetRegion describes a region where the shared image should be replicated