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 - azurerm_fluid_relay_server #17238

Merged
merged 32 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d769ed8
add fluid relay resource
wuxu92 May 30, 2022
092858a
add test for fluid relay server
wuxu92 Jun 9, 2022
4ce7843
update fluid relay sdk version to 2022-05-26
wuxu92 Jun 12, 2022
119cbca
add relayfluid complete test and remove some log
wuxu92 Jun 14, 2022
367a27f
update website categories of fluid relay
wuxu92 Jun 14, 2022
4fee5e4
fix some issues, need more fix
wuxu92 Jun 14, 2022
ceb3d57
fix pr issue
wuxu92 Jun 15, 2022
22e0fa3
remove comment in test file
wuxu92 Jun 16, 2022
29d6d7e
fix typo
wuxu92 Jun 16, 2022
b2f3a1a
add ami test, remove Ptr/Value generic functions in utils
wuxu92 Jun 16, 2022
d7dfbc8
add computed filed check in fluid relay server
wuxu92 Jun 16, 2022
ca4e439
regenerate relay fluid
wuxu92 Jun 16, 2022
7831406
update website markdown format
wuxu92 Jun 16, 2022
9270092
terrafmt fluidrelay test
wuxu92 Jun 16, 2022
307bd11
fix systemAndUser identity and update test
wuxu92 Jun 17, 2022
54afef0
terrafmt
wuxu92 Jun 17, 2022
af85657
restore fluid relay server name validator
wuxu92 Jun 17, 2022
b7c33a6
remove embed pandora sdk
wuxu92 Jun 22, 2022
29f6b24
use go-azure-sdk for pandora sdk intead of embed in azurerm
wuxu92 Jun 22, 2022
a547c61
Merge remote-tracking branch 'origin' into t/fluidrelay
wuxu92 Jun 24, 2022
5f5e620
fix website category
wuxu92 Jun 24, 2022
be0f35b
update go generate
wuxu92 Jun 27, 2022
01d67fb
update fluid relay markdown
wuxu92 Jun 28, 2022
032aa12
combine err check if
wuxu92 Jun 28, 2022
4148bd2
remove some not used properties
wuxu92 Jun 28, 2022
ee0aba1
add storage sku support
wuxu92 Jun 28, 2022
67b4d4d
update storage sku and terrafmt
wuxu92 Jun 28, 2022
1de2dc1
set storage sku as force new
wuxu92 Jul 7, 2022
70cd133
Merge remote-tracking branch 'origin/main' into t/fluidrelay
wuxu92 Jul 7, 2022
d48d6f8
Update fluid_relay_servers_resource.go
mbfrahry Jul 7, 2022
2ae5284
Update fluid_relay_servers.html.markdown
mbfrahry Jul 7, 2022
ebc2897
Update fluid_relay_servers_resource.go
mbfrahry Jul 7, 2022
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 .teamcity/components/generated/services.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var services = mapOf(
"eventgrid" to "EventGrid",
"eventhub" to "EventHub",
"firewall" to "Firewall",
"fluidrelay" to "Fluid Relay",
"frontdoor" to "FrontDoor",
"hdinsight" to "HDInsight",
"hpccache" to "HPC Cache",
Expand Down
3 changes: 3 additions & 0 deletions internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (
eventgrid "github.com/hashicorp/terraform-provider-azurerm/internal/services/eventgrid/client"
eventhub "github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/client"
firewall "github.com/hashicorp/terraform-provider-azurerm/internal/services/firewall/client"
fluidrelay "github.com/hashicorp/terraform-provider-azurerm/internal/services/fluidrelay/client"
frontdoor "github.com/hashicorp/terraform-provider-azurerm/internal/services/frontdoor/client"
hdinsight "github.com/hashicorp/terraform-provider-azurerm/internal/services/hdinsight/client"
healthcare "github.com/hashicorp/terraform-provider-azurerm/internal/services/healthcare/client"
Expand Down Expand Up @@ -159,6 +160,7 @@ type Client struct {
EventGrid *eventgrid.Client
Eventhub *eventhub.Client
Firewall *firewall.Client
FluidRelay *fluidrelay.Client
Frontdoor *frontdoor.Client
HPCCache *hpccache.Client
HSM *hsm.Client
Expand Down Expand Up @@ -272,6 +274,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
client.EventGrid = eventgrid.NewClient(o)
client.Eventhub = eventhub.NewClient(o)
client.Firewall = firewall.NewClient(o)
client.FluidRelay = fluidrelay.NewClient(o)
client.Frontdoor = frontdoor.NewClient(o)
client.HPCCache = hpccache.NewClient(o)
client.HSM = hsm.NewClient(o)
Expand Down
2 changes: 2 additions & 0 deletions internal/provider/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventgrid"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/firewall"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/fluidrelay"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/frontdoor"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/hdinsight"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/healthcare"
Expand Down Expand Up @@ -121,6 +122,7 @@ func SupportedTypedServices() []sdk.TypedServiceRegistration {
costmanagement.Registration{},
disks.Registration{},
eventhub.Registration{},
fluidrelay.Registration{},
keyvault.Registration{},
loadbalancer.Registration{},
loadtest.Registration{},
Expand Down
19 changes: 19 additions & 0 deletions internal/services/fluidrelay/client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package client

import (
servers "github.com/hashicorp/go-azure-sdk/resource-manager/fluidrelay/2022-05-26/fluidrelayservers"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

type Client struct {
ServerClient *servers.FluidRelayServersClient
}

func NewClient(o *common.ClientOptions) *Client {
serverClient := servers.NewFluidRelayServersClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&serverClient.Client, o.ResourceManagerAuthorizer)

return &Client{
ServerClient: &serverClient,
}
}
270 changes: 270 additions & 0 deletions internal/services/fluidrelay/fluid_relay_servers_resource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
package fluidrelay

import (
"context"
"fmt"
"time"

"github.com/hashicorp/go-azure-helpers/resourcemanager/location"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/identity"
"github.com/hashicorp/go-azure-sdk/resource-manager/fluidrelay/2022-05-26/fluidrelayservers"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/fluidrelay/validate"
"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"
)

type ServerModel struct {
Name string `tfschema:"name"`
ResourceGroup string `tfschema:"resource_group_name"`
Location string `tfschema:"location"`
StorageSKU string `tfschema:"storage_sku"`
FrsTenantId string `tfschema:"frs_tenant_id"`
OrdererEndpoints []string `tfschema:"orderer_endpoints"`
StorageEndpoints []string `tfschema:"storage_endpoints"`
Tags map[string]string `tfschema:"tags"`
Identity []identity.ModelSystemAssignedUserAssigned `tfschema:"identity"`
}

func (s *ServerModel) flattenIdentity(input *identity.SystemAndUserAssignedMap) error {
if input == nil {
return nil
}
config := identity.SystemAndUserAssignedMap{
Type: input.Type,
PrincipalId: input.PrincipalId,
TenantId: input.TenantId,
IdentityIds: make(map[string]identity.UserAssignedIdentityDetails),
}
for k, v := range input.IdentityIds {
config.IdentityIds[k] = identity.UserAssignedIdentityDetails{
ClientId: v.ClientId,
PrincipalId: v.PrincipalId,
}
}
model, err := identity.FlattenSystemAndUserAssignedMapToModel(&config)
if err != nil {
return err
}
s.Identity = *model
return nil
}

type Server struct{}

var _ sdk.ResourceWithUpdate = (*Server)(nil)

func (s Server) Arguments() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.FluidRelayServerName,
},
"resource_group_name": commonschema.ResourceGroupName(),
"location": commonschema.Location(),
"tags": commonschema.Tags(),
"identity": commonschema.SystemAssignedUserAssignedIdentityOptional(),
"storage_sku": {
wuxu92 marked this conversation as resolved.
Show resolved Hide resolved
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice(fluidrelayservers.PossibleValuesForStorageSKU(), false),
},
}
}

func (s Server) Attributes() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"frs_tenant_id": {
Type: pluginsdk.TypeString,
Computed: true,
},
"orderer_endpoints": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
},
"storage_endpoints": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
},
}
}

