Documentation
¶
Index ¶
- Constants
- Variables
- func AlphaSnakeUpper(name string) string
- func AlphaSnakeUpperFromCasing(name string) string
- func AzureSnakeCase(src string) string
- func BicepName(name string) string
- func BicepNameInfix(name string) string
- func CallFn(fn interface{}, funcName string, args []interface{}) (interface{}, error)
- func ContainerAppName(name string) string
- func ContainerAppSecretName(name string) string
- func EmitBicep(values map[string]string, emitter Resolver) (map[string]string, error)
- func EnvFormat(src string) string
- func EnvVarName(prefix string, varName string) string
- func EnvVars(prefix string, variables map[string]string) map[string]string
- func Eval(values map[string]string, env EvalEnv) (map[string]string, error)
- func ExecInfra(t *template.Template, spec InfraSpec, target string) error
- func ExecInfraFs(t *template.Template, spec InfraSpec) (*memfs.FS, error)
- func Execute(t *template.Template, name string, data any, dest string) error
- func FormatParameter(prefix string, indent string, value any) (string, error)
- func HasACA(services []ServiceSpec) bool
- func HasAppService(services []ServiceSpec) bool
- func IsACA(host HostKind) bool
- func IsAppService(host HostKind) bool
- func Load() (*template.Template, error)
- func RemoveDotAndDash(name string) string
- type AIModel
- type AIModelModel
- type AIModelReference
- type AISearch
- type AISearchReference
- type AiFoundryModel
- type AiFoundryModelSku
- type AiFoundrySpec
- type Backend
- type CosmosSqlDatabaseContainer
- type DatabaseCosmos
- type DatabaseCosmosMongo
- type DatabaseMysql
- type DatabasePostgres
- type DatabaseRedis
- type DatabaseReference
- type EvalEnv
- type EventHubs
- type ExistingResource
- type Expression
- type ExpressionVar
- type Frontend
- type FuncExprData
- type FuncMap
- type HostKind
- type InfraSpec
- type KeyVault
- type KeyVaultReference
- type Kind
- type LiteralExprData
- type Parameter
- type PropertyExprData
- type Resolver
- type ResourceMeta
- type RoleAssignment
- type RoleAssignmentScope
- type RoleAssignments
- type RuntimeInfo
- type ServiceBus
- type ServiceReference
- type ServiceSpec
- type SpecExprData
- type StorageAccount
- type StorageReference
- type VarExprData
- type VaultExprData
Constants ¶
const ( DotToken = "" SpecToken = "spec" VaultToken = "vault" )
const ( DotChar byte = '.' DoubleQuotes byte = '"' SingleQuotes byte = '\'' Space byte = ' ' )
Variables ¶
var Resources = []ResourceMeta{ { ResourceType: "Microsoft.App/containerApps", ApiVersion: "2023-05-01", StandardVarPrefix: "${upper .name}", Variables: map[string]string{ "baseUrl": "${.properties.configuration.ingress.fqdn}", }, }, { ResourceType: "Microsoft.App/managedEnvironments", ApiVersion: "2023-05-01", }, { ResourceType: "Microsoft.Cache/redis", ApiVersion: "2024-03-01", StandardVarPrefix: "REDIS", Variables: map[string]string{ "host": "${.properties.hostName}", "port": "6380", "password": "${vault.redis-password}", "url": "${vault.redis-url}", "endpoint": "${host}:${port}", }, }, { ResourceType: "Microsoft.CognitiveServices/accounts", ApiVersion: "2025-04-01-preview", }, { ResourceType: "Microsoft.CognitiveServices/accounts/deployments", ApiVersion: "2025-04-01-preview", ParentForEval: "Microsoft.CognitiveServices/accounts", StandardVarPrefix: "AZURE_OPENAI", Variables: map[string]string{ "endpoint": "${.properties.endpoint}", }, }, { ResourceType: "Microsoft.CognitiveServices/accounts/projects", ResourceKind: "AIServices", ApiVersion: "2025-04-01-preview", StandardVarPrefix: "AZURE_AI_PROJECT", Variables: map[string]string{ "endpoint": "${aiProjectEndpoint .properties.endpoints}", }, RoleAssignments: RoleAssignments{ Write: []RoleAssignment{ { Name: "AzureAIDeveloper", RoleDefinitionName: "Azure AI Developer", RoleDefinitionId: "64702f94-c441-49e6-a78b-ef80e0188fee", Scope: RoleAssignmentScopeGroup, }, { Name: "CognitiveServicesUser", RoleDefinitionName: "Cognitive Services User", RoleDefinitionId: "a97b65f3-24c7-4388-baec-2e87135dc908", Scope: RoleAssignmentScopeGroup, }, }, }, }, { ResourceType: "Microsoft.ContainerRegistry/registries", ApiVersion: "2023-06-01-preview", }, { ResourceType: "Microsoft.DBforMySQL/flexibleServers/databases", ApiVersion: "2023-12-30", StandardVarPrefix: "MYSQL", ParentForEval: "Microsoft.DBforMySQL/flexibleServers", Variables: map[string]string{ "database": "${spec.name}", "host": "${.properties.fullyQualifiedDomainName}", "username": "${.properties.administratorLogin}", "port": "3306", "password": "${vault.mysql-password}", "url": "mysql://${username}:${password}@${host}:${port}/${database}", }, }, { ResourceType: "Microsoft.DBforPostgreSQL/flexibleServers/databases", ApiVersion: "2022-12-01", StandardVarPrefix: "POSTGRES", ParentForEval: "Microsoft.DBforPostgreSQL/flexibleServers", Variables: map[string]string{ "database": "${spec.name}", "host": "${.properties.fullyQualifiedDomainName}", "username": "${.properties.administratorLogin}", "port": "5432", "password": "${vault.postgres-password}", "url": "postgresql://${username}:${password}@${host}:${port}/${database}", }, }, { ResourceType: "Microsoft.DocumentDB/databaseAccounts/sqlDatabases", ApiVersion: "2023-04-15", ParentForEval: "Microsoft.DocumentDB/databaseAccounts", StandardVarPrefix: "AZURE_COSMOS", Variables: map[string]string{ "endpoint": "${.properties.documentEndpoint}", }, }, { ResourceType: "Microsoft.DocumentDB/databaseAccounts/mongodbDatabases", ApiVersion: "2023-04-15", StandardVarPrefix: "MONGODB", Variables: map[string]string{ "url": "${vault.mongodb-url}", }, }, { ResourceType: "Microsoft.EventHub/namespaces", ApiVersion: "2024-01-01", StandardVarPrefix: "AZURE_EVENT_HUBS", Variables: map[string]string{ "name": "${.name}", "host": "${host .properties.serviceBusEndpoint}", }, RoleAssignments: RoleAssignments{ Write: []RoleAssignment{ { Name: "HubDataOwner", RoleDefinitionName: "Azure Event Hubs Data Owner", RoleDefinitionId: "f526a384-b230-433a-b45c-95f59c4a2dec", }, }, }, }, { ResourceType: "Microsoft.KeyVault/vaults", ApiVersion: "2022-07-01", StandardVarPrefix: "AZURE_KEY_VAULT", Variables: map[string]string{ "name": "${.name}", "endpoint": "${.properties.vaultUri}", }, RoleAssignments: RoleAssignments{ Read: []RoleAssignment{ { Name: "Reader", RoleDefinitionName: "Key Vault Secrets User", RoleDefinitionId: "4633458b-17de-408a-b874-0445c86b69e6", }, }, }, }, { ResourceType: "Microsoft.ManagedIdentity/userAssignedIdentities", ApiVersion: "2023-01-31", }, { ResourceType: "Microsoft.ServiceBus/namespaces", ApiVersion: "2022-10-01-preview", StandardVarPrefix: "AZURE_SERVICE_BUS", Variables: map[string]string{ "name": "${.name}", "host": "${host .properties.serviceBusEndpoint}", }, RoleAssignments: RoleAssignments{ Write: []RoleAssignment{ { Name: "BusDataOwner", RoleDefinitionName: "Azure Service Bus Data Owner", RoleDefinitionId: "090c5cfd-751d-490a-894a-3ce6f1109419", }, }, }, }, { ResourceType: "Microsoft.Storage/storageAccounts", ApiVersion: "2023-05-01", StandardVarPrefix: "AZURE_STORAGE", RoleAssignments: RoleAssignments{ Read: []RoleAssignment{ { Name: "Reader", RoleDefinitionName: "Storage Blob Data Reader", RoleDefinitionId: "2a2b9908-6ea1-4ae2-8e65-a410df84e7d1", }, }, Write: []RoleAssignment{ { Name: "Contributor", RoleDefinitionName: "Storage Blob Data Contributor", RoleDefinitionId: "ba92f5b4-2d11-453d-a403-e96b0029c9fe", }, }, }, Variables: map[string]string{ "accountName": "${.name}", "blobEndpoint": "${.properties.primaryEndpoints.blob}", }, }, { ResourceType: "Microsoft.Search/searchServices", ApiVersion: "2025-02-01-preview", StandardVarPrefix: "AZURE_AI_SEARCH", Variables: map[string]string{ "endpoint": "${.properties.endpoint}", }, RoleAssignments: RoleAssignments{ Write: []RoleAssignment{ { Name: "IdxContributor", RoleDefinitionName: "Search Index Data Contributor", RoleDefinitionId: "8ebe5a00-799e-43f5-93ac-243d3dce84a7", }, { Name: "SvcContributor", RoleDefinitionName: "Search Service Contributor", RoleDefinitionId: "7ca78c08-252a-4471-8644-bb5ff32d4ba0", }, }, }, }, }
List of resources that are supported by scaffold.
Functions ¶
func AlphaSnakeUpper ¶
AlphaSnakeUpper returns a name in upper-snake case alphanumeric name separated only by underscores.
Non-alphanumeric characters are discarded, while consecutive separators ('-', '_', and '.') are treated as a single underscore separator.
func AlphaSnakeUpperFromCasing ¶
AlphaSnakeUpperFromCasing transforms a camel case or pascal case name into an upper-snake case name.
func AzureSnakeCase ¶
func BicepName ¶
BicepName returns a name suitable for use as a bicep variable name.
The name is converted to camel case, with treatment for underscore or dash separators, and all non-alphanumeric characters are removed.
func BicepNameInfix ¶
BicepNameInfix is like BicepName, except that the first character is upper-cased for infix use.
func ContainerAppName ¶
ContainerAppName returns a suitable name a container app resource.
The name is treated to only contain alphanumeric and dash characters, with no repeated dashes, and no dashes as the first or last character.
func ContainerAppSecretName ¶
ContainerAppSecretName returns a suitable name a container app secret name.
The name is treated to only contain lowercase alphanumeric and dash characters, and must start and end with an alphanumeric character
func EnvFormat ¶
EnvFormat takes an input parameter like `fooParam` which is expected to be in camel case and returns it in upper snake case with env var template, like `${AZURE_FOO_PARAM}`.
func EnvVarName ¶
EnvVarName creates an environment variable name by concatenating the prefix and the variable name.
func EnvVars ¶
EnvVars creates a map of environment variables with the given prefix and variable names.
func Eval ¶
Eval evaluates the given values using the provided environment. It replaces the expressions in the values with their resolved values. It returns the resolved values as a map.
The function supports the following types of expressions: - Variable references, ${varName} - ARM Property expressions, ${.property.path} - Spec expressions, ${spec.property.path} - Literal expressions, ${"literal"} (for use in function expressions) - Vault expressions, ${vault.secretName} OR ${vault.} -- the latter will use the key as the secret name - Function expressions (only a single-level of nesting), ${replace "management.azure.com/" spec.id}
The function also supports nested expressions and circular dependencies.
func ExecInfra ¶
ExecInfra scaffolds infrastructure files for the given spec, using the loaded templates in t. The resulting files are written to the target directory.
func ExecInfraFs ¶
ExecInfraFs scaffolds infrastructure files for the given spec, using the loaded templates in t. The resulting files are written to the in-memory filesystem.
func Execute ¶
Execute applies the template associated with t that has the given name to the specified data object and writes the output to the dest path on the filesystem.
func FormatParameter ¶
Formats a parameter value for use in a bicep file. If the value is a string, it is quoted inline with no indentation. Otherwise, the value is marshaled with indentation specified by prefix and indent.
func HasACA ¶
func HasACA(services []ServiceSpec) bool
func HasAppService ¶
func HasAppService(services []ServiceSpec) bool
func IsAppService ¶
func Load ¶
Load loads all templates as a template.Template.
To execute a named template, call Execute with the defined name.
func RemoveDotAndDash ¶
Types ¶
type AIModel ¶
type AIModel struct { Name string Model AIModelModel }
AIModel represents a deployed, ready to use AI model.
type AIModelModel ¶
type AIModelModel struct { // The name of the underlying model. Name string // The version of the underlying model. Version string }
AIModelModel represents a model that backs the AIModel.
type AIModelReference ¶
type AIModelReference struct {
Name string
}
type AISearchReference ¶
type AISearchReference struct { }
type AiFoundryModel ¶
type AiFoundryModel struct { AIModelModel Format string `yaml:"format,omitempty"` Sku AiFoundryModelSku `yaml:"sku,omitempty"` }
type AiFoundryModelSku ¶
type AiFoundrySpec ¶
type AiFoundrySpec struct { Name string Models []AiFoundryModel }
AIModel represents a deployed, ready to use AI model.
type Backend ¶
type Backend struct {
Frontends []ServiceReference
}
type DatabaseCosmos ¶
type DatabaseCosmos struct { DatabaseName string Containers []CosmosSqlDatabaseContainer }
type DatabaseCosmosMongo ¶
type DatabaseCosmosMongo struct {
DatabaseName string
}
type DatabaseMysql ¶
type DatabaseMysql struct {
DatabaseName string
}
type DatabasePostgres ¶
type DatabasePostgres struct {
DatabaseName string
}
type DatabaseRedis ¶
type DatabaseRedis struct { }
type DatabaseReference ¶
type DatabaseReference struct {
DatabaseName string
}
type EvalEnv ¶
type EvalEnv struct { // ResourceSpec is the azure.yaml resource spec. ResourceSpec *yaml.Node // ArmResource is the Azure resource representation. ArmResource string // VaultSecret is a function that resolves a secret from the vault. VaultSecret func(string) (string, error) // FuncMap is a map of function names to their implementations. FuncMap FuncMap }
type ExistingResource ¶
type ExistingResource struct { // The unique logical name of the existing resource in the infra scope. Name string // The resource ID of the resource. ResourceIdEnvVar string // The resource type of the resource. This should match the type contained in the resource ID. ResourceType string // The API version of the resource to look up values. ApiVersion string // Role assignment RoleAssignments []RoleAssignment }
type Expression ¶
type Expression struct { // The kind of expression. Kind Kind // The data associated with the kind of expression. Data any // The finalized value of the expression. Value string // The start and end positions of the expression in the template. Start int End int // contains filtered or unexported fields }
func Parse ¶
func Parse(s *string) ([]*Expression, error)
func (*Expression) Replace ¶
func (e *Expression) Replace(val string)
type ExpressionVar ¶
type ExpressionVar struct { // The name of the variable Key string // The Value of the expression // // When initially created, this is the raw Value of the expression. // When the expression is resolved, this is the resolved Value. Value string // The Expressions parsed from the value. Can be nil if the value does not contain any Expressions. Expressions []*Expression // contains filtered or unexported fields }
ExpressionVar represents an expression variable to be resolved, and its final output value.
type Frontend ¶
type Frontend struct {
Backends []ServiceReference
}
type FuncExprData ¶
type FuncExprData struct { // The name of the function FuncName string // The arguments to the function Args []*Expression }
New struct for function expression data
type FuncMap ¶
FuncMap is the type of the map defining the mapping from names to functions. Each function must have either a single return value, or two return values of which the second has type error. In that case, if the second (error) return value evaluates to non-nil during execution, execution terminates and Eval returns that error.
func BaseEmitBicepFuncMap ¶
func BaseEmitBicepFuncMap() FuncMap
BaseEmitFuncMap returns a map of functions that can be used for bicep emitting purposes.
The functions are similar to the base function map, except they are compile-time expressions that operate on the string symbols of the variables, rather than their resolved values. The functions are not evaluated at runtime, but rather emitted as part of the Bicep template.
func BaseEvalFuncMap ¶
func BaseEvalFuncMap() FuncMap
BaseEvalFuncMap returns a map of functions that can be used for evaluation purposes.
The functions are evaluated at runtime against live Azure resources.
type InfraSpec ¶
type InfraSpec struct { Parameters []Parameter Services []ServiceSpec // Existing resources for declaration purposes. // These are resources that are already created and should be used by the // current deployment for referencing Existing []ExistingResource // Databases to create DbPostgres *DatabasePostgres DbMySql *DatabaseMysql DbCosmosMongo *DatabaseCosmosMongo DbCosmos *DatabaseCosmos DbRedis *DatabaseRedis // Key vault KeyVault *KeyVault // Messaging services ServiceBus *ServiceBus EventHubs *EventHubs // Storage account StorageAccount *StorageAccount // ai models AIModels []AIModel // ai foundry models AiFoundryProject *AiFoundrySpec AISearch *AISearch }
type KeyVaultReference ¶
type KeyVaultReference struct { }
type LiteralExprData ¶
type LiteralExprData struct { // The literal value Value string }
type PropertyExprData ¶
type PropertyExprData struct { // The dotted property path PropertyPath string }
type Resolver ¶
type Resolver func(value *ExpressionVar, results map[string]string) error
Resolver is a function that resolves a variable expression. It takes the expression value, and the current results map. The function should evaluate expressions within value and call Replace.
type ResourceMeta ¶
type ResourceMeta struct { // ResourceType is the resource type. ResourceType string // ResourceKind is the resource kind. ResourceKind string // ParentForEval is the parent resource used for evaluation. // Note: This is temporarily used for displaying sub-resources and can be moved into the expression language later. ParentForEval string // ApiVersion is the api version for the resource. ApiVersion string // StandardVarPrefix is the standard variable prefix for the resource. StandardVarPrefix string // Variables are the variables exposed by this resource for connecting to application code. // // To evaluate the actual values, see [Eval]. Variables map[string]string // RoleAssignments are related role assignments the resource. RoleAssignments RoleAssignments }
ResourceMeta contains the metadata for a resource.
func ResourceMetaFromType ¶
func ResourceMetaFromType(resourceType string) (ResourceMeta, bool)
type RoleAssignment ¶
type RoleAssignment struct { // A name for the role assignment that is unique within the resource. // This should be a Bicep-friendly name. Name string // The Microsoft defined role definition ID. // See https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles RoleDefinitionId string // Friendly name for display purposes. RoleDefinitionName string // The Scope of the role assignment. // This is the resource ID of the resource to which the role assignment applies. // When empty, the scope is the resource itself. Scope RoleAssignmentScope }
type RoleAssignmentScope ¶
type RoleAssignmentScope int32
const ( RoleAssignmentScopeResource RoleAssignmentScope = iota RoleAssignmentScopeGroup )
type RoleAssignments ¶
type RoleAssignments struct { Read []RoleAssignment Write []RoleAssignment }
type RuntimeInfo ¶
type ServiceBus ¶
type ServiceReference ¶
type ServiceReference struct {
Name string
}
type ServiceSpec ¶
type ServiceSpec struct { Name string Port int Host HostKind Env map[string]string // App Service specific configuration Runtime *RuntimeInfo StartupCommand string // Front-end properties. Frontend *Frontend // Back-end properties Backend *Backend // Key vault KeyVault *KeyVaultReference // Connection to a database DbPostgres *DatabaseReference DbMySql *DatabaseReference DbCosmosMongo *DatabaseReference DbCosmos *DatabaseReference DbRedis *DatabaseReference StorageAccount *StorageReference // AI model connections AIModels []AIModelReference // Messaging services ServiceBus *ServiceBus EventHubs *EventHubs AiFoundryProject *AiFoundrySpec AISearch *AISearchReference // Existing resource bindings Existing []*ExistingResource }
type SpecExprData ¶
type SpecExprData struct { // The dotted property path PropertyPath string }
type StorageAccount ¶
type StorageAccount struct {
Containers []string
}
type StorageReference ¶
type StorageReference struct { }
type VarExprData ¶
type VarExprData struct { // The name of the variable Name string }
type VaultExprData ¶
type VaultExprData struct { // The vault secret path to the value of the expression SecretPath string }