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

Auto PR - New Resources: azurerm_dev_center / azurerm_dev_center_project #23538

Merged
merged 4 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/labeler-issue-triage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ service/datadog:
- '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_datadog_monitor((.|\n)*)###'

service/dev-center:
- '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_dev_center((.|\n)*)###'

service/devtestlabs:
- '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_dev_test_((.|\n)*)###'
Expand Down
3 changes: 3 additions & 0 deletions .teamcity/components/settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ var serviceTestConfigurationOverrides = mapOf(
// data factory uses NC class VMs which are not available in eastus2
"datafactory" to testConfiguration(daysOfWeek = "2,4,6", locationOverride = LocationConfiguration("westeurope", "southeastasia", "westus2", false)),

// Dev Center only available in some regions / has a quota of 5
"devcenter" to testConfiguration(parallelism = 4, locationOverride = LocationConfiguration("westeurope", "uksouth", "canadacentral", false)),

// "hdinsight" is super expensive - G class VM's are not available in westus2, quota only available in westeurope currently
"hdinsight" to testConfiguration(daysOfWeek = "2,4,6", locationOverride = LocationConfiguration("westeurope", "southeastasia", "eastus2", false)),

Expand Down
6 changes: 6 additions & 0 deletions internal/clients/client_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import (

"github.com/hashicorp/terraform-provider-azurerm/internal/common"
containers "github.com/hashicorp/terraform-provider-azurerm/internal/services/containers/client"
devcenter "github.com/hashicorp/terraform-provider-azurerm/internal/services/devcenter/client"
loadtestservice "github.com/hashicorp/terraform-provider-azurerm/internal/services/loadtestservice/client"
managedidentity "github.com/hashicorp/terraform-provider-azurerm/internal/services/managedidentity/client"
)

type autoClient struct {
ContainerService *containers.AutoClient
DevCenter *devcenter.AutoClient
LoadTestService *loadtestservice.AutoClient
ManagedIdentity *managedidentity.AutoClient
}
Expand All @@ -23,6 +25,10 @@ func buildAutoClients(client *autoClient, o *common.ClientOptions) (err error) {
return fmt.Errorf("building client for ContainerService: %+v", err)
}

if client.DevCenter, err = devcenter.NewClient(o); err != nil {
return fmt.Errorf("building client for DevCenter: %+v", err)
}

if client.LoadTestService, err = loadtestservice.NewClient(o); err != nil {
return fmt.Errorf("building client for LoadTestService: %+v", err)
}
Expand Down
27 changes: 27 additions & 0 deletions internal/services/devcenter/client/client_gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package client

import (
"fmt"

devcenterV20230401 "github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2023-04-01"
"github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

type AutoClient struct {
V20230401 devcenterV20230401.Client
}

func NewClient(o *common.ClientOptions) (*AutoClient, error) {

v20230401Client, err := devcenterV20230401.NewClientWithBaseURI(o.Environment.ResourceManager, func(c *resourcemanager.Client) {
o.Configure(c, o.Authorizers.ResourceManager)
})
if err != nil {
return nil, fmt.Errorf("building client for devcenter V20230401: %+v", err)
}

return &AutoClient{
V20230401: *v20230401Client,
}, nil
}
279 changes: 279 additions & 0 deletions internal/services/devcenter/dev_center_project_resource_gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
package devcenter

// NOTE: this file is generated - manual changes will be overwritten.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See NOTICE.txt in the project root for license information.
import (
"context"
"fmt"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2023-04-01/projects"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
)

var _ sdk.Resource = DevCenterProjectResource{}
var _ sdk.ResourceWithUpdate = DevCenterProjectResource{}

type DevCenterProjectResource struct{}

func (r DevCenterProjectResource) ModelObject() interface{} {
return &DevCenterProjectResourceSchema{}
}

type DevCenterProjectResourceSchema struct {
Description string `tfschema:"description"`
DevCenterId string `tfschema:"dev_center_id"`
DevCenterUri string `tfschema:"dev_center_uri"`
Location string `tfschema:"location"`
MaxDevBoxesPerUser int64 `tfschema:"max_dev_boxes_per_user"`
Name string `tfschema:"name"`
ResourceGroupName string `tfschema:"resource_group_name"`
Tags map[string]interface{} `tfschema:"tags"`
}

func (r DevCenterProjectResource) IDValidationFunc() pluginsdk.SchemaValidateFunc {
return projects.ValidateProjectID
}
func (r DevCenterProjectResource) ResourceType() string {
return "azurerm_dev_center_project"
}
func (r DevCenterProjectResource) Arguments() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"dev_center_id": {
ForceNew: true,
Required: true,
Type: pluginsdk.TypeString,
},
"location": commonschema.Location(),
"name": {
ForceNew: true,
Required: true,
Type: pluginsdk.TypeString,
},
"resource_group_name": commonschema.ResourceGroupName(),
"description": {
ForceNew: true,
Optional: true,
Type: pluginsdk.TypeString,
},
"max_dev_boxes_per_user": {
Optional: true,
Type: pluginsdk.TypeInt,
},
"tags": commonschema.Tags(),
}
}
func (r DevCenterProjectResource) Attributes() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"dev_center_uri": {
Computed: true,
Type: pluginsdk.TypeString,
},
}
}
func (r DevCenterProjectResource) Create() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 30 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.DevCenter.V20230401.Projects

