armbicep

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2025 License: MIT Imports: 12 Imported by: 0

README

Azure Resources Module for Go

The armbicep module provides operations for working with Azure Resources.

Source code

Getting started

Prerequisites

  • An Azure subscription
  • Supported version of Go (You could download and install the latest version of Go from here. It will replace the existing Go on your machine. If you want to install multiple Go versions on the same machine, you could refer this doc.)

Install the package

This project uses Go modules for versioning and dependency management.

Install the Azure Resources module:

go get github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armbicep

Authorization

When creating a client, you will need to provide a credential for authenticating with Azure Resources. The azidentity module provides facilities for various ways of authenticating with Azure including client/secret, certificate, managed identity, and more.

cred, err := azidentity.NewDefaultAzureCredential(nil)

For more information on authentication, please see the documentation for azidentity at pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity.

Client Factory

Azure Resources module consists of one or more clients. We provide a client factory which could be used to create any client in this module.

clientFactory, err := armbicep.NewClientFactory(<subscription ID>, cred, nil)

You can use ClientOptions in package github.com/Azure/azure-sdk-for-go/sdk/azcore/arm to set endpoint to connect with public and sovereign clouds as well as Azure Stack. For more information, please see the documentation for azcore at pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azcore.

options := arm.ClientOptions {
    ClientOptions: azcore.ClientOptions {
        Cloud: cloud.AzureChina,
    },
}
clientFactory, err := armbicep.NewClientFactory(<subscription ID>, cred, &options)

Clients

A client groups a set of related APIs, providing access to its functionality. Create one or more clients to access the APIs you require using client factory.

client := clientFactory.NewDecompileOperationGroupClient()

Fakes

The fake package contains types used for constructing in-memory fake servers used in unit tests. This allows writing tests to cover various success/error conditions without the need for connecting to a live service.

Please see https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/samples/fakes for details and examples on how to use fakes.

Provide Feedback

If you encounter bugs or have suggestions, please open an issue and assign the Resources label.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientFactory

type ClientFactory struct {
	// contains filtered or unexported fields
}

ClientFactory is a client factory used to create any client in this module. Don't use this type directly, use NewClientFactory instead.

func NewClientFactory

func NewClientFactory(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ClientFactory, error)

NewClientFactory creates a new instance of ClientFactory with the specified values. The parameter values will be propagated to any client created from this factory.

  • subscriptionID - The ID of the target subscription. The value must be an UUID.
  • credential - used to authorize requests. Usually a credential from azidentity.
  • options - pass nil to accept the default values.

func (*ClientFactory) NewDecompileOperationGroupClient

func (c *ClientFactory) NewDecompileOperationGroupClient() *DecompileOperationGroupClient

NewDecompileOperationGroupClient creates a new instance of DecompileOperationGroupClient.

type DecompileOperationGroupClient

type DecompileOperationGroupClient struct {
	// contains filtered or unexported fields
}

DecompileOperationGroupClient contains the methods for the DecompileOperationGroup group. Don't use this type directly, use NewDecompileOperationGroupClient() instead.

func NewDecompileOperationGroupClient

func NewDecompileOperationGroupClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*DecompileOperationGroupClient, error)

NewDecompileOperationGroupClient creates a new instance of DecompileOperationGroupClient with the specified values.

  • subscriptionID - The ID of the target subscription. The value must be an UUID.
  • credential - used to authorize requests. Usually a credential from azidentity.
  • options - pass nil to accept the default values.

func (*DecompileOperationGroupClient) Bicep

Bicep - Decompiles an ARM json template into a Bicep template If the operation fails it returns an *azcore.ResponseError type.

Generated from API version 2023-11-01

  • decompileOperationRequest - The request body
  • options - DecompileOperationGroupClientBicepOptions contains the optional parameters for the DecompileOperationGroupClient.Bicep method.
Example

Generated from example definition: 2023-11-01/DecompileBicep.json

package main

import (
	"context"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
	"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
	"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armbicep"
	"log"
)

