identity

package
v2.85.6 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2021 License: MPL-2.0 Imports: 6 Imported by: 0

README

Identity

This package contains helpers for working with Managed Identities.

Azure supports up to 4 different combinations of Managed Identities:

  • None - where no Managed Identity is available/configured for this Azure Resource.
  • SystemAssigned - where Azure will generate a Managed Identity (Service Principal) for this Azure Resource.
  • SystemAssigned, UserAssigned - where Azure will generate a Managed Identity (Service Principal) for this Azure Resource, but they can also be assigned.
  • UserAssigned - where specific Managed Identities can be assigned to this Azure Resource.

Since Managed Identities are an optional feature - within Terarform we're exposing this in 3 manners, exposed in this package as 3 types:

  • SystemAssigned
  • SystemAssignedUserAssigned (coming soon)
  • UserAssigned

Where the block is Optional within Terraform - for consistency across the Provider we've opted to treat the absence of the identity block to represent "None" - and the presence of the block to indicate one of the Managed Identity types above.

Usage

Within the resource itself, assign a type reference via:

type resourceNameIdentity = identity.SystemAssigned

which can then be instantiated and used to call the Expand, Flatten and Schema functions:

resourceNameIdentity{}.Schema()
resourceNameIdentity{}.Expand(d.Get("identity").([]interface{}))
resourceNameIdentity{}.Flatten(input)

Due to the Azure SDK using a different Type for each Service Package, at this time an Expand and Flatten function are needed to cast from the intermediate type *identity.ExpandedConfig to the type used within the Azure SDK for the specified Service Package, for example:

func expandResourceNameIdentity(input []interface{}) (*somepackage.PackageTypeForManagedIdentity, error) {
	config, err := resourceNameIdentity{}.Expand(input)
	if err != nil {
		return nil, err
	}

	return &somepackage.ManagedIdentityProperties{
		Type:        somepackage.ManagedIdentityType(config.Type),
		TenantID:    config.TenantId,
		PrincipalID: config.PrincipalId,
	}, nil
}