var config DevCenterProjectResourceSchema
if err := metadata.Decode(&config); err != nil {
return fmt.Errorf("decoding: %+v", err)
}

subscriptionId := metadata.Client.Account.SubscriptionId

id := projects.NewProjectID(subscriptionId, config.ResourceGroupName, config.Name)

existing, err := client.Get(ctx, id)
if err != nil {
if !response.WasNotFound(existing.HttpResponse) {
return fmt.Errorf("checking for the presence of an existing %s: %+v", id, err)
}
}
if !response.WasNotFound(existing.HttpResponse) {
return metadata.ResourceRequiresImport(r.ResourceType(), id)
}

var payload projects.Project
if err := r.mapDevCenterProjectResourceSchemaToProject(config, &payload); err != nil {
return fmt.Errorf("mapping schema model to sdk model: %+v", err)
}

if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil {
return fmt.Errorf("creating %s: %+v", id, err)
}

metadata.SetID(id)
return nil
},
}
}
func (r DevCenterProjectResource) Read() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 5 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.DevCenter.V20230401.Projects
schema := DevCenterProjectResourceSchema{}

id, err := projects.ParseProjectID(metadata.ResourceData.Id())
if err != nil {
return err
}

resp, err := client.Get(ctx, *id)
if err != nil {
if response.WasNotFound(resp.HttpResponse) {
return metadata.MarkAsGone(*id)
}
return fmt.Errorf("retrieving %s: %+v", *id, err)
}

if model := resp.Model; model != nil {
schema.Name = id.ProjectName
schema.ResourceGroupName = id.ResourceGroupName
if err := r.mapProjectToDevCenterProjectResourceSchema(*model, &schema); err != nil {
return fmt.Errorf("flattening model: %+v", err)
}
}

return metadata.Encode(&schema)
},
}
}
func (r DevCenterProjectResource) Delete() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 30 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.DevCenter.V20230401.Projects

id, err := projects.ParseProjectID(metadata.ResourceData.Id())
if err != nil {
return err
}

if err := client.DeleteThenPoll(ctx, *id); err != nil {
return fmt.Errorf("deleting %s: %+v", *id, err)
}

return nil
},
}
}
func (r DevCenterProjectResource) Update() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 30 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.DevCenter.V20230401.Projects

id, err := projects.ParseProjectID(metadata.ResourceData.Id())
if err != nil {
return err
}

var config DevCenterProjectResourceSchema
if err := metadata.Decode(&config); err != nil {
return fmt.Errorf("decoding: %+v", err)
}

var payload projects.ProjectUpdate
if err := r.mapDevCenterProjectResourceSchemaToProjectUpdate(config, &payload); err != nil {
return fmt.Errorf("mapping schema model to sdk model: %+v", err)
}

