Skip to content

Commit

Permalink
New Resource: azurerm_extended_location_custom_location
Browse files Browse the repository at this point in the history
  • Loading branch information
jiaweitao001 committed Dec 19, 2023
1 parent bf215e9 commit 22f3a0c
Show file tree
Hide file tree
Showing 30 changed files with 868 additions and 978 deletions.
1 change: 1 addition & 0 deletions .teamcity/components/generated/services.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ var services = mapOf(
"elasticsan" to "ElasticSan",
"eventgrid" to "EventGrid",
"eventhub" to "EventHub",
"extendedlocation" to "ExtendedLocation",
"firewall" to "Firewall",
"fluidrelay" to "Fluid Relay",
"frontdoor" to "FrontDoor",
Expand Down
4 changes: 3 additions & 1 deletion internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,9 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
if client.Eventhub, err = eventhub.NewClient(o); err != nil {
return fmt.Errorf("building clients for Eventhub: %+v", err)
}
client.ExtendedLocation = extendedlocation.NewClient(o)
if client.ExtendedLocation, err = extendedlocation.NewClient(o); err != nil {
return fmt.Errorf("building clients for ExtendedLocation: %+v", err)
}
if client.FluidRelay, err = fluidrelay.NewClient(o); err != nil {
return fmt.Errorf("building clients for FluidRelay: %+v", err)
}
Expand Down
14 changes: 9 additions & 5 deletions internal/services/extendedlocation/client/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package client

import (
"fmt"

Check failure on line 4 in internal/services/extendedlocation/client/client.go

View workflow job for this annotation

GitHub Actions / golint

File is not `goimports`-ed (goimports)
"github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)
Expand All @@ -9,11 +10,14 @@ type Client struct {
CustomLocationsClient *customlocations.CustomLocationsClient
}

func NewClient(o *common.ClientOptions) *Client {
customLocationsClient := customlocations.NewCustomLocationsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&customLocationsClient.Client, o.ResourceManagerAuthorizer)
func NewClient(o *common.ClientOptions) (*Client, error) {
customLocationsClient, err := customlocations.NewCustomLocationsClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building CustomLocations client: %+v", err)
}
o.Configure(customLocationsClient.Client, o.Authorizers.ResourceManager)

return &Client{
CustomLocationsClient: &customLocationsClient,
}
CustomLocationsClient: customLocationsClient,
}, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,38 @@ package extendedlocation
import (
"context"
"fmt"
"github.com/hashicorp/go-azure-helpers/lang/pointer"

Check failure on line 6 in internal/services/extendedlocation/extended_location_custom_location.go

View workflow job for this annotation

GitHub Actions / golint

File is not `goimports`-ed (goimports)
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/extendedlocation/2021-08-15/customlocations"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
"github.com/hashicorp/terraform-provider-azurerm/utils"
"time"
)

type CustomLocationResource struct{}

type CustomLocationResourceModel struct {
Name string `tfschema:"name"`
ResourceGroupName string `tfschema:"resource_group_name"`
Location string `tfschema:"location"`
AuthenticationType string `tfschema:"authentication_type"`
AuthenticationValue string `tfschema:"authentication_value"`
ClusterExtensionIds []string `tfschema:"cluster_extension_ids"`
DisplayName string `tfschema:"display_name"`
HostResourceId string `tfschema:"host_resource_id"`
HostType string `tfschema:"host_type"`
Namespace string `tfschema:"namespace"`
Name string `tfschema:"name"`
ResourceGroupName string `tfschema:"resource_group_name"`
Location string `tfschema:"location"`
Authentication []AuthModel `tfschema:"authentication"`
ClusterExtensionIds []string `tfschema:"cluster_extension_ids"`
DisplayName string `tfschema:"display_name"`
HostResourceId string `tfschema:"host_resource_id"`
HostType string `tfschema:"host_type"`
Namespace string `tfschema:"namespace"`
}

type AuthModel struct {
Type string `tfschema:"type"`
Value string `tfschema:"value"`
}

func (r CustomLocationResource) Arguments() map[string]*schema.Schema {
return map[string]*schema.Schema{
func (r CustomLocationResource) Arguments() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
Expand All @@ -51,6 +56,13 @@ func (r CustomLocationResource) Arguments() map[string]*schema.Schema {
ValidateFunc: validation.StringIsNotEmpty,
},

"namespace": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"cluster_extension_ids": {
Type: pluginsdk.TypeList,
Required: true,
Expand All @@ -65,16 +77,24 @@ func (r CustomLocationResource) Arguments() map[string]*schema.Schema {
ValidateFunc: validation.StringIsNotEmpty,
},

"authentication_type": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"authentication_value": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
"authentication": {
Type: pluginsdk.TypeList,
Optional: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"type": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"value": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},
},
},
},

"display_name": {
Expand All @@ -90,25 +110,19 @@ func (r CustomLocationResource) Arguments() map[string]*schema.Schema {
string(customlocations.HostTypeKubernetes),
}, false),
},

"namespace": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},
}
}

func (r CustomLocationResource) Attributes() map[string]*schema.Schema {
return map[string]*schema.Schema{}
func (r CustomLocationResource) Attributes() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{}
}

func (r CustomLocationResource) ModelObject() interface{} {
return &CustomLocationResourceModel{}
}

func (r CustomLocationResource) ResourceType() string {
return "azurerm_extended_custom_locations"
return "azurerm_extended_custom_location"
}

func (r CustomLocationResource) Create() sdk.ResourceFunc {
Expand All @@ -135,10 +149,11 @@ func (r CustomLocationResource) Create() sdk.ResourceFunc {

customLocationProps := customlocations.CustomLocationProperties{}

if model.AuthenticationValue != "" && model.AuthenticationType != "" {
if model.Authentication != nil {
auth := model.Authentication[0]
customLocationProps.Authentication = &customlocations.CustomLocationPropertiesAuthentication{
Type: &model.AuthenticationType,
Value: &model.AuthenticationValue,
Type: &auth.Type,
Value: &auth.Value,
}
}

Expand Down Expand Up @@ -202,14 +217,20 @@ func (r CustomLocationResource) Read() sdk.ResourceFunc {
props := model.Properties

state := CustomLocationResourceModel{
Name: id.ResourceName,
Name: id.CustomLocationName,
ResourceGroupName: id.ResourceGroupName,
Location: model.Location,
}

if props.Authentication != nil && props.Authentication.Type != nil && props.Authentication.Value != nil {
state.AuthenticationType = *props.Authentication.Type
state.AuthenticationValue = *props.Authentication.Value
if props != nil && props.Authentication != nil {
authType := pointer.From(props.Authentication.Type)
authValue := pointer.From(props.Authentication.Value)
state.Authentication = []AuthModel{
{
Type: authType,
Value: authValue,
},
}
}

if props.ClusterExtensionIds != nil {
Expand Down Expand Up @@ -280,10 +301,13 @@ func (r CustomLocationResource) Update() sdk.ResourceFunc {
customLocationProps := customlocations.CustomLocationProperties{}
d := metadata.ResourceData

if d.HasChanges("authentication_type", "authentication_value") {
customLocationProps.Authentication = &customlocations.CustomLocationPropertiesAuthentication{
Type: &state.AuthenticationType,
Value: &state.AuthenticationValue,
if d.HasChanges("authentication") {
if state.Authentication != nil {
auth := state.Authentication[0]
customLocationProps.Authentication = &customlocations.CustomLocationPropertiesAuthentication{
Type: &auth.Type,
Value: &auth.Value,
}
}
}

Expand Down
Loading

0 comments on commit 22f3a0c

Please sign in to comment.