resources

package
v0.0.0-...-d9f4117 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Example (CreateTemplateDeployment)
groupName := config.GenerateGroupName("groups-template")
config.SetGroupName(groupName) // TODO: don't rely on globals
ctx, cancel := context.WithTimeout(context.Background(), 300*time.Second)
defer cancel()
defer Cleanup(ctx)

_, err := CreateGroup(ctx, config.GroupName())
if err != nil {
	util.LogAndPanic(err)
}

wd, _ := os.Getwd()
templateFile := filepath.Join(wd, "testdata", "template.json")
parametersFile := filepath.Join(wd, "testdata", "parameters.json")
deployName := "VMdeploy"

template, err := util.ReadJSON(templateFile)
if err != nil {
	return
}
params, err := util.ReadJSON(parametersFile)
if err != nil {
	return
}

_, err = ValidateDeployment(ctx, deployName, template, params)
if err != nil {
	util.LogAndPanic(err)
}
util.PrintAndLog("validated VM template deployment")

_, err = CreateDeployment(ctx, deployName, template, params)
if err != nil {
	util.LogAndPanic(err)
}
util.PrintAndLog("created VM template deployment")

ipName := (*params)["publicIPAddresses_QuickstartVM_ip_name"].(map[string]interface{})["value"].(string)
vmUser := (*params)["vm_user"].(map[string]interface{})["value"].(string)
vmPass := (*params)["vm_password"].(map[string]interface{})["value"].(string)

r, err := GetResource(ctx,
	"Microsoft.Network",
	"publicIPAddresses",
	ipName,
	"2018-01-01")
if err != nil {
	util.LogAndPanic(err)
}
util.PrintAndLog("got public IP info via get generic resource")

log.Printf("Log in with ssh: %s@%s, password: %s",
	vmUser,
	r.Properties.(map[string]interface{})["ipAddress"].(string),
	vmPass)
Output:

validated VM template deployment
created VM template deployment
got public IP info via get generic resource

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cleanup

func Cleanup(ctx context.Context)

Cleanup deletes the resource group created for the sample

func CreateDeployment

func CreateDeployment(ctx context.Context, deploymentName string, template, params *map[string]interface{}) (de resources.DeploymentExtended, err error)

CreateDeployment creates a template deployment using the referenced JSON files for the template and its parameters

func CreateGroup

func CreateGroup(ctx context.Context, groupName string) (resources.Group, error)

CreateGroup creates a new resource group named by env var

func CreateGroupWithAuthFile

func CreateGroupWithAuthFile(ctx context.Context, groupName string) (resources.Group, error)

CreateGroupWithAuthFile creates a new resource group. The client authorizer is set up based on an auth file created using the Azure CLI.

func DeleteAllGroupsWithPrefix

func DeleteAllGroupsWithPrefix(ctx context.Context, prefix string) (futures []resources.GroupsDeleteFuture, groups []string)

DeleteAllGroupsWithPrefix deletes all rescource groups that start with a certain prefix

func DeleteGroup

func DeleteGroup(ctx context.Context, groupName string) (result resources.GroupsDeleteFuture, err error)

DeleteGroup removes the resource group named by env var

func GetGroup

func GetGroup(ctx context.Context) (resources.Group, error)

GetGroup gets info on the resource group in use

func GetResource

func GetResource(ctx context.Context, resourceProvider, resourceType, resourceName, apiVersion string) (resources.GenericResource, error)

GetResource gets a resource, the generic way. The API version parameter overrides the API version in the SDK, this is needed because not all resources are supported on all API versions.

func ListGroups

ListGroups gets an interator that gets all resource groups in the subscription

func RegisterProvider

func RegisterProvider(ctx context.Context, provider string) (resources.Provider, error)

RegisterProvider registers an azure resource provider for the subscription

func ValidateDeployment

func ValidateDeployment(ctx context.Context, deploymentName string, template, params *map[string]interface{}) (valid resources.DeploymentValidateResult, err error)

ValidateDeployment validates the template deployments and their parameters are correct and will produce a successful deployment.GetResource

func WaitForDeleteCompletion

func WaitForDeleteCompletion(ctx context.Context, wg *sync.WaitGroup, futures []resources.GroupsDeleteFuture, groups []string)

WaitForDeleteCompletion concurrently waits for delete group operations to finish

func WithAPIVersion

func WithAPIVersion(apiVersion string) autorest.PrepareDecorator

WithAPIVersion returns a prepare decorator that changes the request's query for api-version This can be set up as a client's RequestInspector.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL