Skip to content

Commit

Permalink
refactor: updating logz to use github.com/hashicorp/go-azure-sdk (#…
Browse files Browse the repository at this point in the history
…21321)

* r/logz_monitor: refactoring to use `go-azure-sdk`

* r/logz_tag_rule: refactoring to use go-azure-sdk

* r/logz_sub_account: refactoring to use go-azure-sdk

* r/logz_sub_account_tag_rule: refactoring to use `hashicorp/go-azure-sdk`

* go mod tidy/go mod vendor

* r/logz_monitor: using the value for `user` from the state

* r/logz_sub_account: `properties.UserInfo` isn't returned from the API

Tracked in Azure/azure-rest-api-specs#23461 (comment)
  • Loading branch information
tombuildsstuff authored Apr 17, 2023
1 parent d1f264e commit b7a2f42
Show file tree
Hide file tree
Showing 109 changed files with 5,344 additions and 7,306 deletions.
27 changes: 12 additions & 15 deletions internal/services/logz/client/client.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
package client

import (
"github.com/Azure/azure-sdk-for-go/services/logz/mgmt/2020-10-01/logz" // nolint: staticcheck
"github.com/hashicorp/go-azure-sdk/resource-manager/logz/2020-10-01/monitors"
"github.com/hashicorp/go-azure-sdk/resource-manager/logz/2020-10-01/subaccount"
"github.com/hashicorp/go-azure-sdk/resource-manager/logz/2020-10-01/tagrules"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

type Client struct {
MonitorClient *logz.MonitorsClient
TagRuleClient *logz.TagRulesClient
SubAccountClient *logz.SubAccountClient
SubAccountTagRuleClient *logz.SubAccountTagRulesClient
MonitorClient *monitors.MonitorsClient
TagRuleClient *tagrules.TagRulesClient
SubAccountClient *subaccount.SubAccountClient
}

func NewClient(o *common.ClientOptions) *Client {
monitorClient := logz.NewMonitorsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
monitorClient := monitors.NewMonitorsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&monitorClient.Client, o.ResourceManagerAuthorizer)

tagRuleClient := logz.NewTagRulesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
tagRuleClient := tagrules.NewTagRulesClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&tagRuleClient.Client, o.ResourceManagerAuthorizer)

subAccountClient := logz.NewSubAccountClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
subAccountClient := subaccount.NewSubAccountClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&subAccountClient.Client, o.ResourceManagerAuthorizer)

subAccountTagRuleClient := logz.NewSubAccountTagRulesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&subAccountTagRuleClient.Client, o.ResourceManagerAuthorizer)

return &Client{
MonitorClient: &monitorClient,
TagRuleClient: &tagRuleClient,
SubAccountClient: &subAccountClient,
SubAccountTagRuleClient: &subAccountTagRuleClient,
MonitorClient: &monitorClient,
TagRuleClient: &tagRuleClient,
SubAccountClient: &subAccountClient,
}
}
131 changes: 1 addition & 130 deletions internal/services/logz/logz_common.go
Original file line number Diff line number Diff line change
@@ -1,139 +1,10 @@
package logz

import (
"fmt"

"github.com/Azure/azure-sdk-for-go/services/logz/mgmt/2020-10-01/logz" // nolint: staticcheck
"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"
)

const TagRuleName = "default"
import "fmt"

const PlanId100gb14days = "100gb14days"
const PlanDetails100gb14days = "100gb14days@TIDgmz7xq9ge3py"

func SchemaUserInfo() *pluginsdk.Schema {
return &pluginsdk.Schema{
Type: pluginsdk.TypeList,
Required: true,
ForceNew: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"email": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"first_name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 50),
},

"last_name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 50),
},

"phone_number": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 40),
},
},
},
}
}

func expandUserInfo(input []interface{}) *logz.UserInfo {
if len(input) == 0 || input[0] == nil {
return nil
}

v := input[0].(map[string]interface{})
return &logz.UserInfo{
FirstName: utils.String(v["first_name"].(string)),
LastName: utils.String(v["last_name"].(string)),
EmailAddress: utils.String(v["email"].(string)),
PhoneNumber: utils.String(v["phone_number"].(string)),
}
}

func flattenUserInfo(input *logz.UserInfo) []interface{} {
if input == nil {
return make([]interface{}, 0)
}

var firstName string
if input.FirstName != nil {
firstName = *input.FirstName
}

var lastName string
if input.LastName != nil {
lastName = *input.LastName
}

var email string
if input.EmailAddress != nil {
email = *input.EmailAddress
}

var phoneNumber string
if input.PhoneNumber != nil {
phoneNumber = *input.PhoneNumber
}

return []interface{}{
map[string]interface{}{
"first_name": firstName,
"last_name": lastName,
"email": email,
"phone_number": phoneNumber,
},
}
}

func schemaTagFilter() *pluginsdk.Schema {
return &pluginsdk.Schema{
Type: pluginsdk.TypeList,
Optional: true,
MaxItems: 10,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"action": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
string(logz.TagActionInclude),
string(logz.TagActionExclude),
}, false),
},

"value": {
Type: pluginsdk.TypeString,
Optional: true,
},
},
},
}
}

func getPlanDetails(plan string) (string, error) {
if plan == PlanId100gb14days {
return PlanDetails100gb14days, nil
Expand Down
Loading

0 comments on commit b7a2f42

Please sign in to comment.