Giter VIP home page Giter VIP logo

go-azure-sdk's Introduction

hashicorp/go-azure-sdk

This SDK is an opinionated Go SDK for Azure Resource Manager, primarily intended to be used in the Terraform AzureRM Provider and the Packer Azure Plugin.

The SDKs within this repository are generated using the data in the Azure Rest API Specifications repository.

At this time this SDK uses both the base-layer within this repository and the Azure/go-autorest base layer (although this is gradually being removed).

Repository Structure

This repository contains:

  • ./docs - usage documentation.
  • ./microsoft-graph - (WIP) the Microsoft Graph Services supported by this SDK.
  • ./resource-manager - the Resource Manager Services supported by this SDK.
  • ./sdk - the base layer that's used in this repository.

In addition, a README.md file can be found within each Service / API Version in the ./resource-manager directory highlighting how that SDK can be used (example).

Getting Started

SDKs within this repository can be found within the ./resource-manager directory, in the structure ./resource-manager/{serviceName}/{apiVersion}/{resource} for example this the Resource Groups SDK for API Version 2022-09-01 can be found in ./resource-manager/resources/2022-09-01/resourcegroups, where the README for which also demonstrates how to use each function.

SDK Clients require authentication which is available from the auth package, see the README in the ./sdk/auth directory for information on how to authenticate and obtain an Authorizer.

Once you've got an Authorizer, you can use an SDK Client like so:

package main

import (
	"context"
	"log"
	"time"

	"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
	"github.com/hashicorp/go-azure-sdk/resource-manager/resources/2022-09-01/resourcegroups"
	"github.com/hashicorp/go-azure-sdk/sdk/auth"
	"github.com/hashicorp/go-azure-sdk/sdk/environments"
)

func main() {
	ctx, cancel := context.WithTimeout(context.TODO(), 5 * time.Minute)
	defer cancel()

	id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group")
	environment := environments.AzurePublic()
	credentials := auth.Credentials{
		Environment:                       *environment,
		EnableAuthenticatingUsingAzureCLI: true,
		// you can also authenticate using a Service Principal, via MSI, OIDC etc by turning on the flag
	}
	log.Printf("[DEBUG] Obtaining Credentials..")
	authorizer, err := auth.NewAuthorizerFromCredentials(ctx, credentials, environment.ResourceManager)
	if err != nil {
		log.Fatalf("building authorizer from credentials: %+v", err)
	}

	log.Printf("[DEBUG] Building Resource Groups Client..")
	client, err := resourcegroups.NewResourceGroupsClientWithBaseURI(environment.ResourceManager)
	if err != nil {
		log.Fatalf("building ResourceGroups client: %+v", err)
	}
	client.Client.Authorizer = authorizer

	// NOTE: the Resource ID type can be used for logging too, it contains a human-friendly description
	log.Printf("[DEBUG] Creating %s..", id)
	payload := resourcegroups.ResourceGroup{
		// ...
	}
	if _, err := client.CreateOrUpdate(ctx, id, payload); err != nil {
		log.Fatalf("creating %s: %+v", id, err)
	}
	log.Printf("[DEBUG] %s created..", id)
}

Further Documentation

Further information can be found in the ./docs directory, and also the README.md file within each Service / API Version in the ./resource-manager directory (example).

go-azure-sdk's People

Contributors

tombuildsstuff avatar manicminer avatar stephybun avatar mbfrahry avatar jackofallops avatar catriona-m avatar katbyte avatar hashicorp-tsccr[bot] avatar hashicorp-copywrite[bot] avatar wuxu92 avatar teowa avatar dependabot[bot] avatar magodo avatar markdordoy avatar sinbai avatar kenchan0130 avatar neil-yechenwei avatar jengoldstrich avatar tzdybel avatar ms-zhenhua avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.