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_logz_sub_account #16581

Merged
merged 9 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
13 changes: 9 additions & 4 deletions internal/services/logz/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
)

type Client struct {
MonitorClient *logz.MonitorsClient
TagRuleClient *logz.TagRulesClient
MonitorClient *logz.MonitorsClient
TagRuleClient *logz.TagRulesClient
SubAccountClient *logz.SubAccountClient
}

func NewClient(o *common.ClientOptions) *Client {
Expand All @@ -17,8 +18,12 @@ func NewClient(o *common.ClientOptions) *Client {
tagRuleClient := logz.NewTagRulesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&tagRuleClient.Client, o.ResourceManagerAuthorizer)

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

return &Client{
MonitorClient: &monitorClient,
TagRuleClient: &tagRuleClient,
MonitorClient: &monitorClient,
TagRuleClient: &tagRuleClient,
SubAccountClient: &subAccountClient,
}
}
62 changes: 62 additions & 0 deletions internal/services/logz/logz_common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package logz

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

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)),
}
}
68 changes: 8 additions & 60 deletions internal/services/logz/logz_monitor_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package logz
import (
"fmt"
"log"
"regexp"
"time"

"github.com/hashicorp/terraform-provider-azurerm/internal/services/logz/validate"

"github.com/Azure/azure-sdk-for-go/services/logz/mgmt/2020-10-01/logz"
"github.com/Azure/go-autorest/autorest/date"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
Expand Down Expand Up @@ -43,13 +44,10 @@ func resourceLogzMonitor() *pluginsdk.Resource {

Schema: map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringMatch(
regexp.MustCompile(`^[\w\-]{1,32}$`),
`The name length must be from 1 to 32 characters. The name can only contain letters, numbers, hyphens and underscore.`,
),
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.LogzMonitorName,
},

"resource_group_name": azure.SchemaResourceGroupName(),
Expand Down Expand Up @@ -130,43 +128,7 @@ func resourceLogzMonitor() *pluginsdk.Resource {
},
},

"user": {
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),
},
},
},
},
"user": SchemaUserInfo(),

"enabled": {
Type: pluginsdk.TypeBool,
Expand Down Expand Up @@ -208,7 +170,7 @@ func resourceLogzMonitorCreate(d *pluginsdk.ResourceData, meta interface{}) erro
Properties: &logz.MonitorProperties{
LogzOrganizationProperties: expandMonitorOrganizationProperties(d),
PlanData: expandMonitorPlanData(d.Get("plan").([]interface{})),
UserInfo: expandMonitorUserInfo(d.Get("user").([]interface{})),
UserInfo: expandUserInfo(d.Get("user").([]interface{})),
MonitoringStatus: monitoringStatus,
},
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
Expand Down Expand Up @@ -350,20 +312,6 @@ func expandMonitorPlanData(input []interface{}) *logz.PlanData {
}
}

func expandMonitorUserInfo(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 flattenMonitorOrganizationProperties(d *pluginsdk.ResourceData, input *logz.OrganizationProperties) {
if input == nil {
return
Expand Down
6 changes: 3 additions & 3 deletions internal/services/logz/logz_monitor_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ provider "azurerm" {

resource "azurerm_resource_group" "test" {
name = "acctest-logz-%d"
location = "%s"
location = "westeurope"
ms-zhenhua marked this conversation as resolved.
Show resolved Hide resolved
}
`, data.RandomInteger, data.Locations.Primary)
`, data.RandomInteger)
}

func (r LogzMonitorResource) basic(data acceptance.TestData, effectiveDate string, email string) string {
Expand Down Expand Up @@ -231,7 +231,7 @@ resource "azurerm_logz_monitor" "test" {
last_name = "last"
phone_number = "123456"
}
enabled = false
enabled = true
ms-zhenhua marked this conversation as resolved.
Show resolved Hide resolved
tags = {
ENV = "Test"
}
Expand Down
Loading