if err := client.UpdateThenPoll(ctx, *id, payload); err != nil {
return fmt.Errorf("updating %s: %+v", *id, err)
}

return nil
},
}
}

func (r DevCenterProjectResource) mapDevCenterProjectResourceSchemaToProjectProperties(input DevCenterProjectResourceSchema, output *projects.ProjectProperties) error {
output.Description = &input.Description
output.DevCenterId = input.DevCenterId

output.MaxDevBoxesPerUser = &input.MaxDevBoxesPerUser
return nil
}

func (r DevCenterProjectResource) mapProjectPropertiesToDevCenterProjectResourceSchema(input projects.ProjectProperties, output *DevCenterProjectResourceSchema) error {
output.Description = pointer.From(input.Description)
output.DevCenterId = input.DevCenterId
output.DevCenterUri = pointer.From(input.DevCenterUri)
output.MaxDevBoxesPerUser = pointer.From(input.MaxDevBoxesPerUser)
return nil
}

func (r DevCenterProjectResource) mapDevCenterProjectResourceSchemaToProject(input DevCenterProjectResourceSchema, output *projects.Project) error {
output.Location = location.Normalize(input.Location)
output.Tags = tags.Expand(input.Tags)

if output.Properties == nil {
output.Properties = &projects.ProjectProperties{}
}
if err := r.mapDevCenterProjectResourceSchemaToProjectProperties(input, output.Properties); err != nil {
return fmt.Errorf("mapping Schema to SDK Field %q / Model %q: %+v", "ProjectProperties", "Properties", err)
}

return nil
}

func (r DevCenterProjectResource) mapProjectToDevCenterProjectResourceSchema(input projects.Project, output *DevCenterProjectResourceSchema) error {
output.Location = location.Normalize(input.Location)
output.Tags = tags.Flatten(input.Tags)

if input.Properties == nil {
input.Properties = &projects.ProjectProperties{}
}
if err := r.mapProjectPropertiesToDevCenterProjectResourceSchema(*input.Properties, output); err != nil {
return fmt.Errorf("mapping SDK Field %q / Model %q to Schema: %+v", "ProjectProperties", "Properties", err)
}

return nil
}

func (r DevCenterProjectResource) mapDevCenterProjectResourceSchemaToProjectUpdateProperties(input DevCenterProjectResourceSchema, output *projects.ProjectUpdateProperties) error {
output.MaxDevBoxesPerUser = &input.MaxDevBoxesPerUser
return nil
}

func (r DevCenterProjectResource) mapProjectUpdatePropertiesToDevCenterProjectResourceSchema(input projects.ProjectUpdateProperties, output *DevCenterProjectResourceSchema) error {
output.MaxDevBoxesPerUser = pointer.From(input.MaxDevBoxesPerUser)
return nil
}

func (r DevCenterProjectResource) mapDevCenterProjectResourceSchemaToProjectUpdate(input DevCenterProjectResourceSchema, output *projects.ProjectUpdate) error {
output.Tags = tags.Expand(input.Tags)

if output.Properties == nil {
output.Properties = &projects.ProjectUpdateProperties{}
}
if err := r.mapDevCenterProjectResourceSchemaToProjectUpdateProperties(input, output.Properties); err != nil {
return fmt.Errorf("mapping Schema to SDK Field %q / Model %q: %+v", "ProjectUpdateProperties", "Properties", err)
}

return nil
}

func (r DevCenterProjectResource) mapProjectUpdateToDevCenterProjectResourceSchema(input projects.ProjectUpdate, output *DevCenterProjectResourceSchema) error {
output.Tags = tags.Flatten(input.Tags)

if input.Properties == nil {
input.Properties = &projects.ProjectUpdateProperties{}
}
if err := r.mapProjectUpdatePropertiesToDevCenterProjectResourceSchema(*input.Properties, output); err != nil {
return fmt.Errorf("mapping SDK Field %q / Model %q to Schema: %+v", "ProjectUpdateProperties", "Properties", err)
}

return nil
}
Loading
Loading