Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sinbai committed Nov 29, 2024
1 parent 13b9ed3 commit 9fe5c10
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 53 deletions.
5 changes: 4 additions & 1 deletion .github/labeler-issue-triage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ service/event-hubs:
- '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_eventhub((.|\n)*)###'

service/extended-location:
- '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_(extended_custom_location|fabric_capacity)((.|\n)*)###'
- '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_extended_custom_location((.|\n)*)###'

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

service/firewall:
- '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_firewall((.|\n)*)###'
Expand Down
5 changes: 5 additions & 0 deletions .github/labeler-pull-request-triage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ service/extended-location:
- any-glob-to-any-file:
- internal/services/extendedlocation/**/*

service/fabric:
- changed-files:
- any-glob-to-any-file:
- internal/services/fabric/**/*

service/firewall:
- changed-files:
- any-glob-to-any-file:
Expand Down
2 changes: 1 addition & 1 deletion internal/services/fabric/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Client struct {
func NewClient(o *common.ClientOptions) (*Client, error) {
fabricCapacitiesClient, err := fabriccapacities.NewFabricCapacitiesClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building fabric client: %+v", err)
return nil, fmt.Errorf("building capacities client: %+v", err)
}
o.Configure(fabricCapacitiesClient.Client, o.Authorizers.ResourceManager)

Expand Down
66 changes: 22 additions & 44 deletions internal/services/fabric/fabric_capacity_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ type FabricCapacityResource struct{}

var _ sdk.ResourceWithUpdate = FabricCapacityResource{}

var _ sdk.ResourceWithCustomizeDiff = FabricCapacityResource{}

type FabricCapacityResourceModel struct {
Name string `tfschema:"name"`
ResourceGroupName string `tfschema:"resource_group_name"`
Expand Down Expand Up @@ -71,11 +69,22 @@ func (r FabricCapacityResource) Arguments() map[string]*pluginsdk.Schema {
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
"F2",
"F4",
"F8",
"F16",
"F32",
"F64",
"F128",
"F256",
"F512",
"F1024",
"F2048",
}, false),
},

"tier": {
Type: pluginsdk.TypeString,
Required: true,
Expand All @@ -88,7 +97,7 @@ func (r FabricCapacityResource) Arguments() map[string]*pluginsdk.Schema {
},

"administration_members": {
Type: pluginsdk.TypeList,
Type: pluginsdk.TypeSet,
Optional: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
Expand Down Expand Up @@ -137,7 +146,7 @@ func (r FabricCapacityResource) Create() sdk.ResourceFunc {
Members: model.AdministrationMembers,
},
},
Sku: pointer.From(expandSkuModel(model.Sku)),
Sku: expandSkuModel(model.Sku),
}

if model.Tags != nil {
Expand Down Expand Up @@ -187,7 +196,7 @@ func (r FabricCapacityResource) Update() sdk.ResourceFunc {
}

if metadata.ResourceData.HasChange("sku") {
payload.Sku = pointer.From(expandSkuModel(model.Sku))
payload.Sku = expandSkuModel(model.Sku)
}

if metadata.ResourceData.HasChange("tags") {
Expand Down Expand Up @@ -231,7 +240,7 @@ func (r FabricCapacityResource) Read() sdk.ResourceFunc {
if model := resp.Model; model != nil {
state.Location = location.Normalize(model.Location)
state.AdministrationMembers = model.Properties.Administration.Members
state.Sku = flattenSkuModel(&model.Sku)
state.Sku = flattenSkuModel(model.Sku)
state.Tags = pointer.From(model.Tags)
}

Expand Down Expand Up @@ -260,47 +269,16 @@ func (r FabricCapacityResource) Delete() sdk.ResourceFunc {
}
}

func (r FabricCapacityResource) CustomizeDiff() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 5 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
var state FabricCapacityResourceModel
if err := metadata.DecodeDiff(&state); err != nil {
return fmt.Errorf("DecodeDiff: %+v", err)
}

if len(state.AdministrationMembers) > 0 {
existing := make(map[string]bool)
for _, str := range state.AdministrationMembers {
if existing[str] {
return fmt.Errorf("`administration_members` contains the duplicate value %q", str)
}
existing[str] = true
}
}

return nil
},
}
}

func expandSkuModel(inputList []SkuModel) *fabriccapacities.RpSku {
if len(inputList) == 0 {
return nil
}

func expandSkuModel(inputList []SkuModel) fabriccapacities.RpSku {
input := &inputList[0]
return &fabriccapacities.RpSku{
return fabriccapacities.RpSku{
Name: input.Name,
Tier: fabriccapacities.RpSkuTier(input.Tier),
}
}

func flattenSkuModel(input *fabriccapacities.RpSku) []SkuModel {
func flattenSkuModel(input fabriccapacities.RpSku) []SkuModel {
outputList := make([]SkuModel, 0)
if input == nil {
return outputList
}
output := SkuModel{
Name: input.Name,
Tier: string(input.Tier),
Expand Down
7 changes: 1 addition & 6 deletions internal/services/fabric/fabric_capacity_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"testing"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/fabric/2023-11-01/fabriccapacities"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
Expand Down Expand Up @@ -99,12 +98,8 @@ func (r FabricFabricCapacityResource) Exists(ctx context.Context, clients *clien
return nil, err
}

client := clients.Fabric.FabricCapacitiesClient
resp, err := client.Get(ctx, *id)
resp, err := clients.Fabric.FabricCapacitiesClient.Get(ctx, *id)
if err != nil {
if response.WasNotFound(resp.HttpResponse) {
return pointer.To(false), nil
}
return nil, fmt.Errorf("retrieving %s: %+v", *id, err)
}
return pointer.To(resp.Model != nil), nil
Expand Down
4 changes: 4 additions & 0 deletions internal/services/fabric/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ type Registration struct{}

var _ sdk.TypedServiceRegistration = Registration{}

func (r Registration) AssociatedGitHubLabel() string {
return "service/fabric"
}

// Name is the name of this Service
func (r Registration) Name() string {
return "Fabric"
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/fabric_capacity.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ The following arguments are supported:

A `sku` block supports the following:

* `name` - (Required) The name of the SKU to use for the Fabric Capacity.
* `name` - (Required) The name of the SKU to use for the Fabric Capacity. Possible values are `F2`, `F4`, `F8`, `F16`, `F32`, `F64`, `F128`, `F256`, `F512`, `F1024`, `F2048`.

* `tier` - (Required) The tier of the SKU to use for the Fabric Capacity. The only possible value is `Fabric`.

Expand Down

0 comments on commit 9fe5c10

Please sign in to comment.