func main() {
	cred, err := azidentity.NewDefaultAzureCredential(nil)
	if err != nil {
		log.Fatalf("failed to obtain a credential: %v", err)
	}
	ctx := context.Background()
	clientFactory, err := armbicep.NewClientFactory("00000000-0000-0000-0000-000000000000", cred, nil)
	if err != nil {
		log.Fatalf("failed to create client: %v", err)
	}
	res, err := clientFactory.NewDecompileOperationGroupClient().Bicep(ctx, armbicep.DecompileOperationRequest{
		Template: to.Ptr("{\r\n \"$schema\": \"https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#\",\r\n \"contentVersion\": \"1.0.0.0\",\r\n \"metadata\": {\r\n \"_generator\": {\r\n \"name\": \"bicep\",\r\n \"version\": \"0.15.31.15270\",\r\n \"templateHash\": \"9249505596133208719\"\r\n }\r\n },\r\n \"parameters\": {\r\n \"storageAccountName\": {\r\n \"type\": \"string\"\r\n }\r\n },\r\n \"resources\": []\r\n}"),
	}, nil)
	if err != nil {
		log.Fatalf("failed to finish the request: %v", err)
	}
	// You could use response here. We use blank identifier for just demo purposes.
	_ = res
	// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
	// res = armbicep.DecompileOperationGroupClientBicepResponse{
	// 	DecompileOperationSuccessResponse: &armbicep.DecompileOperationSuccessResponse{
	// 		EntryPoint: to.Ptr("main.bicep"),
	// 		Files: []*armbicep.FileDefinition{
	// 			{
	// 				Path: to.Ptr("main.bicep"),
	// 				Contents: to.Ptr("param storageAccountName string"),
	// 			},
	// 		},
	// 	},
	// }
}

type DecompileOperationGroupClientBicepOptions

type DecompileOperationGroupClientBicepOptions struct {
}

DecompileOperationGroupClientBicepOptions contains the optional parameters for the DecompileOperationGroupClient.Bicep method.

type DecompileOperationGroupClientBicepResponse

type DecompileOperationGroupClientBicepResponse struct {
	// The response of the decompileBicep operation
	DecompileOperationSuccessResponse
}

DecompileOperationGroupClientBicepResponse contains the response from method DecompileOperationGroupClient.Bicep.

type DecompileOperationRequest

type DecompileOperationRequest struct {
	// REQUIRED; The ARM json template to be decompiled into a Bicep file
	Template *string
}

DecompileOperationRequest - The body of the request for the decompileBicep operation

func (DecompileOperationRequest) MarshalJSON

func (d DecompileOperationRequest) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface for type DecompileOperationRequest.

func (*DecompileOperationRequest) UnmarshalJSON

func (d *DecompileOperationRequest) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for type DecompileOperationRequest.

type DecompileOperationSuccessResponse

type DecompileOperationSuccessResponse struct {
	// REQUIRED; The file path to the main Bicep file generated from the decompiled ARM json template.
	EntryPoint *string

	// REQUIRED; An array of key-value pairs containing the entryPoint string as the key for the Bicep file decompiled from the
	// ARM json template
	Files []*FileDefinition
}

DecompileOperationSuccessResponse - The response of the decompileBicep operation

func (DecompileOperationSuccessResponse) MarshalJSON

func (d DecompileOperationSuccessResponse) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface for type DecompileOperationSuccessResponse.

func (*DecompileOperationSuccessResponse) UnmarshalJSON

func (d *DecompileOperationSuccessResponse) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for type DecompileOperationSuccessResponse.

type FileDefinition

type FileDefinition struct {
	// The contents of the Bicep file.
	Contents *string

	// The file path of the Bicep file.
	Path *string
}

FileDefinition - The definition of a file along with its contents

func (FileDefinition) MarshalJSON

func (f FileDefinition) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface for type FileDefinition.

func (*FileDefinition) UnmarshalJSON

func (f *FileDefinition) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface for type FileDefinition.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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