func (s Server) ModelObject() interface{} {
return &ServerModel{}
}

func (s Server) ResourceType() string {
return "azurerm_fluid_relay_server"
}

func (s Server) Create() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 30 * time.Minute,
Func: func(ctx context.Context, meta sdk.ResourceMetaData) (err error) {
client := meta.Client.FluidRelay.ServerClient

var model ServerModel
if err = meta.Decode(&model); err != nil {
return err
}

subscriptionID := meta.Client.Account.SubscriptionId
id := fluidrelayservers.NewFluidRelayServerID(subscriptionID, model.ResourceGroup, model.Name)

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

return meta.ResourceRequiresImport(s.ResourceType(), id)
}

serverReq := fluidrelayservers.FluidRelayServer{
Location: azure.NormalizeLocation(model.Location),
Name: utils.String(model.Name),
}
if model.Tags != nil {
serverReq.Tags = &model.Tags
}
serverReq.Properties = &fluidrelayservers.FluidRelayServerProperties{}
serverReq.Identity, err = identity.ExpandSystemAndUserAssignedMapFromModel(model.Identity)
if err != nil {
return fmt.Errorf("expanding user identities: %+v", err)
}

if model.StorageSKU != "" {
serverReq.Properties.Storagesku = (*fluidrelayservers.StorageSKU)(&model.StorageSKU)
}
_, err = client.CreateOrUpdate(ctx, id, serverReq)
if err != nil {
return fmt.Errorf("creating %v err: %+v", id, err)
}
meta.SetID(id)

