-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
required_resource_providers.go
77 lines (71 loc) · 3.05 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
package azurerm
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.Authorization": {},
"Microsoft.Automation": {},
"Microsoft.Cache": {},
"Microsoft.Cdn": {},
"Microsoft.CognitiveServices": {},
"Microsoft.Compute": {},
"Microsoft.ContainerInstance": {},
"Microsoft.ContainerRegistry": {},
"Microsoft.ContainerService": {},
"Microsoft.Databricks": {},
"Microsoft.DataLakeAnalytics": {},
"Microsoft.DataLakeStore": {},
"Microsoft.DBforMySQL": {},
"Microsoft.DBforPostgreSQL": {},
"Microsoft.Devices": {},
"Microsoft.DevSpaces": {},
"Microsoft.DevTestLab": {},
"Microsoft.DocumentDB": {},
"Microsoft.EventGrid": {},
"Microsoft.EventHub": {},
"Microsoft.KeyVault": {},
"microsoft.insights": {},
"Microsoft.Logic": {},
"Microsoft.ManagedIdentity": {},
"Microsoft.Management": {},
"Microsoft.Network": {},
"Microsoft.NotificationHubs": {},
"Microsoft.OperationalInsights": {},
"Microsoft.OperationsManagement": {},
"Microsoft.Relay": {},
"Microsoft.RecoveryServices": {},
"Microsoft.Resources": {},
"Microsoft.Scheduler": {},
"Microsoft.Search": {},
"Microsoft.Security": {},
"Microsoft.ServiceBus": {},
"Microsoft.ServiceFabric": {},
"Microsoft.Sql": {},
"Microsoft.Storage": {},
"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
}