No description
Find a file
2026-03-30 21:44:26 +00:00
.github build(deps): bump actions/setup-go from 5.3.0 to 5.6.0 (#1277) 2026-02-04 10:39:34 +01:00
data-plane data-plane: updating to 'v0.20260330.1214357' of 'github.com/hashicorp/go-azure-sdk/sdk' 2026-03-30 21:44:26 +00:00
docs docs: updating the readme's 2023-08-16 17:39:02 +02:00
microsoft-graph microsoft-graph: updating to 'v0.20260330.1214357' of 'github.com/hashicorp/go-azure-sdk/sdk' 2026-03-30 21:44:13 +00:00
resource-manager resource-manager: updating to 'v0.20260330.1214357' of 'github.com/hashicorp/go-azure-sdk/sdk' 2026-03-30 21:44:23 +00:00
scripts automation - add data-plane to module tagging for releases (#1298) 2026-02-12 15:59:39 +01:00
sdk microsoft-graph: updating to 'v0.20260326.1151219' of 'github.com/hashicorp/go-azure-sdk/sdk' 2026-03-26 15:12:35 +00:00
.gitignore gitignore: ignoring fleet directories 2022-12-14 16:46:52 +01:00
.go-version dataplane initial support for generated Data Plane SDKs (#1284) 2026-02-10 08:53:02 +01:00
.whitesource Add .whitesource configuration file and disable SAST scanning for this repo (#1300) 2026-03-10 13:26:16 -06:00
GNUmakefile dataplane initial support for generated Data Plane SDKs (#1284) 2026-02-10 08:53:02 +01:00
LICENSE [COMPLIANCE] Update MPL 2.0 LICENSE 2022-10-12 22:05:41 +00:00
NOTICE.txt Initial commit 2022-06-10 11:43:34 +02:00
README.md microsoft-graph: update SDK readme 2024-09-24 22:28:57 +01:00

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 - 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).