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
131 changes: 67 additions & 64 deletions azurerm/internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
kusto "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/kusto/client"
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"
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 @@ -79,70 +80,71 @@ 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
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
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
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
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 @@ -185,6 +187,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
client.Kusto = kusto.NewClient(o)
client.LogAnalytics = loganalytics.NewClient(o)
client.Logic = logic.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 @@ -34,6 +34,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/kusto"
"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/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 @@ -104,6 +105,7 @@ func SupportedServices() []common.ServiceRegistration {
kusto.Registration{},
loganalytics.Registration{},
logic.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,138 @@
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/tags"
"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,
},

"location": azure.SchemaLocationForDataSource(),

"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),

"authorization": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"role_definition_id": {
Type: schema.TypeString,
Computed: true,
},
"service_principal_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},

"create_ui_definition": {
Type: schema.TypeString,
Computed: true,
},

"description": {
Type: schema.TypeString,
Computed: true,
},

"display_name": {
Type: schema.TypeString,
Computed: true,
},

"package_enabled": {
Type: schema.TypeBool,
Computed: true,
},

"lock_level": {
Type: schema.TypeString,
Computed: true,
},

"main_template": {
Type: schema.TypeString,
Computed: true,
},

"package_file_uri": {
Type: schema.TypeString,
Computed: true,
},
neil-yechenwei marked this conversation as resolved.
Show resolved Hide resolved

"tags": tags.SchemaDataSource(),
},
}
}

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("Failed: Managed Application Definition (Managed Application Definition Name %q / Resource Group %q) was not found", name, resourceGroup)
neil-yechenwei marked this conversation as resolved.
Show resolved Hide resolved
}
return fmt.Errorf("Failure reading 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 props := resp.ApplicationDefinitionProperties; props != nil {
if err := d.Set("authorization", flattenArmManagedApplicationDefinitionAuthorization(props.Authorizations)); err != nil {
return fmt.Errorf("Failure setting `authorization`: %+v", err)
}
d.Set("description", props.Description)
d.Set("display_name", props.DisplayName)
d.Set("package_enabled", props.IsEnabled)
d.Set("lock_level", string(props.LockLevel))
}
if v, ok := d.GetOk("create_ui_definition"); ok {
neil-yechenwei marked this conversation as resolved.
Show resolved Hide resolved
d.Set("create_ui_definition", v.(string))
}
if v, ok := d.GetOk("main_template"); ok {
d.Set("main_template", v.(string))
}
if v, ok := d.GetOk("package_file_uri"); ok {
d.Set("package_file_uri", v.(string))
}

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 tags.FlattenAndSet(d, resp.Tags)
}
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
}
Loading