Skip to content

Commit

Permalink
Merge pull request #4305 from terraform-providers/f/marketplace-agree…
Browse files Browse the repository at this point in the history
…ment

New Resource: `azurerm_marketplace_agreement`
  • Loading branch information
tombuildsstuff authored Sep 13, 2019
2 parents 8db5df0 + c91bd13 commit 6502dcf
Show file tree
Hide file tree
Showing 55 changed files with 1,793 additions and 6,765 deletions.
10 changes: 5 additions & 5 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/Azure/go-autorest/autorest/azure"
"github.com/hashicorp/go-azure-helpers/authentication"
"github.com/hashicorp/go-azure-helpers/sender"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/analysisservices"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/apimanagement"
Expand All @@ -17,7 +18,6 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/bot"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/cdn"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/cognitive"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/containers"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/cosmos"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databricks"
Expand Down Expand Up @@ -71,7 +71,7 @@ import (
// resource classes' respective clients.
type ArmClient struct {
// inherit the fields from the parent, so that we should be able to set/access these at either level
common.Client
clients.Client

clientId string
tenantId string
Expand All @@ -91,7 +91,7 @@ type ArmClient struct {
bot *bot.Client
cdn *cdn.Client
cognitive *cognitive.Client
compute *compute.Client
compute *clients.ComputeClient
containers *containers.Client
cosmos *cosmos.Client
databricks *databricks.Client
Expand Down Expand Up @@ -151,7 +151,7 @@ func getArmClient(authConfig *authentication.Config, skipProviderRegistration bo

// client declarations:
client := ArmClient{
Client: common.Client{},
Client: clients.Client{},

clientId: authConfig.ClientID,
tenantId: authConfig.TenantID,
Expand Down Expand Up @@ -219,7 +219,7 @@ func getArmClient(authConfig *authentication.Config, skipProviderRegistration bo
client.bot = bot.BuildClient(o)
client.cdn = cdn.BuildClient(o)
client.cognitive = cognitive.BuildClient(o)
client.compute = compute.BuildClient(o)
client.compute = clients.NewComputeClient(o)
client.containers = containers.BuildClient(o)
client.cosmos = cosmos.BuildClient(o)
client.databricks = databricks.BuildClient(o)
Expand Down
2 changes: 0 additions & 2 deletions azurerm/helpers/azure/resourceid.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ func ParseAzureResourceID(id string) (*ResourceID, error) {
if resourceGroup, ok := componentMap["resourcegroups"]; ok {
idObj.ResourceGroup = resourceGroup
delete(componentMap, "resourcegroups")
} else {
return nil, fmt.Errorf("No resource group name found in: %q", path)
}
}

Expand Down
23 changes: 21 additions & 2 deletions azurerm/helpers/azure/resourceid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ func TestParseAzureResourceID(t *testing.T) {
},
{
"/subscriptions/6d74bdd2-9f84-11e5-9bd9-7831c1c4c038",
nil,
true,
&ResourceID{
SubscriptionID: "6d74bdd2-9f84-11e5-9bd9-7831c1c4c038",
ResourceGroup: "",
Provider: "",
Path: map[string]string{},
},
false,
},
{
"subscriptions/6d74bdd2-9f84-11e5-9bd9-7831c1c4c038",
Expand Down Expand Up @@ -140,9 +145,23 @@ func TestParseAzureResourceID(t *testing.T) {
},
false,
},
{
// missing resource group
"/subscriptions/11111111-1111-1111-1111-111111111111/providers/Microsoft.ApiManagement/service/service1/subscriptions/22222222-2222-2222-2222-222222222222",
&ResourceID{
SubscriptionID: "11111111-1111-1111-1111-111111111111",
Provider: "Microsoft.ApiManagement",
Path: map[string]string{
"service": "service1",
"subscriptions": "22222222-2222-2222-2222-222222222222",
},
},
false,
},
}

for _, test := range testCases {
t.Logf("[DEBUG] Testing %q", test.id)
parsed, err := ParseAzureResourceID(test.id)
if test.expectError && err != nil {
continue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package common
package clients

import "context"
import (
"context"
)

type Client struct {
// StopContext is used for propagating control from Terraform Core (e.g. Ctrl/Cmd+C)
StopContext context.Context

Compute ComputeClient
}
90 changes: 90 additions & 0 deletions azurerm/internal/clients/compute.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package clients

import (
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute"
"github.com/Azure/azure-sdk-for-go/services/marketplaceordering/mgmt/2015-06-01/marketplaceordering"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

type ComputeClient struct {
AvailabilitySetsClient *compute.AvailabilitySetsClient
DisksClient *compute.DisksClient
GalleriesClient *compute.GalleriesClient
GalleryImagesClient *compute.GalleryImagesClient
GalleryImageVersionsClient *compute.GalleryImageVersionsClient
ProximityPlacementGroupsClient *compute.ProximityPlacementGroupsClient
MarketplaceAgreementsClient *marketplaceordering.MarketplaceAgreementsClient
ImagesClient *compute.ImagesClient
SnapshotsClient *compute.SnapshotsClient
UsageClient *compute.UsageClient
VMExtensionImageClient *compute.VirtualMachineExtensionImagesClient
VMExtensionClient *compute.VirtualMachineExtensionsClient
VMScaleSetClient *compute.VirtualMachineScaleSetsClient
VMClient *compute.VirtualMachinesClient
VMImageClient *compute.VirtualMachineImagesClient
}

func NewComputeClient(o *common.ClientOptions) *ComputeClient {
availabilitySetsClient := compute.NewAvailabilitySetsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&availabilitySetsClient.Client, o.ResourceManagerAuthorizer)

disksClient := compute.NewDisksClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&disksClient.Client, o.ResourceManagerAuthorizer)

galleriesClient := compute.NewGalleriesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&galleriesClient.Client, o.ResourceManagerAuthorizer)

galleryImagesClient := compute.NewGalleryImagesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&galleryImagesClient.Client, o.ResourceManagerAuthorizer)

galleryImageVersionsClient := compute.NewGalleryImageVersionsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&galleryImageVersionsClient.Client, o.ResourceManagerAuthorizer)

imagesClient := compute.NewImagesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&imagesClient.Client, o.ResourceManagerAuthorizer)

marketplaceAgreementsClient := marketplaceordering.NewMarketplaceAgreementsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&marketplaceAgreementsClient.Client, o.ResourceManagerAuthorizer)

proximityPlacementGroupsClient := compute.NewProximityPlacementGroupsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&proximityPlacementGroupsClient.Client, o.ResourceManagerAuthorizer)

snapshotsClient := compute.NewSnapshotsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&snapshotsClient.Client, o.ResourceManagerAuthorizer)

