/
required_resource_providers.go
97 lines (91 loc) · 4.01 KB
/
required_resource_providers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package provider
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/profiles/2017-03-09/resources/mgmt/resources"
"github.com/hashicorp/go-azure-helpers/resourceproviders"
)
// RequiredResourceProviders returns all of the Resource Providers used by the AzureRM Provider
// whilst all may not be used by every user - the intention is that we determine which should be
// registered such that we can avoid obscure errors where Resource Providers aren't registered.
// new Resource Providers should be added to this list as they're used in the Provider
// (this is the approach used by Microsoft in their tooling)
func RequiredResourceProviders() map[string]struct{} {
// NOTE: Resource Providers in this list are case sensitive
return map[string]struct{}{
"Microsoft.ApiManagement": {},
"Microsoft.AppPlatform": {},
"Microsoft.Authorization": {},
"Microsoft.Automation": {},
"Microsoft.Blueprints": {},
"Microsoft.BotService": {},
"Microsoft.Cache": {},
"Microsoft.Cdn": {},
"Microsoft.CognitiveServices": {},
"Microsoft.Compute": {},
"Microsoft.ContainerInstance": {},
"Microsoft.ContainerRegistry": {},
"Microsoft.ContainerService": {},
"Microsoft.CostManagement": {},
"Microsoft.CustomProviders": {},
"Microsoft.Databricks": {},
"Microsoft.DataLakeAnalytics": {},
"Microsoft.DataLakeStore": {},
"Microsoft.DataMigration": {},
"Microsoft.DBforMariaDB": {},
"Microsoft.DBforMySQL": {},
"Microsoft.DBforPostgreSQL": {},
"Microsoft.Devices": {},
"Microsoft.DevSpaces": {},
"Microsoft.DevTestLab": {},
"Microsoft.DocumentDB": {},
"Microsoft.EventGrid": {},
"Microsoft.EventHub": {},
"Microsoft.HDInsight": {},
"Microsoft.Healthcare": {},
"Microsoft.KeyVault": {},
"Microsoft.Kusto": {},
"microsoft.insights": {},
"Microsoft.Logic": {},
"Microsoft.MachineLearningServices": {},
"Microsoft.Maintenance": {},
"Microsoft.ManagedIdentity": {},
"Microsoft.Management": {},
"Microsoft.Maps": {},
"Microsoft.MarketplaceOrdering": {},
"Microsoft.Media": {},
"Microsoft.MixedReality": {},
"Microsoft.Network": {},
"Microsoft.NotificationHubs": {},
"Microsoft.OperationalInsights": {},
"Microsoft.OperationsManagement": {},
"Microsoft.PowerBIDedicated": {},
"Microsoft.Relay": {},
"Microsoft.RecoveryServices": {},
"Microsoft.Resources": {},
"Microsoft.Search": {},
"Microsoft.Security": {},
"Microsoft.SecurityInsights": {},
"Microsoft.ServiceBus": {},
"Microsoft.ServiceFabric": {},
"Microsoft.Sql": {},
"Microsoft.Storage": {},
"Microsoft.StorageCache": {},
"Microsoft.StreamAnalytics": {},
"Microsoft.TimeSeriesInsights": {},
"Microsoft.Web": {},
}
}
func EnsureResourceProvidersAreRegistered(ctx context.Context, client resources.ProvidersClient, availableRPs []resources.Provider, requiredRPs map[string]struct{}) error {
log.Printf("[DEBUG] Determining which Resource Providers require Registration")
providersToRegister := resourceproviders.DetermineResourceProvidersRequiringRegistration(availableRPs, requiredRPs)
if len(providersToRegister) > 0 {
log.Printf("[DEBUG] Registering %d Resource Providers", len(providersToRegister))
if err := resourceproviders.RegisterForSubscription(ctx, client, providersToRegister); err != nil {
return err
}
} else {
log.Printf("[DEBUG] All required Resource Providers are registered")
}
return nil
}