alzlib

package module
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2024 License: MIT Imports: 17 Imported by: 0

README

alzlib

Go test codecov

This module provides a go library for reading Azure Landing Zones Library definitions.

Installation

To install alzlib, use the following go get command:

go get -u github.com/Azure/alzlib

Usage

See the examples in the integrationtest/examples_test.go file for usage examples.

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.opensource.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., status check, 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.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

Documentation

Overview

Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License.

Package alzlib provides the data structures needed to deploy Azure Landing Zones. It takes in fs.FS as input and returns a map of resources that can be used to deploy Azure Landing Zones of varying complexity.

Internally the Azure SDK is used to store the resources in memory. It is up to the caller to transform this data into the required format for deployment.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FetchAzureLandingZonesLibraryMember added in v0.14.0

func FetchAzureLandingZonesLibraryMember(ctx context.Context, member, tag, dst string) (fs.FS, error)

FetchAzureLandingZonesLibraryByTag is a convenience function to fetch the Azure Landing Zones library by member and tag. It calls FetchLibraryByGetterString with the appropriate URL. The destination directory will be appended to the .alzlib directory in the current working directory. To fetch the ALZ reference, supply "platform/alz" as the member, with the tag (e.g. 2024.03.03).

func FetchLibraryByGetterString added in v0.14.0

func FetchLibraryByGetterString(ctx context.Context, getterString, dstDir string) (fs.FS, error)

FetchLibraryByGetterString fetches a library from a URL using the go-getter library. The caller must supply a valid go-getter URL and a destination directory, which will be appended to the .alzlib directory in the current working directory. It returns an fs.FS interface to the fetched library to be used in the AlzLib.Init() method.

Types

type AlzLib

type AlzLib struct {
	Options *AlzLibOptions
	// contains filtered or unexported fields
}

AlzLib is the structure that gets built from the the library files do not create this directly, use NewAlzLib instead.

func NewAlzLib

func NewAlzLib(opts *AlzLibOptions) *AlzLib

NewAlzLib returns a new instance of the alzlib library, optionally using the supplied directory for additional policy (set) definitions. To customize the options for the AlzLib, pass in an AlzLibOptions struct, otherwise the default options will be used.

func (*AlzLib) AddPolicyAssignments added in v0.14.0

func (az *AlzLib) AddPolicyAssignments(pas ...*assets.PolicyAssignment) error

AddPolicyAssignments adds policy assignments to the AlzLib struct.

func (*AlzLib) AddPolicyClient

func (az *AlzLib) AddPolicyClient(client *armpolicy.ClientFactory)

AddPolicyClient adds an authenticated *armpolicy.ClientFactory to the AlzLib struct. This is needed to get policy objects from Azure.

func (*AlzLib) AddPolicyDefinitions added in v0.14.0

func (az *AlzLib) AddPolicyDefinitions(pds ...*assets.PolicyDefinition) error

AddPolicyDefinitions adds policy definitions to the AlzLib struct.

func (*AlzLib) AddPolicySetDefinitions added in v0.14.0

func (az *AlzLib) AddPolicySetDefinitions(psds ...*assets.PolicySetDefinition) error

AddPolicySetDefinitions adds policy set definitions to the AlzLib struct.

func (*AlzLib) AddRoleDefinitions added in v0.14.0

func (az *AlzLib) AddRoleDefinitions(rds ...*assets.RoleDefinition) error

AddRoleDefinitions adds role definitions to the AlzLib struct.

func (*AlzLib) Archetype added in v0.14.0

func (az *AlzLib) Archetype(name string) (*Archetype, error)

Archetype returns a copy of the requested archetype by name.

func (*AlzLib) Archetypes added in v0.14.0

func (az *AlzLib) Archetypes() []string

Archetypes returns a list of the archetypes in the AlzLib struct.

func (*AlzLib) Architecture added in v0.14.0

func (az *AlzLib) Architecture(name string) (*Architecture, error)

Architecture returns the requested architecture.

func (*AlzLib) Architectures added in v0.18.0

func (az *AlzLib) Architectures() []string

Architectures returns a list of the architecture names in the AlzLib struct.

func (*AlzLib) AssignmentReferencedDefinitionHasParameter added in v0.19.0

func (az *AlzLib) AssignmentReferencedDefinitionHasParameter(res *arm.ResourceID, param string) bool

