Skip to content

Commit

Permalink
Merge pull request #10395 from allantargino/purview
Browse files Browse the repository at this point in the history
New resource: azurerm_purview_account
  • Loading branch information
tombuildsstuff authored Mar 11, 2021
2 parents 5813873 + 0c40029 commit 02b5e9d
Show file tree
Hide file tree
Showing 27 changed files with 4,619 additions and 0 deletions.
1 change: 1 addition & 0 deletions .teamcity/components/generated/services.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ var services = mapOf(
"postgres" to "PostgreSQL",
"powerbi" to "PowerBI",
"privatedns" to "Private DNS",
"purview" to "Purview",
"recoveryservices" to "Recovery Services",
"redis" to "Redis",
"redisenterprise" to "Redis Enterprise",
Expand Down
3 changes: 3 additions & 0 deletions azurerm/internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import (
postgres "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/postgres/client"
powerBI "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/powerbi/client"
privatedns "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/privatedns/client"
purview "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/purview/client"
recoveryServices "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/recoveryservices/client"
redis "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/redis/client"
redisenterprise "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/redisenterprise/client"
Expand Down Expand Up @@ -172,6 +173,7 @@ type Client struct {
Postgres *postgres.Client
PowerBI *powerBI.Client
PrivateDns *privatedns.Client
Purview *purview.Client
RecoveryServices *recoveryServices.Client
Redis *redis.Client
RedisEnterprise *redisenterprise.Client
Expand Down Expand Up @@ -272,6 +274,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
client.Postgres = postgres.NewClient(o)
client.PowerBI = powerBI.NewClient(o)
client.PrivateDns = privatedns.NewClient(o)
client.Purview = purview.NewClient(o)
client.RecoveryServices = recoveryServices.NewClient(o)
client.Redis = redis.NewClient(o)
client.RedisEnterprise = redisenterprise.NewClient(o)
Expand Down
2 changes: 2 additions & 0 deletions azurerm/internal/provider/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/postgres"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/powerbi"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/privatedns"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/purview"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/recoveryservices"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/redis"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/redisenterprise"
Expand Down Expand Up @@ -173,6 +174,7 @@ func SupportedUntypedServices() []sdk.UntypedServiceRegistration {
postgres.Registration{},
powerbi.Registration{},
privatedns.Registration{},
purview.Registration{},
recoveryservices.Registration{},
redis.Registration{},
redisenterprise.Registration{},
Expand Down
19 changes: 19 additions & 0 deletions azurerm/internal/services/purview/client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package client

import (
"github.com/Azure/azure-sdk-for-go/services/preview/purview/mgmt/2020-12-01-preview/purview"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

type Client struct {
AccountsClient *purview.AccountsClient
}

func NewClient(o *common.ClientOptions) *Client {
accountsClient := purview.NewAccountsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&accountsClient.Client, o.ResourceManagerAuthorizer)

return &Client{
AccountsClient: &accountsClient,
}
}
69 changes: 69 additions & 0 deletions azurerm/internal/services/purview/parse/account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package parse

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import (
"fmt"
"strings"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
)

type AccountId struct {
SubscriptionId string
ResourceGroup string
Name string
}

func NewAccountID(subscriptionId, resourceGroup, name string) AccountId {
return AccountId{
SubscriptionId: subscriptionId,
ResourceGroup: resourceGroup,
Name: name,
}
}

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.Purview/accounts/%s"
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.Name)
}

// AccountID parses a Account ID into an AccountId struct
func AccountID(input string) (*AccountId, error) {
id, err := azure.ParseAzureResourceID(input)
if err != nil {
return nil, err
}

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

if resourceId.SubscriptionId == "" {
return nil, fmt.Errorf("ID was missing the 'subscriptions' element")
}

if resourceId.ResourceGroup == "" {
return nil, fmt.Errorf("ID was missing the 'resourceGroups' element")
}

if resourceId.Name, err = id.PopSegment("accounts"); err != nil {
return nil, err
}

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

return &resourceId, nil
}
112 changes: 112 additions & 0 deletions azurerm/internal/services/purview/parse/account_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package parse

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import (
"testing"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/resourceid"
)

var _ resourceid.Formatter = AccountId{}

func TestAccountIDFormatter(t *testing.T) {
actual := NewAccountID("12345678-1234-9876-4563-123456789012", "resGroup1", "account1").ID()
expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Purview/accounts/account1"
if actual != expected {
t.Fatalf("Expected %q but got %q", expected, actual)
}
}

func TestAccountID(t *testing.T) {
testData := []struct {
Input string
Error bool
Expected *AccountId
}{

{
// empty
Input: "",
Error: true,
},

{
// missing SubscriptionId
Input: "/",
Error: true,
},

{
// missing value for SubscriptionId
Input: "/subscriptions/",
Error: true,
},

{
// missing ResourceGroup
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/",
Error: true,
},

{
// missing value for ResourceGroup
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/",
Error: true,
},

{
// missing Name
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Purview/",
Error: true,
},

{
// missing value for Name
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Purview/accounts/",
Error: true,
},

{
// valid
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Purview/accounts/account1",
Expected: &AccountId{
SubscriptionId: "12345678-1234-9876-4563-123456789012",
ResourceGroup: "resGroup1",
Name: "account1",
},
},

{
// upper-cased
Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.PURVIEW/ACCOUNTS/ACCOUNT1",
Error: true,
},
}

for _, v := range testData {
t.Logf("[DEBUG] Testing %q", v.Input)

actual, err := AccountID(v.Input)
if err != nil {
if v.Error {
continue
}

t.Fatalf("Expect a value but got an error: %s", err)
}
if v.Error {
t.Fatal("Expect an error but didn't get one")
}

if actual.SubscriptionId != v.Expected.SubscriptionId {
t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId)
}
if actual.ResourceGroup != v.Expected.ResourceGroup {
t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup)
}
if actual.Name != v.Expected.Name {
t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name)
}
}
}
Loading

0 comments on commit 02b5e9d

Please sign in to comment.