Skip to content

heaths/go-dotazure

Repository files navigation

Dotazure

releases reference ci

Locate and load environment variables defined when provisioning an Azure Developer CLI project.

Getting Started

If you do not already have an Azure Developer CLI (azd) project, you can create one:

azd init

After you define some resources e.g., an Azure Key Vault, you can provision those resources which will create a .env file with any output parameters:

azd up

Example

After azd up provisions resources and creates a .env file, you can call Load() to load those environment variables from the default environment e.g.,

package main

import (
    "errors"
    "fmt"
    "os"

    "github.com/heaths/go-dotazure"
)

func main() {
    if loaded, err := dotazure.Load(); err != nil {
        panic(err)
    } else if loaded {
        fmt.Fprintln(os.Stderr, "loaded environment variables")
    }

    // Assumes bicep contains e.g.
    //
    // output AZURE_KEYVAULT_URL string = kv.properties.vaultUri
    vaultURL, _ := os.LookupEnv("AZURE_KEYVAULT_URL")
    fmt.Printf("AZURE_KEYVAULT_URL=%q\n", vaultURL)
}

If you want to customize behavior, you can call Load() with various With* option functions.

License

Licensed under the MIT license.

About

Load environment variables from Azure Developer CLI environment

Topics

Resources

License

Stars

Watchers

Forks