AssignmentReferencedDefinitionHasParameter checks if the referenced definition of an assignment has a specific parameter. It takes a resource ID and a parameter name as input and returns a boolean indicating whether the parameter exists or not.

func (*AlzLib) DefaultPolicyAssignmentValues added in v0.19.0

func (az *AlzLib) DefaultPolicyAssignmentValues(defaultName string) DefaultPolicyAssignmentValuesValue

DefaultPolicyAssignmentValues returns the DefaultPolicyAssignmentValuesValue associated with the given defaultName. If the defaultName does not exist in the defaultPolicyAssignmentValues map, it returns nil.

func (*AlzLib) GetDefinitionsFromAzure

func (az *AlzLib) GetDefinitionsFromAzure(ctx context.Context, pds []string) error

GetDefinitionsFromAzure takes a slice of strings of Azure resource IDs of policy definitions and policy set definitions. It then fetches them from Azure if they don't already exist (determined by last segment tof resource id). For set definitions we need to get all of them, even if they exist in AlzLib already because they can contain built-in definitions.

func (*AlzLib) Init

func (az *AlzLib) Init(ctx context.Context, libs ...fs.FS) error

Init processes ALZ libraries, supplied as `fs.FS` interfaces. Use FetchAzureLandingZonesLibraryMember/FetchLibraryByGetterString to get the library from GitHub. It populates the struct with the results of the processing.

func (*AlzLib) PolicyAssignment added in v0.14.0

func (az *AlzLib) PolicyAssignment(name string) (*assets.PolicyAssignment, error)

GetPolicySetDefinition returns a deep copy of the requested policy set definition. This is safe to modify without affecting the original.

func (*AlzLib) PolicyAssignmentExists

func (az *AlzLib) PolicyAssignmentExists(name string) bool

PolicyAssignmentExists returns true if the policy assignment exists name in the AlzLib struct.

func (*AlzLib) PolicyAssignments added in v0.18.0

func (az *AlzLib) PolicyAssignments() []string

PolicyAssignments returns a slice of all the policy assignment names in the library.

func (*AlzLib) PolicyDefinition added in v0.14.0

func (az *AlzLib) PolicyDefinition(name string) (*assets.PolicyDefinition, error)

PolicyDefinition returns a deep copy of the requested policy definition. This is safe to modify without affecting the original.

func (*AlzLib) PolicyDefinitionExists

func (az *AlzLib) PolicyDefinitionExists(name string) bool

PolicyDefinitionExists returns true if the policy definition name exists in the AlzLib struct.

func (*AlzLib) PolicyDefinitions added in v0.18.0

func (az *AlzLib) PolicyDefinitions() []string

PolicyDefinitions returns a slice of all the policy definition names in the library.

func (*AlzLib) PolicySetDefinition added in v0.14.0

func (az *AlzLib) PolicySetDefinition(name string) (*assets.PolicySetDefinition, error)

PolicySetDefinition returns a deep copy of the requested policy set definition. This is safe to modify without affecting the original.

func (*AlzLib) PolicySetDefinitionExists

func (az *AlzLib) PolicySetDefinitionExists(name string) bool

PolicySetDefinitionExists returns true if the policy set definition name exists in the AlzLib struct.

func (*AlzLib) PolicySetDefinitions added in v0.18.0

func (az *AlzLib) PolicySetDefinitions() []string

PolicySetDefinitions returns a slice of all the policy set definition names in the library.

func (*AlzLib) RoleDefinition added in v0.14.0

func (az *AlzLib) RoleDefinition(name string) (*assets.RoleDefinition, error)

RoleDefinition returns a deep copy of the requested role definition. This is safe to modify without affecting the original.

func (*AlzLib) RoleDefinitionExists

func (az *AlzLib) RoleDefinitionExists(name string) bool

RoleDefinitionExists returns true if the role definition name exists in the AlzLib struct.

func (*AlzLib) RoleDefinitions added in v0.18.0

func (az *AlzLib) RoleDefinitions() []string

RoleDefinitions returns a slice of all the role definition names in the library.

type AlzLibOptions

type AlzLibOptions struct {
	AllowOverwrite bool // AllowOverwrite allows overwriting of existing policy assignments when processing additional libraries with AlzLib.Init().
	Parallelism    int  // Parallelism is the number of parallel requests to make to Azure APIs when getting policy definitions and policy set definitions.
}

