예제 #1
0
func main() {

	groupName := "armtestgroup"
	groupLocation := "West US"

	arm, err := helpers.AuthenticateForARM()
	if err != nil {
		fmt.Printf("Failed to authenticate: '%s'\n", err.Error())
		return
	}

	arm.RequestInspector = helpers.WithInspection()
	arm.ResponseInspector = helpers.ByInspecting()

	rgc := arm.ResourceGroups()

	params := resources.ResourceGroup{Name: &groupName, Location: &groupLocation}

	group, err := rgc.CreateOrUpdate(groupName, params)
	if err != nil {
		fmt.Printf("Failed to create resource group '%s' in location '%s': '%s'\n", groupName, groupLocation, err.Error())
		return
	}

	fmt.Printf("Created resource group '%s'\n", *group.Name)
}
예제 #2
0
func main() {

	groupName := "createvm01"
	groupLocation := "West US"

	var group resources.ResourceGroup
	var subnet network.Subnet
	var nic network.Interface
	var avset compute.AvailabilitySet

	client, err := helpers.AuthenticateForARM()
	if err != nil {
		fmt.Printf("Failed to authenticate: '%s'\n", err.Error())
		return
	}

	client.RequestInspector = helpers.WithInspection()
	client.ResponseInspector = helpers.ByInspecting()

	group, err = createResourceGroup(groupName, groupLocation, client)

	if err != nil {
		fmt.Printf("ERROR:'%s'\n", err.Error())
		return
	}

	if err := createStorageAccount(group, client); err != nil {
		fmt.Printf("ERROR: '%s'\n", err.Error())
		return
	}

	if avset, err = createAvailabilitySet(group, client); err != nil {
		fmt.Printf("ERROR: '%s'\n", err.Error())
		return
	}

	if subnet, err = createNetwork(group, client); err != nil {
		fmt.Printf("ERROR: '%s'\n", err.Error())
		return
	}

	if nic, err = createNetworkInterface("01", group, subnet, client); err != nil {
		fmt.Printf("ERROR: '%s'\n", err.Error())
		return
	}

	if err := createVirtualMachine(group, "vm001", "admin", "foobar1234", avset, nic, client); err != nil {
		fmt.Printf("ERROR: '%s'\n", err.Error())
		return
	}
}
예제 #3
0
func main() {

	name := "storage-account-name"

	c, err := helpers.LoadCredentials()
	if err != nil {
		log.Fatalf("Error: %v", err)
	}

	sid := c["subscriptionID"]
	tid := c["tenantID"]
	cid := c["clientID"]
	secret := c["clientSecret"]

	spt, err := azure.NewServicePrincipalToken(cid, secret, tid, azure.AzureResourceManagerScope)
	if err != nil {
		log.Fatalf("Error: %v", err)
	}

	arm := arm.NewClient(sid, spt)
	arm.RequestInspector = helpers.WithInspection()
	arm.ResponseInspector = helpers.ByInspecting()

	ac := arm.StorageAccounts()

	cna, err := ac.CheckNameAvailability(
		storage.AccountCheckNameAvailabilityParameters{
			Name: to.StringPtr(name),
			Type: to.StringPtr("Microsoft.Storage/storageAccounts")})

	if err != nil {
		log.Fatalf("Error: %v", err)
	} else {
		if to.Bool(cna.NameAvailable) {
			fmt.Printf("The name '%s' is available\n", name)
		} else {
			fmt.Printf("The name '%s' is unavailable because %s\n", name, to.String(cna.Message))
		}
	}
}
예제 #4
0
func main() {

	if len(os.Args) == 2 && os.Args[1] == "--help" {
		fmt.Println("usage: deploy [parameter-file-name [template-file-name]]")
		return
	}

	deploymentName := "simplelinux"
	groupName := "templatetests"
	groupLocation := "West US"

	arm, err := helpers.AuthenticateForARM()
	if err != nil {
		fmt.Printf("Failed to authenticate: '%s'\n", err.Error())
		return
	}

	arm.RequestInspector = helpers.WithInspection()
	arm.ResponseInspector = helpers.ByInspecting()

	_, err = createResourceGroup(groupName, groupLocation, arm)
	if err != nil {
		fmt.Printf("Failed to create resource group '%s': '%s'\n", groupName, err.Error())
		return
	}

	var parameterLink *string
	var parameters map[string]interface{}

	var templateLink *string

	if len(os.Args) >= 2 {
		pl := os.Args[1]
		parameterLink = &pl
	}
	if len(os.Args) >= 3 {
		tl := os.Args[2]
		templateLink = &tl
	}

	if parameterLink != nil {
		parameters, err = helpers.ReadMap(*parameterLink)
		if err != nil {
			fmt.Printf("Failed to read parameter file '%s': '%s'\n", *parameterLink, err.Error())
			return
		}
		if p, ok := parameters["parameters"]; ok {
			parameters = p.(map[string]interface{})
		}
	} else {
		parameters = map[string]interface{}{
			"adminUsername":   makeStringParameterValue("tmpltest"),
			"adminPassword":   makeStringParameterValue("<<PLEASE EDIT>>"),
			"dnsLabelPrefix":  makeStringParameterValue("<<MUST BE UNIQUE>>"),
			"ubuntuOSVersion": makeStringParameterValue("14.04.2-LTS"),
		}
	}

	var deploymentProps resources.DeploymentProperties

	if templateLink != nil {

		template, err := helpers.ReadMap(*templateLink)
		if err != nil {
			fmt.Printf("Failed to read template file '%s': '%s'\n", *templateLink, err.Error())
			return
		}

		deploymentProps = resources.DeploymentProperties{
			Template:   &template,
			Parameters: &parameters,
			Mode:       resources.Incremental,
		}

	} else {

		deploymentProps = resources.DeploymentProperties{
			TemplateLink: &resources.TemplateLink{
				URI:            to.StringPtr("https://raw.githubusercontent.com/NiklasGustafsson/azure-go-samples/master/arm/templates/deploy-template/template01.json"),
				ContentVersion: to.StringPtr("1.0.0.0"),
			},
			Parameters: &parameters,
			Mode:       resources.Incremental,
		}

	}

	deployment, err := arm.Deployments().CreateOrUpdate(groupName, deploymentName, resources.Deployment{Properties: &deploymentProps})
	if err != nil {
		if aerr, ok := err.(autorest.Error); ok {
			fmt.Printf("Failed to create resource deployment details: '%s'\n", aerr.Message())
		} else {
			fmt.Printf("Failed to create resource deployment: '%s'\n", err.Error())
		}
		return
	}

	fmt.Printf("Created resource deployment '%s'\n", *deployment.Name)
}
예제 #5
0
func main() {

	client, err := helpers.AuthenticateForARM()
	if err != nil {
		fmt.Printf("Failed to authenticate: '%s'\n", err.Error())
		return
	}

	client.RequestInspector = helpers.WithInspection()
	client.ResponseInspector = helpers.ByInspecting()

	vm1, err :=
		client.CreateSimpleVM(
			to.StringPtr("vmgroup02"),
			to.StringPtr("West US"),
			arm.VMParameters{
				User:     "******",
				Password: "******",
				ImageReference: compute.ImageReference{
					Publisher: to.StringPtr("MicrosoftWindowsServer"),
					Offer:     to.StringPtr("WindowsServer"),
					Sku:       to.StringPtr("2012-R2-Datacenter"),
					Version:   to.StringPtr("latest"),
				},
				AvailabilitySet: to.StringPtr("avset1"),
				StorageAccount:  to.StringPtr("vmgroup01accnta44c9ea1"),
			},
		)

	if err != nil {
		fmt.Printf("Failed to create virtual machine: %s\n", err.Error())
		return
	}

	fmt.Printf("Created vm '%s'\n", *vm1.Name)

	vm2, err :=
		client.CreateSimpleVM(
			to.StringPtr("vmgroup01"),
			to.StringPtr("West US"),
			arm.VMParameters{
				User:     "******",
				Password: "******",
				ImageReference: compute.ImageReference{
					Publisher: to.StringPtr("Canonical"),
					Offer:     to.StringPtr("UbuntuServer"),
					Sku:       to.StringPtr("14.04.2-LTS"),
					Version:   to.StringPtr("latest"),
				},
				AvailabilitySet: to.StringPtr("avset1"),
				StorageAccount:  to.StringPtr("vmgroup01accnta44c9ea1"),
			},
		)

	if err != nil {
		fmt.Printf("Failed to create virtual machine: %s\n", err.Error())
		return
	}

	fmt.Printf("Created vm '%s'\n", *vm2.Name)
}