Skip to content

Commit

Permalink
Merge pull request #30 from hashicorp/main
Browse files Browse the repository at this point in the history
Fork Sync: Update from parent repository
  • Loading branch information
mbialon authored Sep 27, 2023
2 parents 777a847 + 09cadb0 commit 2d3136e
Show file tree
Hide file tree
Showing 64 changed files with 3,246 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/labeler-issue-triage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ service/service-fabric:
service/service-fabric-managed-cluster:
- '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_service_fabric_managed_cluster((.|\n)*)###'

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

service/signalr:
- '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_(signalr_s|web_pubsub)((.|\n)*)###'

Expand Down
3 changes: 3 additions & 0 deletions .github/labeler-pull-request-triage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ service/service-fabric:
service/service-fabric-managed-cluster:
- internal/services/servicefabricmanaged/**/*

service/service-networking:
- internal/services/servicenetworking/**/*

service/signalr:
- internal/services/signalr/**/*

Expand Down
1 change: 1 addition & 0 deletions .teamcity/components/generated/services.kt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ var services = mapOf(
"sentinel" to "Sentinel",
"servicefabric" to "Service Fabric",
"servicefabricmanaged" to "Service Fabric Managed Clusters",
"servicenetworking" to "Service Networking",
"servicebus" to "ServiceBus",
"serviceconnector" to "ServiceConnector",
"signalr" to "SignalR",
Expand Down
3 changes: 3 additions & 0 deletions .teamcity/components/settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ var serviceTestConfigurationOverrides = mapOf(
// Synapse is only available in certain locations
"synapse" to testConfiguration(locationOverride = LocationConfiguration("westeurope", "francecentral", "eastus2", false)),

// ServiceNetworking is available in certain locations
"servicenetworking" to testConfiguration(locationOverride = LocationConfiguration("eastus","westus","westeurope", false)),

// Currently, we have insufficient quota to actually run these, but there are a few nodes in West Europe, so we'll pin it there for now
"vmware" to testConfiguration(parallelism = 3, locationOverride = LocationConfiguration("westeurope", "westus2", "eastus2", false)),

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## 3.75.0 (Unreleased)

FEATURES:

* New Resource: `azurerm_application_load_balancer` [GH-22517]

BUG FIXES:

* `azurerm_api_management_api` : fix importing `openapi` format content file issue [GH-23348]
Expand Down
6 changes: 6 additions & 0 deletions internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
fluidrelay_2022_05_26 "github.com/hashicorp/go-azure-sdk/resource-manager/fluidrelay/2022-05-26"
nginx2 "github.com/hashicorp/go-azure-sdk/resource-manager/nginx/2022-08-01"
redis_v2023_04_01 "github.com/hashicorp/go-azure-sdk/resource-manager/redis/2023-04-01"
servicenetworking_v2023_05_01_preview "github.com/hashicorp/go-azure-sdk/resource-manager/servicenetworking/2023-05-01-preview"
storagecache_2023_05_01 "github.com/hashicorp/go-azure-sdk/resource-manager/storagecache/2023-05-01"
timeseriesinsights_v2020_05_15 "github.com/hashicorp/go-azure-sdk/resource-manager/timeseriesinsights/2020-05-15"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
Expand Down Expand Up @@ -130,6 +131,7 @@ import (
serviceConnector "github.com/hashicorp/terraform-provider-azurerm/internal/services/serviceconnector/client"
serviceFabric "github.com/hashicorp/terraform-provider-azurerm/internal/services/servicefabric/client"
serviceFabricManaged "github.com/hashicorp/terraform-provider-azurerm/internal/services/servicefabricmanaged/client"
serviceNetworking "github.com/hashicorp/terraform-provider-azurerm/internal/services/servicenetworking/client"
signalr "github.com/hashicorp/terraform-provider-azurerm/internal/services/signalr/client"
appPlatform "github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud/client"
sql "github.com/hashicorp/terraform-provider-azurerm/internal/services/sql/client"
Expand Down Expand Up @@ -263,6 +265,7 @@ type Client struct {
ServiceConnector *serviceConnector.Client
ServiceFabric *serviceFabric.Client
ServiceFabricManaged *serviceFabricManaged.Client
ServiceNetworking *servicenetworking_v2023_05_01_preview.Client
SignalR *signalr.Client
Storage *storage.Client
StorageMover *storageMover.Client
Expand Down Expand Up @@ -574,6 +577,9 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
client.ServiceConnector = serviceConnector.NewClient(o)
client.ServiceFabric = serviceFabric.NewClient(o)
client.ServiceFabricManaged = serviceFabricManaged.NewClient(o)
if client.ServiceNetworking, err = serviceNetworking.NewClient(o); err != nil {
return fmt.Errorf("building clients for ServiceNetworking: %+v", err)
}
if client.SignalR, err = signalr.NewClient(o); err != nil {
return fmt.Errorf("building clients for SignalR: %+v", err)
}
Expand Down
2 changes: 2 additions & 0 deletions internal/provider/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/services/serviceconnector"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/servicefabric"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/servicefabricmanaged"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/servicenetworking"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/signalr"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/springcloud"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/sql"
Expand Down Expand Up @@ -192,6 +193,7 @@ func SupportedTypedServices() []sdk.TypedServiceRegistration {
sentinel.Registration{},
serviceconnector.Registration{},
servicefabricmanaged.Registration{},
servicenetworking.Registration{},
storage.Registration{},
storagemover.Registration{},
signalr.Registration{},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
package servicenetworking

import (
"context"
"fmt"
"regexp"
"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-sdk/resource-manager/servicenetworking/2023-05-01-preview/trafficcontrollerinterface"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tags"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
)

type ApplicationLoadBalancerResource struct{}

type ApplicationLoadBalancerModel struct {
Name string `tfschema:"name"`
ResourceGroupName string `tfschema:"resource_group_name"`
Location string `tfschema:"location"`
PrimaryConfigurationEndpoints string `tfschema:"primary_configuration_endpoint"`
Tags map[string]string `tfschema:"tags"`
}

var _ sdk.ResourceWithUpdate = ApplicationLoadBalancerResource{}

func (t ApplicationLoadBalancerResource) Arguments() map[string]*schema.Schema {
return map[string]*schema.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,62}[a-zA-Z0-9]$`), "the name must begin with a letter or number, end with a letter, number or underscore, and may contain only letters, numbers, underscores, periods, or hyphens. The value must be 1-64 characters long."),
},

"resource_group_name": commonschema.ResourceGroupName(),

"location": commonschema.Location(),

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

func (t ApplicationLoadBalancerResource) Attributes() map[string]*schema.Schema {
return map[string]*schema.Schema{
"primary_configuration_endpoint": {
Type: pluginsdk.TypeString,
Computed: true,
},
}
}

func (t ApplicationLoadBalancerResource) ModelObject() interface{} {
return &ApplicationLoadBalancerModel{}
}

func (t ApplicationLoadBalancerResource) ResourceType() string {
return "azurerm_application_load_balancer"
}

func (t ApplicationLoadBalancerResource) IDValidationFunc() pluginsdk.SchemaValidateFunc {
return trafficcontrollerinterface.ValidateTrafficControllerID
}

func (t ApplicationLoadBalancerResource) Create() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 30 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.ServiceNetworking.TrafficControllerInterface
subscriptionId := metadata.Client.Account.SubscriptionId

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

id := trafficcontrollerinterface.NewTrafficControllerID(subscriptionId, config.ResourceGroupName, config.Name)
existing, err := client.Get(ctx, id)
if err != nil {
if !response.WasNotFound(existing.HttpResponse) {
return fmt.Errorf("checking for presence of existing %s: %+v", id, err)
}
}

if !response.WasNotFound(existing.HttpResponse) {
return metadata.ResourceRequiresImport(t.ResourceType(), id)
}

payload := trafficcontrollerinterface.TrafficController{
Location: location.Normalize(config.Location),
Tags: pointer.To(config.Tags),
}

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

metadata.SetID(id)
return nil
},
}
}

func (t ApplicationLoadBalancerResource) Read() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 5 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.ServiceNetworking.TrafficControllerInterface

id, err := trafficcontrollerinterface.ParseTrafficControllerID(metadata.ResourceData.Id())
if err != nil {
return fmt.Errorf("parsing %s: %+v", metadata.ResourceData.Id(), 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", metadata.ResourceData.Id(), err)
}

state := ApplicationLoadBalancerModel{
Name: id.TrafficControllerName,
ResourceGroupName: id.ResourceGroupName,
}

if model := resp.Model; model != nil {
state.Location = model.Location
state.Tags = pointer.From(model.Tags)

if prop := model.Properties; prop != nil {
if endpoint := prop.ConfigurationEndpoints; endpoint != nil && len(*endpoint) > 0 {
state.PrimaryConfigurationEndpoints = (*endpoint)[0]
}
}
}

return metadata.Encode(&state)
},
}
}

func (t ApplicationLoadBalancerResource) Update() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 30 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.ServiceNetworking.TrafficControllerInterface

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

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

payload := trafficcontrollerinterface.TrafficControllerUpdate{
Tags: pointer.To(config.Tags),
}

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

return nil
},
}
}

func (t ApplicationLoadBalancerResource) Delete() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 30 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.ServiceNetworking.TrafficControllerInterface

id, err := trafficcontrollerinterface.ParseTrafficControllerID(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
},
}
}
Loading

0 comments on commit 2d3136e

Please sign in to comment.