AlzLibOptions are options for the AlzLib.

type Archetype

type Archetype struct {
	PolicyDefinitions    mapset.Set[string]
	PolicyAssignments    mapset.Set[string]
	PolicySetDefinitions mapset.Set[string]
	RoleDefinitions      mapset.Set[string]
	// contains filtered or unexported fields
}

Archetype represents an archetype definition that hasn't been assigned to a management group The contents of the sets represent the map keys of the corresponding AlzLib maps. Do not creaste this struct directly, use NewArchetype instead.

func NewArchetype added in v0.14.0

func NewArchetype(name string) *Archetype

NewArchetype creates a new Archetype with the given name.

func (*Archetype) Name added in v0.14.0

func (a *Archetype) Name() string

Name returns the name of the archetype.

type Architecture added in v0.14.0

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

Architecture represents an Azure architecture that has not been deployed. Do not create this struct directly, use NewArchitecture instead.

func NewArchitecture added in v0.14.0

func NewArchitecture(name string, az *AlzLib) *Architecture

NewArchitecture creates a new Architecture with the given name and AlzLib.

func (*Architecture) RootMgs added in v0.14.0

func (a *Architecture) RootMgs() (res []*ArchitectureManagementGroup)

RootMgs returns the top level management groups of the architecture.

type ArchitectureManagementGroup added in v0.14.0

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

ArchitectureManagementGroup represents a management group in an undeployed architecture.

func (*ArchitectureManagementGroup) Archetypes added in v0.14.0

func (mg *ArchitectureManagementGroup) Archetypes() (res []*Archetype)

Archetypes returns the archetypes assigned to the management group.

func (*ArchitectureManagementGroup) Children added in v0.14.0

Children returns the child management groups of the management group.

func (*ArchitectureManagementGroup) DisplayName added in v0.14.0

func (mg *ArchitectureManagementGroup) DisplayName() string

DisplayName returns the display name of the management group.

func (*ArchitectureManagementGroup) Id added in v0.14.0

Id returns the id of the management group.

type DefaultPolicyAssignmentValues added in v0.19.0

type DefaultPolicyAssignmentValues map[string]DefaultPolicyAssignmentValuesValue

PolicyAssignmentsParameterValues is a map of default names to DefaultPolicyAssignmentValuesValue. It is used to map a single value to multiple policy assignments.

func (DefaultPolicyAssignmentValues) Add added in v0.19.0

func (d DefaultPolicyAssignmentValues) Add(defaultName, assignmentName string, parameterNames ...string)

Add adds a new default policy assignment value to the DefaultPolicyAssignmentValues. It takes the defaultName, assignmentName, and parameterNames as input parameters. If the defaultName does not exist in the DefaultPolicyAssignmentValues, it creates a new entry. If the assignmentName does not exist under the defaultName, it creates a new entry. Finally, it appends the parameterNames to the assignmentName.

func (DefaultPolicyAssignmentValues) AssignmentParameterComboExists added in v0.19.0

func (d DefaultPolicyAssignmentValues) AssignmentParameterComboExists(wantAssignmentName, wantParameterName string) bool

AssignmentParameterComboExists checks if a given assignment name and parameter name combination exists in the DefaultPolicyAssignmentValues. It iterates through each assignment in the DefaultPolicyAssignmentValues and checks if the assignment contains the specified assignment name. If the assignment contains the assignment name, it then checks if the assignment's parameters contain the specified parameter name. If the combination exists, it returns true. Otherwise, it returns false.

type DefaultPolicyAssignmentValuesValue added in v0.19.0

type DefaultPolicyAssignmentValuesValue map[string]mapset.Set[string]

DefaultPolicyAssignmentValuesValue is a map of assignments names to parameter names.

Directories

Path Synopsis
package assets provides the types used by the Alzlib library.
package assets provides the types used by the Alzlib library.
cmd
alzlibtool command
Package deployment contains the types and methods for managing the deployment of an Azure management group hierarchy using the supplied Alzlib.
Package deployment contains the types and methods for managing the deployment of an Azure management group hierarchy using the supplied Alzlib.
package processor is used to process the library files and read them into a result struct for Alzlib to use.
package processor is used to process the library files and read them into a result struct for Alzlib to use.
Package to contains various type-conversion helper functions.
Package to contains various type-conversion helper functions.
tools

Jump to

Keyboard shortcuts

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