Skip to content

Commit 01358e7

Browse files
authored
New Resource - azurerm_custom_resource_provider #6234
2 parents ae2e84f + ed8d070 commit 01358e7

File tree

20 files changed

+3070
-0
lines changed

20 files changed

+3070
-0
lines changed

azurerm/internal/clients/client.go

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
containerServices "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/containers/client"
2121
cosmosdb "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/cosmos/client"
2222
costmanagement "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/costmanagement/client"
23+
customproviders "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/customproviders/client"
2324
datamigration "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databasemigration/client"
2425
databricks "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databricks/client"
2526
datafactory "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/client"
@@ -94,6 +95,7 @@ type Client struct {
9495
Containers *containerServices.Client
9596
Cosmos *cosmosdb.Client
9697
CostManagement *costmanagement.Client
98+
CustomProviders *customproviders.Client
9799
DatabaseMigration *datamigration.Client
98100
DataBricks *databricks.Client
99101
DataFactory *datafactory.Client
@@ -169,6 +171,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
169171
client.Containers = containerServices.NewClient(o)
170172
client.Cosmos = cosmosdb.NewClient(o)
171173
client.CostManagement = costmanagement.NewClient(o)
174+
client.CustomProviders = customproviders.NewClient(o)
172175
client.DatabaseMigration = datamigration.NewClient(o)
173176
client.DataBricks = databricks.NewClient(o)
174177
client.DataFactory = datafactory.NewClient(o)

azurerm/internal/provider/required_resource_providers.go

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func RequiredResourceProviders() map[string]struct{} {
2828
"Microsoft.ContainerRegistry": {},
2929
"Microsoft.ContainerService": {},
3030
"Microsoft.CostManagement": {},
31+
"Microsoft.CustomProviders": {},
3132
"Microsoft.Databricks": {},
3233
"Microsoft.DataLakeAnalytics": {},
3334
"Microsoft.DataLakeStore": {},

azurerm/internal/provider/services.go

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/containers"
1717
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/cosmos"
1818
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/costmanagement"
19+
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/customproviders"
1920
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databasemigration"
2021
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databricks"
2122
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory"
@@ -87,6 +88,7 @@ func SupportedServices() []common.ServiceRegistration {
8788
containers.Registration{},
8889
cosmos.Registration{},
8990
costmanagement.Registration{},
91+
customproviders.Registration{},
9092
databricks.Registration{},
9193
datafactory.Registration{},
9294
datalake.Registration{},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package client
2+
3+
import (
4+
"github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders"
5+
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
6+
)
7+
8+
type Client struct {
9+
CustomProviderClient *customproviders.CustomResourceProviderClient
10+
}
11+
12+
func NewClient(o *common.ClientOptions) *Client {
13+
CustomProviderClient := customproviders.NewCustomResourceProviderClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
14+
o.ConfigureClient(&CustomProviderClient.Client, o.ResourceManagerAuthorizer)
15+
16+
return &Client{
17+
CustomProviderClient: &CustomProviderClient,
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package parse
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
7+
)
8+
9+
type CustomProviderId struct {
10+
ResourceGroup string
11+
Name string
12+
}
13+
14+
func CustomProviderID(input string) (*CustomProviderId, error) {
15+
id, err := azure.ParseAzureResourceID(input)
16+
if err != nil {
17+
return nil, fmt.Errorf("[ERROR] Unable to parse Custom Resource Provider ID %q: %+v", input, err)
18+
}
19+
20+
service := CustomProviderId{
21+
ResourceGroup: id.ResourceGroup,
22+
}
23+
24+
if service.Name, err = id.PopSegment("resourceproviders"); err != nil {
25+
return nil, err
26+
}
27+
28+
if err := id.ValidateNoEmptySegments(input); err != nil {
29+
return nil, err
30+
}
31+
32+
return &service, nil
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package parse
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestCustomResourceProviderId(t *testing.T) {
8+
testData := []struct {
9+
Name string
10+
Input string
11+
Expected *CustomProviderId
12+
}{
13+
{
14+
Name: "Empty",
15+
Input: "",
16+
Expected: nil,
17+
},
18+
{
19+
Name: "No Resource Groups Segment",
20+
Input: "/subscriptions/00000000-0000-0000-0000-000000000000",
21+
Expected: nil,
22+
},
23+
{
24+
Name: "No Resource Groups Value",
25+
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/",
26+
Expected: nil,
27+
},
28+
{
29+
Name: "Resource Group ID",
30+
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/",
31+
Expected: nil,
32+
},
33+
{
34+
Name: "Missing Search Services Value",
35+
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.CustomProviders/resourceproviders/",
36+
Expected: nil,
37+
},
38+
{
39+
Name: "Search Service ID",
40+
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.CustomProviders/resourceproviders/Provider1",
41+
Expected: &CustomProviderId{
42+
Name: "Provider1",
43+
ResourceGroup: "resGroup1",
44+
},
45+
},
46+
{
47+
Name: "Wrong Casing",
48+
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.CustomProviders/ResourceProviders/Service1",
49+
Expected: nil,
50+
},
51+
}
52+
53+
for _, v := range testData {
54+
t.Logf("[DEBUG] Testing %q", v.Name)
55+
56+
actual, err := CustomProviderID(v.Input)
57+
if err != nil {
58+
if v.Expected == nil {
59+
continue
60+
}
61+
62+
t.Fatalf("Expected a value but got an error: %s", err)
63+
}
64+
65+
if actual.Name != v.Expected.Name {
66+
t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name)
67+
}
68+
69+
if actual.ResourceGroup != v.Expected.ResourceGroup {
70+
t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup)
71+
}
72+
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package customproviders
2+
3+
import (
4+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
5+
)
6+
7+
type Registration struct{}
8+
9+
// Name is the name of this Service
10+
func (r Registration) Name() string {
11+
return "Custom Providers"
12+
}
13+
14+
// WebsiteCategories returns a list of categories which can be used for the sidebar
15+
func (r Registration) WebsiteCategories() []string {
16+
return []string{
17+
"Custom Providers",
18+
}
19+
}
20+
21+
// SupportedDataSources returns the supported Data Sources supported by this Service
22+
func (r Registration) SupportedDataSources() map[string]*schema.Resource {
23+
return map[string]*schema.Resource{}
24+
}
25+
26+
// SupportedResources returns the supported Resources supported by this Service
27+
func (r Registration) SupportedResources() map[string]*schema.Resource {
28+
return map[string]*schema.Resource{
29+
"azurerm_custom_provider": resourceArmCustomProvider(),
30+
}
31+
}

0 commit comments

Comments
 (0)