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

New resource & data source: azurerm_managed_application_definition #6211

Merged
merged 18 commits into from
Mar 28, 2020
Merged
135 changes: 69 additions & 66 deletions azurerm/internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
loganalytics "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/loganalytics/client"
logic "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/logic/client"
machinelearning "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/machinelearning/client"
managedapplication "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/managedapplication/client"
managementgroup "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/managementgroup/client"
maps "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/maps/client"
mariadb "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/mariadb/client"
Expand Down Expand Up @@ -81,72 +82,73 @@ type Client struct {
Account *ResourceManagerAccount
Features features.UserFeatures

AnalysisServices *analysisServices.Client
ApiManagement *apiManagement.Client
AppConfiguration *appConfiguration.Client
AppInsights *applicationInsights.Client
Authorization *authorization.Client
Automation *automation.Client
Batch *batch.Client
Bot *bot.Client
Cdn *cdn.Client
Cognitive *cognitiveServices.Client
Compute *compute.Client
Containers *containerServices.Client
Cosmos *cosmosdb.Client
CostManagement *costmanagement.Client
CustomProviders *customproviders.Client
DatabaseMigration *datamigration.Client
DataBricks *databricks.Client
DataFactory *datafactory.Client
Datalake *datalake.Client
DevSpace *devspace.Client
DevTestLabs *devtestlabs.Client
Dns *dns.Client
EventGrid *eventgrid.Client
Eventhub *eventhub.Client
Frontdoor *frontdoor.Client
HDInsight *hdinsight.Client
HealthCare *healthcare.Client
IoTHub *iothub.Client
IoTCentral *iotcentral.Client
KeyVault *keyvault.Client
Kusto *kusto.Client
LogAnalytics *loganalytics.Client
Logic *logic.Client
MachineLearning *machinelearning.Client
ManagementGroups *managementgroup.Client
Maps *maps.Client
MariaDB *mariadb.Client
Media *media.Client
MixedReality *mixedreality.Client
Monitor *monitor.Client
MSI *msi.Client
MSSQL *mssql.Client
MySQL *mysql.Client
NetApp *netapp.Client
Network *network.Client
NotificationHubs *notificationhub.Client
Policy *policy.Client
Portal *portal.Client
Postgres *postgres.Client
PowerBI *powerBI.Client
PrivateDns *privatedns.Client
RecoveryServices *recoveryServices.Client
Redis *redis.Client
Relay *relay.Client
Resource *resource.Client
Search *search.Client
SecurityCenter *securityCenter.Client
ServiceBus *serviceBus.Client
ServiceFabric *serviceFabric.Client
SignalR *signalr.Client
Storage *storage.Client
StreamAnalytics *streamAnalytics.Client
Subscription *subscription.Client
Sql *sql.Client
TrafficManager *trafficManager.Client
Web *web.Client
AnalysisServices *analysisServices.Client
ApiManagement *apiManagement.Client
AppConfiguration *appConfiguration.Client
AppInsights *applicationInsights.Client
Authorization *authorization.Client
Automation *automation.Client
Batch *batch.Client
Bot *bot.Client
Cdn *cdn.Client
Cognitive *cognitiveServices.Client
Compute *compute.Client
Containers *containerServices.Client
Cosmos *cosmosdb.Client
CostManagement *costmanagement.Client
CustomProviders *customproviders.Client
DatabaseMigration *datamigration.Client
DataBricks *databricks.Client
DataFactory *datafactory.Client
Datalake *datalake.Client
DevSpace *devspace.Client
DevTestLabs *devtestlabs.Client
Dns *dns.Client
EventGrid *eventgrid.Client
Eventhub *eventhub.Client
Frontdoor *frontdoor.Client
HDInsight *hdinsight.Client
HealthCare *healthcare.Client
IoTHub *iothub.Client
IoTCentral *iotcentral.Client
KeyVault *keyvault.Client
Kusto *kusto.Client
LogAnalytics *loganalytics.Client
Logic *logic.Client
MachineLearning *machinelearning.Client
ManagedApplication *managedapplication.Client
ManagementGroups *managementgroup.Client
Maps *maps.Client
MariaDB *mariadb.Client
Media *media.Client
MixedReality *mixedreality.Client
Monitor *monitor.Client
MSI *msi.Client
MSSQL *mssql.Client
MySQL *mysql.Client
NetApp *netapp.Client
Network *network.Client
NotificationHubs *notificationhub.Client
Policy *policy.Client
Portal *portal.Client
Postgres *postgres.Client
PowerBI *powerBI.Client
PrivateDns *privatedns.Client
RecoveryServices *recoveryServices.Client
Redis *redis.Client
Relay *relay.Client
Resource *resource.Client
Search *search.Client
SecurityCenter *securityCenter.Client
ServiceBus *serviceBus.Client
ServiceFabric *serviceFabric.Client
SignalR *signalr.Client
Storage *storage.Client
StreamAnalytics *streamAnalytics.Client
Subscription *subscription.Client
Sql *sql.Client
TrafficManager *trafficManager.Client
Web *web.Client
}

