Documentation ¶
Index ¶
- Constants
- Variables
- func Authenticate(env azure.Environment, tenantID string, say func(string), scope string) (*adal.ServicePrincipalToken, error)
- func FindTenantID(env azure.Environment, subscriptionID string) (string, error)
- func IsAzure() bool
- func NewCertOAuthTokenProvider(env azure.Environment, clientID, clientCertPath, tenantID string, ...) (oAuthTokenProvider, error)
- func NewCliOAuthTokenProvider(env azure.Environment, say func(string), tenantID string) oAuthTokenProvider
- func NewDeviceFlowOAuthTokenProvider(env azure.Environment, say func(string), tenantID string) oAuthTokenProvider
- func NewJWTOAuthTokenProvider(env azure.Environment, clientID, clientJWT, tenantID string) oAuthTokenProvider
- func NewMSIOAuthTokenProvider(env azure.Environment, ClientID string) oAuthTokenProvider
- func NewSecretOAuthTokenProvider(env azure.Environment, clientID, clientSecret, tenantID string) oAuthTokenProvider
- func NormalizeLocation(loc string) string
- type AzureClientSet
- type AzureClientSetMock
- func (m *AzureClientSetMock) DisksClient() computeapi.DisksClientAPI
- func (m *AzureClientSetMock) GalleryImageVersionsClient() computeapi.GalleryImageVersionsClientAPI
- func (m *AzureClientSetMock) GalleryImagesClient() computeapi.GalleryImagesClientAPI
- func (m *AzureClientSetMock) ImagesClient() computeapi.ImagesClientAPI
- func (m *AzureClientSetMock) MetadataClient() MetadataClientAPI
- func (m *AzureClientSetMock) PollClient() autorest.Client
- func (m *AzureClientSetMock) SnapshotsClient() computeapi.SnapshotsClientAPI
- func (m *AzureClientSetMock) SubscriptionID() string
- func (m *AzureClientSetMock) VirtualMachineImagesClient() VirtualMachineImagesClientAPI
- func (m *AzureClientSetMock) VirtualMachineScaleSetVMsClient() computeapi.VirtualMachineScaleSetVMsClientAPI
- func (m *AzureClientSetMock) VirtualMachinesClient() computeapi.VirtualMachinesClientAPI
- type CompoundName
- type ComputeInfo
- type Config
- func (c *Config) CloudEnvironment() *azure.Environment
- func (c *Config) FillParameters() error
- func (c Config) GetServicePrincipalToken(say func(string), forResource string) (servicePrincipalToken *adal.ServicePrincipalToken, err error)
- func (c Config) GetServicePrincipalTokens(say func(string)) (servicePrincipalToken *adal.ServicePrincipalToken, ...)
- func (c *Config) SetDefaultValues() error
- func (c Config) UseCLI() bool
- func (c Config) UseMSI() bool
- func (c Config) Validate(errs *packersdk.MultiError)
- type MetadataClientAPI
- type MetadataClientStub
- type PlatformImage
- type Resource
- type VirtualMachineImagesClient
- type VirtualMachineImagesClientAPI
Constants ¶
const DefaultCloudEnvironmentName = "Public"
Variables ¶
var DefaultMetadataClient = NewMetadataClient()
DefaultMetadataClient is the default instance metadata client for Azure. Replace this variable for testing purposes only
Functions ¶
func Authenticate ¶
func Authenticate(env azure.Environment, tenantID string, say func(string), scope string) (*adal.ServicePrincipalToken, error)
Authenticate fetches a token from the local file cache or initiates a consent flow and waits for token to be obtained.
func FindTenantID ¶
func FindTenantID(env azure.Environment, subscriptionID string) (string, error)
FindTenantID figures out the AAD tenant ID of the subscription by making an unauthenticated request to the Get Subscription Details endpoint and parses the value from WWW-Authenticate header.
func NewCliOAuthTokenProvider ¶
func NewCliOAuthTokenProvider(env azure.Environment, say func(string), tenantID string) oAuthTokenProvider
func NewDeviceFlowOAuthTokenProvider ¶
func NewDeviceFlowOAuthTokenProvider(env azure.Environment, say func(string), tenantID string) oAuthTokenProvider
func NewJWTOAuthTokenProvider ¶
func NewJWTOAuthTokenProvider(env azure.Environment, clientID, clientJWT, tenantID string) oAuthTokenProvider
func NewMSIOAuthTokenProvider ¶
func NewMSIOAuthTokenProvider(env azure.Environment, ClientID string) oAuthTokenProvider
func NewSecretOAuthTokenProvider ¶
func NewSecretOAuthTokenProvider(env azure.Environment, clientID, clientSecret, tenantID string) oAuthTokenProvider
func NormalizeLocation ¶
NormalizeLocation returns a normalized location string. Strings are converted to lower case and spaces are removed.
Types ¶
type AzureClientSet ¶
type AzureClientSet interface { MetadataClient() MetadataClientAPI DisksClient() computeapi.DisksClientAPI SnapshotsClient() computeapi.SnapshotsClientAPI ImagesClient() computeapi.ImagesClientAPI GalleryImagesClient() computeapi.GalleryImagesClientAPI GalleryImageVersionsClient() computeapi.GalleryImageVersionsClientAPI VirtualMachinesClient() computeapi.VirtualMachinesClientAPI VirtualMachineImagesClient() VirtualMachineImagesClientAPI VirtualMachineScaleSetVMsClient() computeapi.VirtualMachineScaleSetVMsClientAPI PollClient() autorest.Client // SubscriptionID returns the subscription ID that this client set was created for SubscriptionID() string }
func GetTestClientSet ¶
func GetTestClientSet(t *testing.T) (AzureClientSet, error)
type AzureClientSetMock ¶
type AzureClientSetMock struct { DisksClientMock computeapi.DisksClientAPI SnapshotsClientMock computeapi.SnapshotsClientAPI ImagesClientMock computeapi.ImagesClientAPI VirtualMachineImagesClientMock VirtualMachineImagesClientAPI VirtualMachinesClientMock computeapi.VirtualMachinesClientAPI VirtualMachineScaleSetVMsClientMock computeapi.VirtualMachineScaleSetVMsClientAPI GalleryImagesClientMock computeapi.GalleryImagesClientAPI GalleryImageVersionsClientMock computeapi.GalleryImageVersionsClientAPI PollClientMock autorest.Client MetadataClientMock MetadataClientAPI SubscriptionIDMock string }
AzureClientSetMock provides a generic mock for AzureClientSet
func (*AzureClientSetMock) DisksClient ¶
func (m *AzureClientSetMock) DisksClient() computeapi.DisksClientAPI
DisksClient returns a DisksClientAPI
func (*AzureClientSetMock) GalleryImageVersionsClient ¶
func (m *AzureClientSetMock) GalleryImageVersionsClient() computeapi.GalleryImageVersionsClientAPI
GalleryImageVersionsClient returns a GalleryImageVersionsClientAPI
func (*AzureClientSetMock) GalleryImagesClient ¶
func (m *AzureClientSetMock) GalleryImagesClient() computeapi.GalleryImagesClientAPI
GalleryImagesClient returns a GalleryImagesClientAPI
func (*AzureClientSetMock) ImagesClient ¶
func (m *AzureClientSetMock) ImagesClient() computeapi.ImagesClientAPI
ImagesClient returns a ImagesClientAPI
func (*AzureClientSetMock) MetadataClient ¶
func (m *AzureClientSetMock) MetadataClient() MetadataClientAPI
MetadataClient returns a MetadataClientAPI
func (*AzureClientSetMock) PollClient ¶
func (m *AzureClientSetMock) PollClient() autorest.Client
PollClient returns an autorest Client that can be used for polling async requests
func (*AzureClientSetMock) SnapshotsClient ¶
func (m *AzureClientSetMock) SnapshotsClient() computeapi.SnapshotsClientAPI
SnapshotsClient returns a SnapshotsClientAPI
func (*AzureClientSetMock) SubscriptionID ¶
func (m *AzureClientSetMock) SubscriptionID() string
SubscriptionID returns SubscriptionIDMock
func (*AzureClientSetMock) VirtualMachineImagesClient ¶
func (m *AzureClientSetMock) VirtualMachineImagesClient() VirtualMachineImagesClientAPI
VirtualMachineImagesClient returns a VirtualMachineImagesClientAPI
func (*AzureClientSetMock) VirtualMachineScaleSetVMsClient ¶
func (m *AzureClientSetMock) VirtualMachineScaleSetVMsClient() computeapi.VirtualMachineScaleSetVMsClientAPI
VirtualMachineScaleSetVMsClient returns a VirtualMachineScaleSetVMsClientAPI
func (*AzureClientSetMock) VirtualMachinesClient ¶
func (m *AzureClientSetMock) VirtualMachinesClient() computeapi.VirtualMachinesClientAPI
VirtualMachinesClient returns a VirtualMachinesClientAPI
type CompoundName ¶
type CompoundName []string
func (CompoundName) String ¶
func (n CompoundName) String() string
type ComputeInfo ¶
type ComputeInfo struct { Name string ResourceID string ResourceGroupName string SubscriptionID string Location string VmScaleSetName string }
ComputeInfo defines the Azure VM metadata that is used in Packer
func (ComputeInfo) GetResourceID ¶
func (ci ComputeInfo) GetResourceID() string
type Config ¶
type Config struct { // One of Public, China, Germany, or // USGovernment. Defaults to Public. Long forms such as // USGovernmentCloud and AzureUSGovernmentCloud are also supported. CloudEnvironmentName string `mapstructure:"cloud_environment_name" required:"false"` // The Hostname of the Azure Metadata Service // (for example management.azure.com), used to obtain the Cloud Environment // when using a Custom Azure Environment. This can also be sourced from the // ARM_METADATA_HOST Environment Variable. // Note: CloudEnvironmentName must be set to the requested environment // name in the list of available environments held in the metadata_host. MetadataHost string `mapstructure:"metadata_host" required:"false"` // The application ID of the AAD Service Principal. // Requires either `client_secret`, `client_cert_path` or `client_jwt` to be set as well. ClientID string `mapstructure:"client_id"` // A password/secret registered for the AAD SP. ClientSecret string `mapstructure:"client_secret"` // The path to a pem-encoded certificate that will be used to authenticate // as the specified AAD SP. ClientCertPath string `mapstructure:"client_cert_path"` // The timeout for the JWT Token when using a [client certificate](#client_cert_path). Defaults to 1 hour. ClientCertExpireTimeout time.Duration `mapstructure:"client_cert_token_timeout" required:"false"` // A JWT bearer token for client auth (RFC 7523, Sec. 2.2) that will be used // to authenticate the AAD SP. Provides more control over token the expiration // when using certificate authentication than when using `client_cert_path`. ClientJWT string `mapstructure:"client_jwt"` // The object ID for the AAD SP. Optional, will be derived from the oAuth token if left empty. ObjectID string `mapstructure:"object_id"` // The Active Directory tenant identifier with which your `client_id` and // `subscription_id` are associated. If not specified, `tenant_id` will be // looked up using `subscription_id`. TenantID string `mapstructure:"tenant_id" required:"false"` // The subscription to use. SubscriptionID string `mapstructure:"subscription_id"` // Flag to use Azure CLI authentication. Defaults to false. // CLI auth will use the information from an active `az login` session to connect to Azure and set the subscription id and tenant id associated to the signed in account. // If enabled, it will use the authentication provided by the `az` CLI. // Azure CLI authentication will use the credential marked as `isDefault` and can be verified using `az account show`. // Works with normal authentication (`az login`) and service principals (`az login --service-principal --username APP_ID --password PASSWORD --tenant TENANT_ID`). // Ignores all other configurations if enabled. UseAzureCLIAuth bool `mapstructure:"use_azure_cli_auth" required:"false"` // contains filtered or unexported fields }
Config allows for various ways to authenticate Azure clients. When `client_id` and `subscription_id` are specified, Packer will use the specified Azure Active Directory (AAD) Service Principal (SP). If only `subscription_id` is specified, Packer will try to interactively log on the current user (tokens will be cached). If none of these options are specified, Packer will attempt to use the Managed Identity and subscription of the VM that Packer is running on. This will only work if Packer is running on an Azure VM.
func (*Config) CloudEnvironment ¶
func (c *Config) CloudEnvironment() *azure.Environment
func (*Config) FillParameters ¶
FillParameters capture the user intent from the supplied parameter set in authType, retrieves the TenantID and CloudEnvironment if not specified. The SubscriptionID is also retrieved in case MSI auth is requested.
func (Config) GetServicePrincipalToken ¶
func (Config) GetServicePrincipalTokens ¶
func (c Config) GetServicePrincipalTokens(say func(string)) ( servicePrincipalToken *adal.ServicePrincipalToken, servicePrincipalTokenVault *adal.ServicePrincipalToken, err error)
func (*Config) SetDefaultValues ¶
CloudEnvironmentName is deprecated in favor of MetadataHost. This is retained for now to preserve backward compatability, but should eventually be removed.
func (Config) Validate ¶
func (c Config) Validate(errs *packersdk.MultiError)
type MetadataClientAPI ¶
type MetadataClientAPI interface {
GetComputeInfo() (*ComputeInfo, error)
}
MetadataClientAPI holds methods that Packer uses to get information about the current VM
func NewMetadataClient ¶
func NewMetadataClient() MetadataClientAPI
NewMetadataClient creates a new instance metadata client
type MetadataClientStub ¶
type MetadataClientStub struct {
ComputeInfo
}
MetadataClientStub is an easy way to put a test hook in DefaultMetadataClient
func (MetadataClientStub) GetComputeInfo ¶
func (s MetadataClientStub) GetComputeInfo() (*ComputeInfo, error)
GetComputeInfo implements MetadataClientAPI
type PlatformImage ¶
type PlatformImage struct {
Publisher, Offer, Sku, Version string
}
func ParsePlatformImageURN ¶
func ParsePlatformImageURN(urn string) (image *PlatformImage, err error)
func (PlatformImage) URN ¶
func (pi PlatformImage) URN() string
type Resource ¶
type Resource struct { Subscription string ResourceGroup string Provider string ResourceType CompoundName ResourceName CompoundName }
func ParseResourceID ¶
ParseResourceID parses an Azure resource ID
type VirtualMachineImagesClient ¶
type VirtualMachineImagesClient struct {
computeapi.VirtualMachineImagesClientAPI
}
func (VirtualMachineImagesClient) GetLatest ¶
func (c VirtualMachineImagesClient) GetLatest(ctx context.Context, publisher, offer, sku, location string) (*compute.VirtualMachineImageResource, error)
type VirtualMachineImagesClientAPI ¶
type VirtualMachineImagesClientAPI interface { computeapi.VirtualMachineImagesClientAPI // extensions GetLatest(ctx context.Context, publisher, offer, sku, location string) (*compute.VirtualMachineImageResource, error) }
Source Files ¶
- azure_client_set.go
- azure_client_set_mock.go
- config.go
- config_retriever.go
- detect_azure_linux.go
- devicelogin.go
- metadata.go
- normalize_location.go
- platform_image.go
- resource.go
- testclient.go
- tokenprovider.go
- tokenprovider_cert.go
- tokenprovider_cli.go
- tokenprovider_devicewflow.go
- tokenprovider_jwt.go
- tokenprovider_msi.go
- tokenprovider_secret.go