Merge pull request #7920 from hashicorp/fix_7865

[wip] fix polling issues in azure
This commit is contained in:
Megan Marsh 2019-08-01 12:40:11 -07:00 committed by GitHub
commit 1952130030
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 6 deletions

View File

@ -9,6 +9,7 @@ import (
"net/url"
"os"
"strconv"
"time"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-04-01/compute"
newCompute "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-03-01/compute"
@ -126,7 +127,7 @@ func byConcatDecorators(decorators ...autorest.RespondDecorator) autorest.Respon
}
func NewAzureClient(subscriptionID, resourceGroupName, storageAccountName string,
cloud *azure.Environment,
cloud *azure.Environment, SharedGalleryTimeout time.Duration,
servicePrincipalToken, servicePrincipalTokenVault *adal.ServicePrincipalToken) (*AzureClient, error) {
var azureClient = &AzureClient{}
@ -210,6 +211,7 @@ func NewAzureClient(subscriptionID, resourceGroupName, storageAccountName string
azureClient.GalleryImageVersionsClient.RequestInspector = withInspection(maxlen)
azureClient.GalleryImageVersionsClient.ResponseInspector = byConcatDecorators(byInspecting(maxlen), errorCapture(azureClient))
azureClient.GalleryImageVersionsClient.UserAgent = fmt.Sprintf("%s %s", useragent.String(), azureClient.GalleryImageVersionsClient.UserAgent)
azureClient.GalleryImageVersionsClient.Client.PollingDuration = SharedGalleryTimeout
azureClient.GalleryImagesClient = newCompute.NewGalleryImagesClientWithBaseURI(cloud.ResourceManagerEndpoint, subscriptionID)
azureClient.GalleryImagesClient.Authorizer = autorest.NewBearerAuthorizer(servicePrincipalToken)

View File

@ -90,6 +90,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
b.config.ResourceGroupName,
b.config.StorageAccount,
b.config.cloudEnvironment,
b.config.SharedGalleryTimeout,
spnCloud,
spnKeyVault)

View File

@ -96,6 +96,7 @@ type Config struct {
// Shared Gallery Destination
SharedGalleryDestination SharedImageGalleryDestination `mapstructure:"shared_image_gallery_destination"`
SharedGalleryTimeout time.Duration `mapstructure:"shared_image_gallery_timeout"`
// Compute
ImagePublisher string `mapstructure:"image_publisher"`
@ -648,6 +649,10 @@ func assertRequiredParametersSet(c *Config, errs *packer.MultiError) {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("A list of replication_regions must be specified for shared_image_gallery_destination"))
}
}
if c.SharedGalleryTimeout == 0 {
// default to a one-hour timeout. In the sdk, the default is 15 m.
c.SharedGalleryTimeout = 60 * time.Minute
}
if c.ManagedImageOSDiskSnapshotName != "" {
if ok, err := assertManagedImageOSDiskSnapshotName(c.ManagedImageOSDiskSnapshotName, "managed_image_os_disk_snapshot_name"); !ok {

View File

@ -122,16 +122,16 @@ When creating a managed image the following options are required.
`managed_image_name` must also be set. See
[documentation](https://docs.microsoft.com/en-us/azure/storage/storage-managed-disks-overview#images)
to learn more about managed images.
Managed images can optionally be published to [Shared Image Gallery](https://azure.microsoft.com/en-us/blog/announcing-the-public-preview-of-shared-image-gallery/)
as Shared Gallery Image version. Shared Image Gallery **only** works with Managed Images. **A VHD cannot be published to
a Shared Image Gallery**. When publishing to a Shared Image Gallery the following options are required.
- `shared_image_gallery_destination` (object) The name of the Shared Image Gallery under which the managed image will be published as Shared Gallery Image version.
Following is an example.
<!-- -->
"shared_image_gallery_destination": {
@ -303,6 +303,14 @@ Providing `temp_resource_group_name` or `location` in combination with
"managed_image_name": "TargetImageName",
"managed_image_resource_group_name": "TargetResourceGroup"
- `shared_image_gallery_timeout` (time.Duration) How long to wait for an image
to be published to the shared image gallery before timing out. If your
Packer build is failing on the Publishing to Shared Image Gallery step
with the error `Original Error: context deadline exceeded`, but the image
is present when you check your Azure dashboard, then you probably need to
increase this timeout from its default of "60m" (valid time units include
`s` for seconds, `m` for minutes, and `h` for hours.)
- `temp_compute_name` (string) temporary name assigned to the VM. If this
value is not set, a random value will be assigned. Knowing the resource
group and VM name allows one to execute commands to update the VM during a