Documentation
¶
Index ¶
- Constants
- Variables
- func CleanName(name string) string
- func InvalidEnvironmentNameError(name string) error
- func IsValidEnvironmentName(name string) bool
- func Key(name string) string
- type DataStore
- type Description
- type Environment
- func (e *Environment) Dotenv() map[string]string
- func (e *Environment) DotenvDelete(key string)
- func (e *Environment) DotenvSet(key string, value string)
- func (e *Environment) Environ() []string
- func (e *Environment) GetLocation() string
- func (e *Environment) GetServiceProperty(serviceName string, propertyName string) string
- func (e *Environment) GetSubscriptionId() string
- func (e *Environment) GetTenantId() string
- func (e *Environment) Getenv(key string) string
- func (e *Environment) LookupEnv(key string) (string, bool)
- func (e *Environment) Name() string
- func (e *Environment) SetLocation(location string)
- func (e *Environment) SetServiceProperty(serviceName string, propertyName string, value string)
- func (e *Environment) SetSubscriptionId(id string)
- type EnvironmentInitError
- type EnvironmentResolver
- type LocalDataStore
- type LocalFileDataStore
- func (fs *LocalFileDataStore) ConfigPath(env *Environment) string
- func (fs *LocalFileDataStore) Delete(ctx context.Context, name string) error
- func (fs *LocalFileDataStore) EnvPath(env *Environment) string
- func (fs *LocalFileDataStore) Get(ctx context.Context, name string) (*Environment, error)
- func (fs *LocalFileDataStore) List(ctx context.Context) ([]*contracts.EnvListEnvironment, error)
- func (fs *LocalFileDataStore) Reload(ctx context.Context, env *Environment) error
- func (fs *LocalFileDataStore) Save(ctx context.Context, env *Environment, options *SaveOptions) error
- type Manager
- type RemoteDataStore
- type RemoteKind
- type SaveOptions
- type Spec
- type StorageBlobDataStore
- func (fs *StorageBlobDataStore) ConfigPath(env *Environment) string
- func (sbd *StorageBlobDataStore) Delete(ctx context.Context, name string) error
- func (fs *StorageBlobDataStore) EnvPath(env *Environment) string
- func (sbd *StorageBlobDataStore) Get(ctx context.Context, name string) (*Environment, error)
- func (sbd *StorageBlobDataStore) List(ctx context.Context) ([]*contracts.EnvListEnvironment, error)
- func (sbd *StorageBlobDataStore) Reload(ctx context.Context, env *Environment) error
- func (sbd *StorageBlobDataStore) Save(ctx context.Context, env *Environment, options *SaveOptions) error
- type TargetResource
- func (ds *TargetResource) Metadata() map[string]string
- func (ds *TargetResource) ResourceGroupName() string
- func (ds *TargetResource) ResourceName() string
- func (ds *TargetResource) ResourceType() string
- func (ds *TargetResource) SetMetadata(metadata map[string]string)
- func (ds *TargetResource) SubscriptionId() string
Constants ¶
const AksClusterEnvVarName = "AZURE_AKS_CLUSTER_NAME"
AksClusterEnvVarName is the name of they key used to store the endpoint of the AKS cluster to push to.
const AppServiceAspireDashboardUrlEnvVarName = "AZURE_APP_SERVICE_DASHBOARD_URI"
AppServiceAspireDashboardUrlEnvVarName is the name of the environment variable that specifies the url for the App Service Aspire Dashboard.
const AzdInitialEnvironmentConfigName = "AZD_INITIAL_ENVIRONMENT_CONFIG"
AzdInitialEnvironmentConfigName is part of a strategy to re-construct AZD environment in CI/CD from an initial state. This strategy was introduced for templates which takes input parameters. Parameters are saved to azd's environment configuration (.azure/env-name/config.json). This file is not committed to source control, so the saved values can't be used during CI/CD. AZD uses AZD_INITIAL_ENVIRONMENT_CONFIG to smuggle all saved parameters into a CI/CD secret and use it to create the environment configuration file (the first time AZD runs and creates a new environment).
While AZD_INITIAL_ENVIRONMENT_CONFIG is still supported for backwards compatibility, it is deprecated. The currently strategy is to create individual variables or secrets for the CI/CD pipeline depending on the parameter configuration.
const ConfigFileName = "config.json"
const ContainerEnvironmentEndpointEnvVarName = "AZURE_CONTAINER_APPS_ENVIRONMENT_DEFAULT_DOMAIN"
ContainerEnvironmentEndpointEnvVarName is the name of the environment variable that specifies the default domain for Azure Container Apps environments.
const ContainerRegistryEndpointEnvVarName = "AZURE_CONTAINER_REGISTRY_ENDPOINT"
ContainerRegistryEndpointEnvVarName is the name of they key used to store the endpoint of the container registry to push to.
const DotEnvFileName = ".env"
const EnvNameEnvVarName = "AZURE_ENV_NAME"
EnvNameEnvVarName is the name of the key used to store the envname property in the environment.
const LocationEnvVarName = "AZURE_LOCATION"
LocationEnvVarName is the name of the key used to store the location property in the environment.
const PlatformTypeEnvVarName = "AZD_PLATFORM_TYPE"
PlatformTypeEnvVarName is the name of the key used to store the current azd platform type
const PrincipalIdEnvVarName = "AZURE_PRINCIPAL_ID"
PrincipalIdEnvVarName is the name of they key used to store the id of a principal in the environment.
const PrincipalTypeEnvVarName = "AZURE_PRINCIPAL_TYPE"
PrincipalTypeEnvVarName is the name of they key used to store the type of a principal in the environment.
const ResourceGroupEnvVarName = "AZURE_RESOURCE_GROUP"
ResourceGroupEnvVarName is the name of the azure resource group that should be used for deployments
const SubscriptionIdEnvVarName = "AZURE_SUBSCRIPTION_ID"
SubscriptionIdEnvVarName is the name of they key used to store the subscription id property in the environment.
const TenantIdEnvVarName = "AZURE_TENANT_ID"
TenantIdEnvVarName is the tenant that owns the subscription
Variables ¶
var ( // Error returned when an environment with the specified name already exists ErrExists = errors.New("environment already exists") // Error returned when an environment with a specified name cannot be found ErrNotFound = errors.New("environment not found") // Error returned when an environment name is not specified ErrNameNotSpecified = errors.New("environment not specified") // Error returned when the default environment cannot be found ErrDefaultEnvironmentNotFound = errors.New("default environment not found") )
var ( ErrAccessDenied = errors.New("access denied connecting Azure Blob Storage container.") ErrInvalidContainer = errors.New("storage container name is invalid.") )
var EnvironmentNameMaxLength = 64
The maximum length of an environment name.
var EnvironmentNameRegexp = regexp.MustCompile(`^[a-zA-Z0-9-\(\)_\.]{1,64}$`)
Same restrictions as a deployment name (ref: https://docs.microsoft.com/azure/azure-resource-manager/management/resource-name-rules#microsoftresources)
var ValidRemoteKinds = []string{ string(RemoteKindAzureBlobStorage), }
Functions ¶
func CleanName ¶
CleanName returns a version of [name] where all characters not allowed in an environment name have been replaced with hyphens
func InvalidEnvironmentNameError ¶ added in v1.23.14
InvalidEnvironmentNameError returns a standardized error for an invalid environment name.
func IsValidEnvironmentName ¶
Types ¶
type DataStore ¶
type DataStore interface {
// Gets the path to the environment .env file
EnvPath(env *Environment) string
// Gets the path to the environment JSON config file
ConfigPath(env *Environment) string
// Gets a list of all environments within the stat store
List(ctx context.Context) ([]*contracts.EnvListEnvironment, error)
// Gets the environment instance for the specified environment name
Get(ctx context.Context, name string) (*Environment, error)
// Reloads the environment from the persistent data store
Reload(ctx context.Context, env *Environment) error
// Saves the environment to the persistent data store
Save(ctx context.Context, env *Environment, options *SaveOptions) error
// Deletes the environment from the persistent data store
Delete(ctx context.Context, name string) error
}
type Description ¶
type Description struct {
// The name of the environment
Name string
// The path to the local .env file for the environment. Useful for IDEs like VS / VSCode
DotEnvPath string
// Specifies when the environment exists locally
HasLocal bool
// Specifies when the environment exists remotely
HasRemote bool
// Specifies when the environment is the default environment
IsDefault bool
}
Description is a metadata description of an environment returned for the `azd env list` command
type Environment ¶
type Environment struct {
// Config is environment specific config
Config config.Config
// contains filtered or unexported fields
}
The zero value of an Environment is not valid. Use New to create one. When writing tests, [Ephemeral] and [EphemeralWithValues] are useful to create environments which are not persisted to disk.
func New ¶
func New(name string) *Environment
New returns a new environment with the specified name.
func NewWithValues ¶
func NewWithValues(name string, values map[string]string) *Environment
NewWithValues returns an ephemeral environment (i.e. not backed by a data store) with a set of values. Useful for testing. The name parameter is added to the environment with the AZURE_ENV_NAME key, replacing an existing value in the provided values map. A nil values is treated the same way as an empty map.
func (*Environment) Dotenv ¶
func (e *Environment) Dotenv() map[string]string
Dotenv returns a copy of the key value pairs from the .env file in the environment.
func (*Environment) DotenvDelete ¶
func (e *Environment) DotenvDelete(key string)
DotenvDelete removes the given key from the .env file in the environment, it is a no-op if the key does not exist. [Save] should be called to ensure this change is persisted.
func (*Environment) DotenvSet ¶
func (e *Environment) DotenvSet(key string, value string)
DotenvSet sets the value of [key] to [value] in the .env file associated with the environment. [Save] should be called to ensure this change is persisted.
func (*Environment) Environ ¶
func (e *Environment) Environ() []string
Creates a slice of key value pairs, based on the entries in the `.env` file like `KEY=VALUE` that can be used to pass into command runner or similar constructs.
func (*Environment) GetLocation ¶
func (e *Environment) GetLocation() string
GetLocation is shorthand for Getenv(LocationEnvVarName)
func (*Environment) GetServiceProperty ¶
func (e *Environment) GetServiceProperty(serviceName string, propertyName string) string
GetServiceProperty is shorthand for Getenv(SERVICE_$SERVICE_NAME_$PROPERTY_NAME)
func (*Environment) GetSubscriptionId ¶
func (e *Environment) GetSubscriptionId() string
GetSubscriptionId is shorthand for Getenv(SubscriptionIdEnvVarName)
func (*Environment) GetTenantId ¶
func (e *Environment) GetTenantId() string
GetTenantId is shorthand for Getenv(TenantIdEnvVarName)
func (*Environment) Getenv ¶
func (e *Environment) Getenv(key string) string
Getenv behaves like os.Getenv, except that any keys in the `.env` file associated with this environment are considered first.
func (*Environment) LookupEnv ¶
func (e *Environment) LookupEnv(key string) (string, bool)
LookupEnv behaves like os.LookupEnv, except that any keys in the `.env` file associated with this environment are considered first.
func (*Environment) Name ¶
func (e *Environment) Name() string
Name gets the name of the environment If empty will fallback to the value of the AZURE_ENV_NAME environment variable
func (*Environment) SetLocation ¶
func (e *Environment) SetLocation(location string)
SetLocation is shorthand for DotenvSet(LocationEnvVarName, location)
func (*Environment) SetServiceProperty ¶
func (e *Environment) SetServiceProperty(serviceName string, propertyName string, value string)
Sets the value of a service-namespaced property in the environment.
func (*Environment) SetSubscriptionId ¶
func (e *Environment) SetSubscriptionId(id string)
SetLocation is shorthand for DotenvSet(SubscriptionIdEnvVarName, location)
type EnvironmentInitError ¶
type EnvironmentInitError struct {
Name string
}
func NewEnvironmentInitError ¶
func NewEnvironmentInitError(envName string) *EnvironmentInitError
func (*EnvironmentInitError) Error ¶
func (err *EnvironmentInitError) Error() string
type EnvironmentResolver ¶
type EnvironmentResolver func(ctx context.Context) (*Environment, error)
type LocalDataStore ¶
type LocalDataStore DataStore
func NewLocalFileDataStore ¶
func NewLocalFileDataStore(azdContext *azdcontext.AzdContext, configManager config.FileConfigManager) LocalDataStore
NewLocalFileDataStore creates a new LocalFileDataStore instance
type LocalFileDataStore ¶
type LocalFileDataStore struct {
// contains filtered or unexported fields
}
LocalFileDataStore is a DataStore implementation that stores environment data in the local file system.
func (*LocalFileDataStore) ConfigPath ¶
func (fs *LocalFileDataStore) ConfigPath(env *Environment) string
ConfigPath returns the path to the config.json file for the given environment
func (*LocalFileDataStore) Delete ¶
func (fs *LocalFileDataStore) Delete(ctx context.Context, name string) error
func (*LocalFileDataStore) EnvPath ¶
func (fs *LocalFileDataStore) EnvPath(env *Environment) string
Path returns the path to the .env file for the given environment
func (*LocalFileDataStore) Get ¶
func (fs *LocalFileDataStore) Get(ctx context.Context, name string) (*Environment, error)
Get returns the environment instance for the specified environment name
func (*LocalFileDataStore) List ¶
func (fs *LocalFileDataStore) List(ctx context.Context) ([]*contracts.EnvListEnvironment, error)
List returns a list of all environments within the data store
func (*LocalFileDataStore) Reload ¶
func (fs *LocalFileDataStore) Reload(ctx context.Context, env *Environment) error
Reload reloads the environment from the persistent data store
func (*LocalFileDataStore) Save ¶
func (fs *LocalFileDataStore) Save(ctx context.Context, env *Environment, options *SaveOptions) error
Save saves the environment to the persistent data store
type Manager ¶
type Manager interface {
Create(ctx context.Context, spec Spec) (*Environment, error)
// Loads the environment with the given name.
// If the name is empty, the user is prompted to select or create an environment.
// If the environment does not exist, the user is prompted to create it.
LoadOrInitInteractive(ctx context.Context, name string) (*Environment, error)
List(ctx context.Context) ([]*Description, error)
// Get returns the existing environment with the given name.
// If the environment specified by the given name does not exist, ErrNotFound is returned.
Get(ctx context.Context, name string) (*Environment, error)
Save(ctx context.Context, env *Environment) error
SaveWithOptions(ctx context.Context, env *Environment, options *SaveOptions) error
Reload(ctx context.Context, env *Environment) error
// Delete deletes the environment from local storage.
Delete(ctx context.Context, name string) error
EnvPath(env *Environment) string
ConfigPath(env *Environment) string
// InvalidateEnvCache invalidates the state cache for the given environment
InvalidateEnvCache(ctx context.Context, envName string) error
// GetStateCacheManager returns the state cache manager for accessing cached state
GetStateCacheManager() *state.StateCacheManager
}
Manager is the interface used for managing instances of environments
func NewManager ¶
func NewManager( serviceLocator ioc.ServiceLocator, azdContext *azdcontext.AzdContext, console input.Console, local LocalDataStore, remoteConfig *state.RemoteConfig, ) (Manager, error)
NewManager creates a new Manager instance
type RemoteDataStore ¶
type RemoteDataStore DataStore
func NewStorageBlobDataStore ¶
func NewStorageBlobDataStore(configManager config.Manager, blobClient storage.BlobClient) RemoteDataStore
type RemoteKind ¶
type RemoteKind string
const (
RemoteKindAzureBlobStorage RemoteKind = "AzureBlobStorage"
)
type SaveOptions ¶
type SaveOptions struct {
// Whether or not the environment is new
IsNew bool
}
SaveOptions provide additional metadata for the save operation
type Spec ¶
type Spec struct {
Name string
Subscription string
Location string
// suggest is the name that is offered as a suggestion if we need to prompt the user for an environment name.
Examples []string
}
Spec is the specification for creating a new environment
type StorageBlobDataStore ¶
type StorageBlobDataStore struct {
// contains filtered or unexported fields
}
func (*StorageBlobDataStore) ConfigPath ¶
func (fs *StorageBlobDataStore) ConfigPath(env *Environment) string
ConfigPath returns the path to the config.json file for the given environment
func (*StorageBlobDataStore) Delete ¶
func (sbd *StorageBlobDataStore) Delete(ctx context.Context, name string) error
func (*StorageBlobDataStore) EnvPath ¶
func (fs *StorageBlobDataStore) EnvPath(env *Environment) string
EnvPath returns the path to the .env file for the given environment
func (*StorageBlobDataStore) Get ¶
func (sbd *StorageBlobDataStore) Get(ctx context.Context, name string) (*Environment, error)
func (*StorageBlobDataStore) List ¶
func (sbd *StorageBlobDataStore) List(ctx context.Context) ([]*contracts.EnvListEnvironment, error)
func (*StorageBlobDataStore) Reload ¶
func (sbd *StorageBlobDataStore) Reload(ctx context.Context, env *Environment) error
func (*StorageBlobDataStore) Save ¶
func (sbd *StorageBlobDataStore) Save(ctx context.Context, env *Environment, options *SaveOptions) error
type TargetResource ¶
type TargetResource struct {
// contains filtered or unexported fields
}
func NewTargetResource ¶
func NewTargetResource( subscriptionId string, resourceGroupName string, resourceName string, resourceType string, ) *TargetResource
func (*TargetResource) Metadata ¶
func (ds *TargetResource) Metadata() map[string]string
func (*TargetResource) ResourceGroupName ¶
func (ds *TargetResource) ResourceGroupName() string
func (*TargetResource) ResourceName ¶
func (ds *TargetResource) ResourceName() string
func (*TargetResource) ResourceType ¶
func (ds *TargetResource) ResourceType() string
func (*TargetResource) SetMetadata ¶
func (ds *TargetResource) SetMetadata(metadata map[string]string)
func (*TargetResource) SubscriptionId ¶
func (ds *TargetResource) SubscriptionId() string