Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maps - regenerate embedded sdk #14155

Merged
merged 2 commits into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/services/maps/maps_account_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func dataSourceMapsAccountRead(d *pluginsdk.ResourceData, meta interface{}) erro

d.SetId(id.ID())

d.Set("name", id.Name)
d.Set("resource_group_name", id.ResourceGroup)
d.Set("name", id.AccountName)
d.Set("resource_group_name", id.ResourceGroupName)

if model := resp.Model; model != nil {
d.Set("sku_name", model.Sku.Name)
Expand Down
4 changes: 2 additions & 2 deletions internal/services/maps/maps_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ func resourceMapsAccountRead(d *pluginsdk.ResourceData, meta interface{}) error
return fmt.Errorf("retrieving %s: %+v", *id, err)
}

d.Set("name", id.Name)
d.Set("resource_group_name", id.ResourceGroup)
d.Set("name", id.AccountName)
d.Set("resource_group_name", id.ResourceGroupName)

if model := resp.Model; model != nil {
d.Set("sku_name", model.Sku.Name)
Expand Down
92 changes: 92 additions & 0 deletions internal/services/maps/sdk/2021-02-01/accounts/constants.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package accounts

import "strings"

type CreatedByType string

const (
Expand All @@ -9,24 +11,114 @@ const (
CreatedByTypeUser CreatedByType = "User"
)

func PossibleValuesForCreatedByType() []string {
return []string{
string(CreatedByTypeApplication),
string(CreatedByTypeKey),
string(CreatedByTypeManagedIdentity),
string(CreatedByTypeUser),
}
}

func parseCreatedByType(input string) (*CreatedByType, error) {
vals := map[string]CreatedByType{
"application": CreatedByTypeApplication,
"key": CreatedByTypeKey,
"managedidentity": CreatedByTypeManagedIdentity,
"user": CreatedByTypeUser,
}
if v, ok := vals[strings.ToLower(input)]; ok {
return &v, nil
}

// otherwise presume it's an undefined value and best-effort it
out := CreatedByType(input)
return &out, nil
}

type KeyType string

const (
KeyTypePrimary KeyType = "primary"
KeyTypeSecondary KeyType = "secondary"
)

func PossibleValuesForKeyType() []string {
return []string{
string(KeyTypePrimary),
string(KeyTypeSecondary),
}
}

func parseKeyType(input string) (*KeyType, error) {
vals := map[string]KeyType{
"primary": KeyTypePrimary,
"secondary": KeyTypeSecondary,
}
if v, ok := vals[strings.ToLower(input)]; ok {
return &v, nil
}

// otherwise presume it's an undefined value and best-effort it
out := KeyType(input)
return &out, nil
}

type Kind string

const (
KindGenOne Kind = "Gen1"
KindGenTwo Kind = "Gen2"
)

func PossibleValuesForKind() []string {
return []string{
string(KindGenOne),
string(KindGenTwo),
}
}

func parseKind(input string) (*Kind, error) {
vals := map[string]Kind{
"gen1": KindGenOne,
"gen2": KindGenTwo,
}
if v, ok := vals[strings.ToLower(input)]; ok {
return &v, nil
}

// otherwise presume it's an undefined value and best-effort it
out := Kind(input)
return &out, nil
}

type Name string

const (
NameGTwo Name = "G2"
NameSOne Name = "S1"
NameSZero Name = "S0"
)

func PossibleValuesForName() []string {
return []string{
string(NameGTwo),
string(NameSOne),
string(NameSZero),
}
}

func parseName(input string) (*Name, error) {
vals := map[string]Name{
"g2": NameGTwo,
"s1": NameSOne,
"s0": NameSZero,
}
if v, ok := vals[strings.ToLower(input)]; ok {
return &v, nil
}

// otherwise presume it's an undefined value and best-effort it
out := Name(input)
return &out, nil
}
142 changes: 79 additions & 63 deletions internal/services/maps/sdk/2021-02-01/accounts/id_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,102 +7,118 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
)

var _ resourceids.ResourceId = AccountId{}

// AccountId is a struct representing the Resource ID for a Account
type AccountId struct {
SubscriptionId string
ResourceGroup string
Name string
SubscriptionId string
ResourceGroupName string
AccountName string
}

func NewAccountID(subscriptionId, resourceGroup, name string) AccountId {
// NewAccountID returns a new AccountId struct
func NewAccountID(subscriptionId string, resourceGroupName string, accountName string) AccountId {
return AccountId{
SubscriptionId: subscriptionId,
ResourceGroup: resourceGroup,
Name: name,
SubscriptionId: subscriptionId,
ResourceGroupName: resourceGroupName,
AccountName: accountName,
}
}

func (id AccountId) String() string {
segments := []string{
fmt.Sprintf("Name %q", id.Name),
fmt.Sprintf("Resource Group %q", id.ResourceGroup),
}
segmentsStr := strings.Join(segments, " / ")
return fmt.Sprintf("%s: (%s)", "Account", segmentsStr)
}

func (id AccountId) ID() string {
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Maps/accounts/%s"
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.Name)
}

// ParseAccountID parses a Account ID into an AccountId struct
// ParseAccountID parses 'input' into a AccountId
func ParseAccountID(input string) (*AccountId, error) {
id, err := resourceids.ParseAzureResourceID(input)
parser := resourceids.NewParserFromResourceIdType(AccountId{})
parsed, err := parser.Parse(input, false)
if err != nil {
return nil, err
}

resourceId := AccountId{
SubscriptionId: id.SubscriptionID,
ResourceGroup: id.ResourceGroup,
return nil, fmt.Errorf("parsing %q: %+v", input, err)
}

if resourceId.SubscriptionId == "" {
return nil, fmt.Errorf("ID was missing the 'subscriptions' element")
}
var ok bool
id := AccountId{}

if resourceId.ResourceGroup == "" {
return nil, fmt.Errorf("ID was missing the 'resourceGroups' element")
if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok {
return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input)
}

if resourceId.Name, err = id.PopSegment("accounts"); err != nil {
return nil, err
if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok {
return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input)
}

if err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
if id.AccountName, ok = parsed.Parsed["accountName"]; !ok {
return nil, fmt.Errorf("the segment 'accountName' was not found in the resource id %q", input)
}

return &resourceId, nil
return &id, nil
}

// ParseAccountIDInsensitively parses an Account ID into an AccountId struct, insensitively
// This should only be used to parse an ID for rewriting to a consistent casing,
// the ParseAccountID method should be used instead for validation etc.
// ParseAccountIDInsensitively parses 'input' case-insensitively into a AccountId
// note: this method should only be used for API response data and not user input
func ParseAccountIDInsensitively(input string) (*AccountId, error) {
id, err := resourceids.ParseAzureResourceID(input)
parser := resourceids.NewParserFromResourceIdType(AccountId{})
parsed, err := parser.Parse(input, true)
if err != nil {
return nil, err
return nil, fmt.Errorf("parsing %q: %+v", input, err)
}

resourceId := AccountId{
SubscriptionId: id.SubscriptionID,
ResourceGroup: id.ResourceGroup,
var ok bool
id := AccountId{}

if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok {
return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input)
}

if resourceId.SubscriptionId == "" {
return nil, fmt.Errorf("ID was missing the 'subscriptions' element")
if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok {
return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input)
}

if resourceId.ResourceGroup == "" {
return nil, fmt.Errorf("ID was missing the 'resourceGroups' element")
if id.AccountName, ok = parsed.Parsed["accountName"]; !ok {
return nil, fmt.Errorf("the segment 'accountName' was not found in the resource id %q", input)
}

// find the correct casing for the 'accounts' segment
accountsKey := "accounts"
for key := range id.Path {
if strings.EqualFold(key, accountsKey) {
accountsKey = key
break
}
return &id, nil
}

// ValidateAccountID checks that 'input' can be parsed as a Account ID
func ValidateAccountID(input interface{}, key string) (warnings []string, errors []error) {
v, ok := input.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected %q to be a string", key))
return
}
if resourceId.Name, err = id.PopSegment(accountsKey); err != nil {
return nil, err

if _, err := ParseAccountID(v); err != nil {
errors = append(errors, err)
}

if err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
return
}

// ID returns the formatted Account ID
func (id AccountId) ID() string {
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Maps/accounts/%s"
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.AccountName)
}

// Segments returns a slice of Resource ID Segments which comprise this Account ID
func (id AccountId) Segments() []resourceids.Segment {
return []resourceids.Segment{
resourceids.StaticSegment("subscriptions", "subscriptions", "subscriptions"),
resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"),
resourceids.StaticSegment("resourceGroups", "resourceGroups", "resourceGroups"),
resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"),
resourceids.StaticSegment("providers", "providers", "providers"),
resourceids.ResourceProviderSegment("microsoftMaps", "Microsoft.Maps", "Microsoft.Maps"),
resourceids.StaticSegment("accounts", "accounts", "accounts"),
resourceids.UserSpecifiedSegment("accountName", "accountValue"),
}
}

return &resourceId, nil
// String returns a human-readable description of this Account ID
func (id AccountId) String() string {
components := []string{
fmt.Sprintf("Subscription: %q", id.SubscriptionId),
fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName),
fmt.Sprintf("Account Name: %q", id.AccountName),
}
return fmt.Sprintf("Account (%s)", strings.Join(components, "\n"))
}
Loading