func flattenResourceNameIdentity(input *somepackage.ManagedIdentityProperties) []interface{} {
	var config *identity.ExpandedConfig
	if input != nil {
		config = &identity.ExpandedConfig{
			Type:        string(input.Type),
			PrincipalId: input.PrincipalID,
			TenantId:    input.TenantID,
		}
	}
	return resourceNameIdentity{}.Flatten(config)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExpandedConfig

type ExpandedConfig struct {
	// Type is the type of User Assigned Identity, either `None`, `SystemAssigned`, `UserAssigned`
	// or `SystemAssigned, UserAssigned`
	Type                    Type     `tfschema:"type"`
	PrincipalId             string   `tfschema:"principal_id"`
	TenantId                string   `tfschema:"tenant_id"`
	UserAssignedIdentityIds []string `tfschema:"identity_ids"`
}

type ExpandedConfigCaster

type ExpandedConfigCaster interface {
	ToExpandedConfig() ExpandedConfig
	FromExpandedConfig(ExpandedConfig)
}

type Identity

type Identity interface {
	Expand(input []interface{}) (*ExpandedConfig, error)
	Flatten(input *ExpandedConfig) []interface{}
	Schema() *pluginsdk.Schema
}

type SystemAssigned

type SystemAssigned struct{}

func (SystemAssigned) Expand

func (s SystemAssigned) Expand(input []interface{}) (*ExpandedConfig, error)

func (SystemAssigned) Flatten

func (s SystemAssigned) Flatten(input *ExpandedConfig) []interface{}

func (SystemAssigned) Schema

func (s SystemAssigned) Schema() *pluginsdk.Schema

type SystemAssignedIdentity

type SystemAssignedIdentity struct {
	Type        Type    `json:"type,omitempty"`
	TenantId    *string `json:"tenantId,omitempty"`
	PrincipalId *string `json:"principalId,omitempty"`
}

func (*SystemAssignedIdentity) FromExpandedConfig

func (s *SystemAssignedIdentity) FromExpandedConfig(config ExpandedConfig)

func (*SystemAssignedIdentity) ToExpandedConfig

func (s *SystemAssignedIdentity) ToExpandedConfig() ExpandedConfig

type SystemAssignedUserAssigned

type SystemAssignedUserAssigned struct{}

func (SystemAssignedUserAssigned) Expand

func (s SystemAssignedUserAssigned) Expand(input []interface{}) (*ExpandedConfig, error)

func (SystemAssignedUserAssigned) Flatten

func (s SystemAssignedUserAssigned) Flatten(input *ExpandedConfig) []interface{}

func (SystemAssignedUserAssigned) Schema

func (SystemAssignedUserAssigned) SchemaDataSource

func (s SystemAssignedUserAssigned) SchemaDataSource() *pluginsdk.Schema

type SystemUserAssignedIdentityList

type SystemUserAssignedIdentityList struct {
	Type                   Type                    `json:"type,omitempty"`
	TenantId               *string                 `json:"tenantId,omitempty"`
	PrincipalId            *string                 `json:"principalId,omitempty"`
	UserAssignedIdentities *[]userAssignedIdentity `json:"userAssignedIdentities"`
}

func (*SystemUserAssignedIdentityList) FromExpandedConfig

func (s *SystemUserAssignedIdentityList) FromExpandedConfig(config ExpandedConfig)

func (*SystemUserAssignedIdentityList) ToExpandedConfig

func (s *SystemUserAssignedIdentityList) ToExpandedConfig() ExpandedConfig

type SystemUserAssignedIdentityMap

type SystemUserAssignedIdentityMap struct {
	Type                   Type                                 `json:"type,omitempty"`
	TenantId               *string                              `json:"tenantId,omitempty"`
	PrincipalId            *string                              `json:"principalId,omitempty"`
	UserAssignedIdentities map[string]*userAssignedIdentityInfo `json:"userAssignedIdentities"`
}

func (*SystemUserAssignedIdentityMap) FromExpandedConfig

func (s *SystemUserAssignedIdentityMap) FromExpandedConfig(config ExpandedConfig)

func (*SystemUserAssignedIdentityMap) ToExpandedConfig

func (s *SystemUserAssignedIdentityMap) ToExpandedConfig() ExpandedConfig

type Type

type Type string

type UserAssigned

type UserAssigned struct{}

func (UserAssigned) Expand

func (u UserAssigned) Expand(input []interface{}) (*ExpandedConfig, error)

func (UserAssigned) Flatten

func (u UserAssigned) Flatten(input *ExpandedConfig) []interface{}

func (UserAssigned) Schema

func (u UserAssigned) Schema() *pluginsdk.Schema

func (UserAssigned) SchemaDataSource

func (u UserAssigned) SchemaDataSource() *pluginsdk.Schema

type UserAssignedIdentityList

type UserAssignedIdentityList struct {
	Type                   Type                    `json:"type,omitempty"`
	UserAssignedIdentities *[]userAssignedIdentity `json:"userAssignedIdentities"`
}

func (*UserAssignedIdentityList) FromExpandedConfig

func (u *UserAssignedIdentityList) FromExpandedConfig(config ExpandedConfig)

func (*UserAssignedIdentityList) ToExpandedConfig

func (u *UserAssignedIdentityList) ToExpandedConfig() ExpandedConfig

type UserAssignedIdentityMap

type UserAssignedIdentityMap struct {
	Type                   Type                                 `json:"type,omitempty"`
	UserAssignedIdentities map[string]*userAssignedIdentityInfo `json:"userAssignedIdentities"`
}

func (*UserAssignedIdentityMap) FromExpandedConfig

func (u *UserAssignedIdentityMap) FromExpandedConfig(config ExpandedConfig)

func (*UserAssignedIdentityMap) ToExpandedConfig

func (u *UserAssignedIdentityMap) ToExpandedConfig() ExpandedConfig

Jump to

Keyboard shortcuts

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