usageClient := compute.NewUsageClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&usageClient.Client, o.ResourceManagerAuthorizer)

vmExtensionImageClient := compute.NewVirtualMachineExtensionImagesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&vmExtensionImageClient.Client, o.ResourceManagerAuthorizer)

vmExtensionClient := compute.NewVirtualMachineExtensionsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&vmExtensionClient.Client, o.ResourceManagerAuthorizer)

vmImageClient := compute.NewVirtualMachineImagesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&vmImageClient.Client, o.ResourceManagerAuthorizer)

vmScaleSetClient := compute.NewVirtualMachineScaleSetsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&vmScaleSetClient.Client, o.ResourceManagerAuthorizer)

vmClient := compute.NewVirtualMachinesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&vmClient.Client, o.ResourceManagerAuthorizer)

return &ComputeClient{
AvailabilitySetsClient: &availabilitySetsClient,
DisksClient: &disksClient,
GalleriesClient: &galleriesClient,
GalleryImagesClient: &galleryImagesClient,
GalleryImageVersionsClient: &galleryImageVersionsClient,
ImagesClient: &imagesClient,
MarketplaceAgreementsClient: &marketplaceAgreementsClient,
ProximityPlacementGroupsClient: &proximityPlacementGroupsClient,
SnapshotsClient: &snapshotsClient,
UsageClient: &usageClient,
VMExtensionImageClient: &vmExtensionImageClient,
VMExtensionClient: &vmExtensionClient,
VMScaleSetClient: &vmScaleSetClient,
VMClient: &vmClient,
VMImageClient: &vmImageClient,
}
}
85 changes: 0 additions & 85 deletions azurerm/internal/services/compute/client.go

This file was deleted.

22 changes: 22 additions & 0 deletions azurerm/internal/services/compute/registration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package compute

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

type Registration struct{}

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

// 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{}
}
18 changes: 15 additions & 3 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hashicorp/terraform/terraform"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/common"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

Expand Down Expand Up @@ -44,7 +45,9 @@ func Provider() terraform.ResourceProvider {
// All over the place
//
// For the moment/until that's done, we'll have to continue defining these inline
supportedServices := []common.ServiceRegistration{}
supportedServices := []common.ServiceRegistration{
compute.Registration{},
}

dataSources := map[string]*schema.Resource{
"azurerm_api_management": dataSourceApiManagementService(),
Expand Down Expand Up @@ -309,6 +312,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_mariadb_firewall_rule": resourceArmMariaDBFirewallRule(),
"azurerm_mariadb_server": resourceArmMariaDbServer(),
"azurerm_mariadb_virtual_network_rule": resourceArmMariaDbVirtualNetworkRule(),
"azurerm_marketplace_agreement": resourceArmMarketplaceAgreement(),
"azurerm_media_services_account": resourceArmMediaServicesAccount(),
"azurerm_metric_alertrule": resourceArmMetricAlertRule(),
"azurerm_monitor_autoscale_setting": resourceArmMonitorAutoScaleSetting(),
Expand Down Expand Up @@ -436,8 +440,16 @@ func Provider() terraform.ResourceProvider {
"azurerm_web_application_firewall_policy": resourceArmWebApplicationFirewallPolicy(),
}

// avoids this showing up in test output
var debugLog = func(f string, v ...interface{}) {
if os.Getenv("TF_LOG") == "" {
return
}

log.Printf(f, v...)
}
for _, service := range supportedServices {
log.Printf("[DEBUG] Registering Data Sources for %q..", service.Name())
debugLog("[DEBUG] Registering Data Sources for %q..", service.Name())
for k, v := range service.SupportedDataSources() {
if existing := dataSources[k]; existing != nil {
panic(fmt.Sprintf("An existing Data Source exists for %q", k))
Expand All @@ -446,7 +458,7 @@ func Provider() terraform.ResourceProvider {
dataSources[k] = v
}

log.Printf("[DEBUG] Registering Resources for %q..", service.Name())
debugLog("[DEBUG] Registering Resources for %q..", service.Name())
for k, v := range service.SupportedResources() {
if existing := resources[k]; existing != nil {
panic(fmt.Sprintf("An existing Resource exists for %q", k))
Expand Down
1 change: 1 addition & 0 deletions azurerm/required_resource_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func requiredResourceProviders() map[string]struct{} {
"Microsoft.ManagedIdentity": {},
"Microsoft.Management": {},
"Microsoft.Maps": {},
"Microsoft.MarketplaceOrdering": {},
"Microsoft.Media": {},
"Microsoft.Network": {},
"Microsoft.NotificationHubs": {},
Expand Down
Loading

0 comments on commit 6502dcf

Please sign in to comment.