// NOTE: it should be possible for this method to become Private once the top level Client's removed
Expand Down Expand Up @@ -191,6 +193,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
client.LogAnalytics = loganalytics.NewClient(o)
client.Logic = logic.NewClient(o)
client.MachineLearning = machinelearning.NewClient(o)
client.ManagedApplication = managedapplication.NewClient(o)
client.ManagementGroups = managementgroup.NewClient(o)
client.Maps = maps.NewClient(o)
client.MariaDB = mariadb.NewClient(o)
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 @@ -36,6 +36,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/loganalytics"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/logic"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/machinelearning"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/managedapplication"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/managementgroup"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/maps"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/mariadb"
Expand Down Expand Up @@ -108,6 +109,7 @@ func SupportedServices() []common.ServiceRegistration {
loganalytics.Registration{},
logic.Registration{},
machinelearning.Registration{},
managedapplication.Registration{},
managementgroup.Registration{},
maps.Registration{},
mariadb.Registration{},
Expand Down
19 changes: 19 additions & 0 deletions azurerm/internal/services/managedapplication/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/resources/mgmt/2019-07-01/managedapplications"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

type Client struct {
ApplicationDefinitionClient *managedapplications.ApplicationDefinitionsClient
}

func NewClient(o *common.ClientOptions) *Client {
applicationDefinitionClient := managedapplications.NewApplicationDefinitionsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&applicationDefinitionClient.Client, o.ResourceManagerAuthorizer)

return &Client{
ApplicationDefinitionClient: &applicationDefinitionClient,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package managedapplication

import (
"fmt"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/managedapplication/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func dataSourceArmManagedApplicationDefinition() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmManagedApplicationDefinitionRead,

Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(5 * time.Minute),
},

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.ManagedApplicationDefinitionName,
},

"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),

"location": azure.SchemaLocationForDataSource(),
},
}
}

func dataSourceArmManagedApplicationDefinitionRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).ManagedApplication.ApplicationDefinitionClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)

resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Managed Application Definition (Managed Application Definition Name %q / Resource Group %q) was not found", name, resourceGroup)
}
return fmt.Errorf("failed to read Managed Application Definition (Managed Application Definition Name %q / Resource Group %q): %+v", name, resourceGroup, err)
}

d.Set("name", name)
d.Set("resource_group_name", resourceGroup)
if location := resp.Location; location != nil {
d.Set("location", azure.NormalizeLocation(*location))
}

if resp.ID == nil || *resp.ID == "" {
return fmt.Errorf("API returns a nil/empty id on Managed Application Definition %q (Resource Group %q): %+v", name, resourceGroup, err)
}
d.SetId(*resp.ID)

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package parse

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

type ManagedApplicationDefinitionId struct {
Name string
ResourceGroup string
}

func ManagedApplicationDefinitionID(input string) (*ManagedApplicationDefinitionId, error) {
id, err := azure.ParseAzureResourceID(input)
if err != nil {
return nil, err
}

account := ManagedApplicationDefinitionId{
ResourceGroup: id.ResourceGroup,
}

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

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

return &account, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package parse

import (
"testing"
)

func TestManagedApplicationDefinitionID(t *testing.T) {
testData := []struct {
Name string
Input string
Error bool
Expect *ManagedApplicationDefinitionId
}{
{
Name: "Empty",
Input: "",
Error: true,
},
{
Name: "No Resource Groups Segment",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000",
Error: true,
},
{
Name: "No Resource Groups Value",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups",
Error: true,
},
{
Name: "Resource Group ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1",
Error: true,
},
{
Name: "Missing Managed Application Definition Value",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Solutions/applicationDefinitions",
Error: true,
},
{
Name: "Managed Application Definition ID",
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Solutions/applicationDefinitions/appDef1",
Error: false,
Expect: &ManagedApplicationDefinitionId{
Name: "appDef1",
ResourceGroup: "group1",
},
},
}

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

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

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

if actual.Name != v.Expect.Name {
t.Fatalf("Expected %q but got %q for Name", v.Expect.Name, actual.Name)
}

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

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 "Managed Applications"
}

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

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

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