-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Resource: azurerm_logz_sub_account (#16581)
- Loading branch information
1 parent
1679275
commit c8a8897
Showing
15 changed files
with
1,045 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
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)), | ||
} | ||
} | ||
|
||
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, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,9 @@ package logz_test | |
import ( | ||
"context" | ||
"fmt" | ||
"strconv" | ||
"testing" | ||
"time" | ||
|
||
"github.com/google/uuid" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/clients" | ||
|
@@ -22,7 +20,7 @@ func TestAccLogzMonitor_basic(t *testing.T) { | |
data := acceptance.BuildTestData(t, "azurerm_logz_monitor", "test") | ||
r := LogzMonitorResource{} | ||
effectiveDate := time.Now().Add(time.Hour * 7).Format(time.RFC3339) | ||
email := uuid.New().String() | ||
email := "[email protected]" | ||
data.ResourceTest(t, r, []acceptance.TestStep{ | ||
{ | ||
Config: r.basic(data, effectiveDate, email), | ||
|
@@ -38,7 +36,7 @@ func TestAccLogzMonitor_requiresImport(t *testing.T) { | |
data := acceptance.BuildTestData(t, "azurerm_logz_monitor", "test") | ||
r := LogzMonitorResource{} | ||
effectiveDate := time.Now().Add(time.Hour * 7).Format(time.RFC3339) | ||
email := uuid.New().String() | ||
email := "[email protected]" | ||
data.ResourceTest(t, r, []acceptance.TestStep{ | ||
{ | ||
Config: r.basic(data, effectiveDate, email), | ||
|
@@ -57,7 +55,7 @@ func TestAccLogzMonitor_complete(t *testing.T) { | |
data := acceptance.BuildTestData(t, "azurerm_logz_monitor", "test") | ||
r := LogzMonitorResource{} | ||
effectiveDate := time.Now().Add(time.Hour * 7).Format(time.RFC3339) | ||
email := uuid.New().String() | ||
email := "[email protected]" | ||
data.ResourceTest(t, r, []acceptance.TestStep{ | ||
{ | ||
Config: r.complete(data, effectiveDate, email), | ||
|
@@ -73,7 +71,7 @@ func TestAccLogzMonitor_update(t *testing.T) { | |
data := acceptance.BuildTestData(t, "azurerm_logz_monitor", "test") | ||
r := LogzMonitorResource{} | ||
effectiveDate := time.Now().Add(time.Hour * 7).Format(time.RFC3339) | ||
email := uuid.New().String() | ||
email := "[email protected]" | ||
data.ResourceTest(t, r, []acceptance.TestStep{ | ||
{ | ||
Config: r.basic(data, effectiveDate, email), | ||
|
@@ -133,7 +131,7 @@ func (r LogzMonitorResource) basic(data acceptance.TestData, effectiveDate strin | |
%s | ||
resource "azurerm_logz_monitor" "test" { | ||
name = "%s" | ||
name = "acctest-lm-%d" | ||
resource_group_name = azurerm_resource_group.test.name | ||
location = azurerm_resource_group.test.location | ||
plan { | ||
|
@@ -144,13 +142,13 @@ resource "azurerm_logz_monitor" "test" { | |
} | ||
user { | ||
email = "%s@example.com" | ||
email = "%s" | ||
first_name = "first" | ||
last_name = "last" | ||
phone_number = "123456" | ||
} | ||
} | ||
`, template, getLogzInstanceName(data.RandomInteger), effectiveDate, email) | ||
`, template, data.RandomInteger, effectiveDate, email) | ||
} | ||
|
||
func (r LogzMonitorResource) update(data acceptance.TestData, effectiveDate string, email string) string { | ||
|
@@ -159,7 +157,7 @@ func (r LogzMonitorResource) update(data acceptance.TestData, effectiveDate stri | |
%s | ||
resource "azurerm_logz_monitor" "test" { | ||
name = "%s" | ||
name = "acctest-lm-%d" | ||
resource_group_name = azurerm_resource_group.test.name | ||
location = azurerm_resource_group.test.location | ||
plan { | ||
|
@@ -170,14 +168,14 @@ resource "azurerm_logz_monitor" "test" { | |
} | ||
user { | ||
email = "%s@example.com" | ||
email = "%s" | ||
first_name = "first" | ||
last_name = "last" | ||
phone_number = "123456" | ||
} | ||
enabled = false | ||
} | ||
`, template, getLogzInstanceName(data.RandomInteger), effectiveDate, email) | ||
`, template, data.RandomInteger, effectiveDate, email) | ||
} | ||
|
||
func (r LogzMonitorResource) requiresImport(data acceptance.TestData, effectiveDate string, email string) string { | ||
|
@@ -197,7 +195,7 @@ resource "azurerm_logz_monitor" "import" { | |
} | ||
user { | ||
email = "%s@example.com" | ||
email = "%s" | ||
first_name = "first" | ||
last_name = "last" | ||
phone_number = "123456" | ||
|
@@ -212,7 +210,7 @@ func (r LogzMonitorResource) complete(data acceptance.TestData, effectiveDate st | |
%s | ||
resource "azurerm_logz_monitor" "test" { | ||
name = "%s" | ||
name = "acctest-lm-%d" | ||
resource_group_name = azurerm_resource_group.test.name | ||
location = azurerm_resource_group.test.location | ||
|
@@ -226,19 +224,15 @@ resource "azurerm_logz_monitor" "test" { | |
} | ||
user { | ||
email = "%s@example.com" | ||
email = "%s" | ||
first_name = "first" | ||
last_name = "last" | ||
phone_number = "123456" | ||
} | ||
enabled = false | ||
enabled = true | ||
tags = { | ||
ENV = "Test" | ||
} | ||
} | ||
`, template, getLogzInstanceName(data.RandomInteger), effectiveDate, email) | ||
} | ||
|
||
func getLogzInstanceName(randomInteger int) string { | ||
return "liftr_test_only_" + strconv.Itoa(randomInteger)[2:] | ||
`, template, data.RandomInteger, effectiveDate, email) | ||
} |
Oops, something went wrong.