return nil
},
}
}

func (s Server) Update() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 10 * time.Minute,
Func: func(ctx context.Context, meta sdk.ResourceMetaData) (err error) {
client := meta.Client.FluidRelay.ServerClient
id, err := fluidrelayservers.ParseFluidRelayServerID(meta.ResourceData.Id())
if err != nil {
return err
}

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

var upd fluidrelayservers.FluidRelayServerUpdate
if meta.ResourceData.HasChange("tags") {
upd.Tags = &model.Tags
}
if meta.ResourceData.HasChange("identity") {
upd.Identity, err = identity.ExpandSystemAndUserAssignedMapFromModel(model.Identity)
if err != nil {
return fmt.Errorf("expanding user identities: %+v", err)
}
}
if _, err = client.Update(ctx, *id, upd); err != nil {
return fmt.Errorf("updating %s: %v", id, err)
}

return nil
},
}
}

func (s Server) Read() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 5 * time.Minute,
Func: func(ctx context.Context, meta sdk.ResourceMetaData) error {
client := meta.Client.FluidRelay.ServerClient

id, err := fluidrelayservers.ParseFluidRelayServerID(meta.ResourceData.Id())
wuxu92 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}

server, err := client.Get(ctx, *id)
if err != nil {
return fmt.Errorf("retrieving %s: %v", id, err)
}

model := server.Model

output := &ServerModel{
Name: id.FluidRelayServerName,
ResourceGroup: id.ResourceGroup,
Location: location.Normalize(model.Location),
}
if err = output.flattenIdentity(model.Identity); err != nil {
return fmt.Errorf("flattening `identity`: %v", err)
}
if server.Model.Tags != nil {
output.Tags = *server.Model.Tags
}
if prop := model.Properties; prop != nil {
if prop.FrsTenantId != nil {
output.FrsTenantId = *prop.FrsTenantId
}
if points := prop.FluidRelayEndpoints; points != nil {
if points.OrdererEndpoints != nil {
output.OrdererEndpoints = *points.OrdererEndpoints
}
if points.StorageEndpoints != nil {
output.StorageEndpoints = *points.StorageEndpoints
}
}
}
if val, ok := meta.ResourceData.GetOk("storage_sku"); ok {
output.StorageSKU = val.(string)
}
return meta.Encode(output)
},
}
}

func (s Server) Delete() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 10 * time.Minute,
Func: func(ctx context.Context, meta sdk.ResourceMetaData) error {
client := meta.Client.FluidRelay.ServerClient

id, err := fluidrelayservers.ParseFluidRelayServerID(meta.ResourceData.Id())
if err != nil {
return err
}

meta.Logger.Infof("deleting %s", id)
if _, err := client.Delete(ctx, *id); err != nil {
return fmt.Errorf("delete %s: %v", id, err)
}
return nil
},
}
}

func (s Server) IDValidationFunc() pluginsdk.SchemaValidateFunc {
return fluidrelayservers.ValidateFluidRelayServerID
}
Loading