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

Add new resource & data source: azurerm_powerbi_embedded #5152

Merged
merged 20 commits into from
Mar 17, 2020
3 changes: 3 additions & 0 deletions azurerm/internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import (
policy "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/policy/client"
portal "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/portal/client"
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"
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"
Expand Down Expand Up @@ -118,6 +119,7 @@ type Client struct {
Policy *policy.Client
Portal *portal.Client
Postgres *postgres.Client
PowerBI *powerBI.Client
PrivateDns *privatedns.Client
RecoveryServices *recoveryServices.Client
Redis *redis.Client
Expand Down Expand Up @@ -186,6 +188,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
client.Policy = policy.NewClient(o)
client.Portal = portal.NewClient(o)
client.Postgres = postgres.NewClient(o)
client.PowerBI = powerBI.NewClient(o)
client.PrivateDns = privatedns.NewClient(o)
client.RecoveryServices = recoveryServices.NewClient(o)
client.Redis = redis.NewClient(o)
Expand Down
1 change: 1 addition & 0 deletions azurerm/internal/provider/required_resource_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func RequiredResourceProviders() map[string]struct{} {
"Microsoft.NotificationHubs": {},
"Microsoft.OperationalInsights": {},
"Microsoft.OperationsManagement": {},
"Microsoft.PowerBIDedicated": {},
"Microsoft.Relay": {},
"Microsoft.RecoveryServices": {},
"Microsoft.Resources": {},
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 @@ -46,6 +46,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/policy"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/portal"
"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/recoveryservices"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/redis"
Expand Down Expand Up @@ -112,6 +113,7 @@ func SupportedServices() []common.ServiceRegistration {
policy.Registration{},
portal.Registration{},
postgres.Registration{},
powerbi.Registration{},
privatedns.Registration{},
recoveryservices.Registration{},
redis.Registration{},
Expand Down
19 changes: 19 additions & 0 deletions azurerm/internal/services/powerbi/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/powerbidedicated/mgmt/2017-10-01/powerbidedicated"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

type Client struct {
CapacityClient *powerbidedicated.CapacitiesClient
}

func NewClient(o *common.ClientOptions) *Client {
capacityClient := powerbidedicated.NewCapacitiesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&capacityClient.Client, o.ResourceManagerAuthorizer)

return &Client{
CapacityClient: &capacityClient,
}
}
33 changes: 33 additions & 0 deletions azurerm/internal/services/powerbi/parse/powerbi_embedded.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package parse

import (
"fmt"

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

type PowerBIEmbeddedId struct {
ResourceGroup string
Name string
}

func PowerBIEmbeddedID(input string) (*PowerBIEmbeddedId, error) {
id, err := azure.ParseAzureResourceID(input)
if err != nil {
return nil, fmt.Errorf("[ERROR] Unable to parse PowerBI Embedded ID %q: %+v", input, err)
}

powerbiEmbedded := PowerBIEmbeddedId{
ResourceGroup: id.ResourceGroup,
}

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

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

return &powerbiEmbedded, nil
}
67 changes: 67 additions & 0 deletions azurerm/internal/services/powerbi/parse/powerbi_embedded_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package parse

import (
"testing"
)

func TestPowerBIEmbeddedId(t *testing.T) {
testData := []struct {
Name string
Input string
Expected *PowerBIEmbeddedId
}{
{
Name: "Empty",
Input: "",
Expected: nil,
},
{
Name: "No Resource Groups Segment",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000",
Expected: nil,
},
{
Name: "No Resource Groups Value",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/",
Expected: nil,
},
{
Name: "Resource Group ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/",
Expected: nil,
},
{
Name: "Missing PowerBI Embedded value",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.PowerBIDedicated/capacities",
Expected: nil,
},
{
Name: "PowerBI Embedded ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.PowerBIDedicated/capacities/capacity1",
Expected: &PowerBIEmbeddedId{
ResourceGroup: "resGroup1",
Name: "capacity1",
},
},
}

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

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

t.Fatalf("Expected a value but got an error: %s", err)
}

if actual.Name != v.Expected.Name {
t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name)
}
if actual.ResourceGroup != v.Expected.ResourceGroup {
t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup)
}
}
}
30 changes: 30 additions & 0 deletions azurerm/internal/services/powerbi/registration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package powerbi

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

type Registration struct{}

// Name is the name of this Service
func (r Registration) Name() string {
return "PowerBI"
}

// WebsiteCategories returns a list of categories which can be used for the sidebar
func (r Registration) WebsiteCategories() []string {
return []string{
"PowerBI",
}
}

// SupportedDataSources returns the supported Data Sources supported by this Service
func (r Registration) SupportedDataSources() map[string]*schema.Resource {
return map[string]*schema.Resource{}
}

// SupportedResources returns the supported Resources supported by this Service
func (r Registration) SupportedResources() map[string]*schema.Resource {
return map[string]*schema.Resource{
"azurerm_powerbi_embedded": resourceArmPowerBIEmbedded()}
}
Loading