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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
resolve comments
ms-zhenhua committed Jun 1, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 8938f1a65863c3823aa435640690e5a8bf441710
35 changes: 14 additions & 21 deletions internal/services/logz/logz_monitor_resource_test.go
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 := "9d186100-1e0f-4b4a-bb10-753d2d52b750@example.com"
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 := "88841ffe-6376-487c-950c-1c3318f63dc5@example.com"
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 := "37d395aa-4b30-4566-b141-72ea4bf84e11@example.com"
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 := "d5d750ce-94fd-475d-816f-48110e1ca04a@example.com"
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,7 +224,7 @@ resource "azurerm_logz_monitor" "test" {
}

user {
email = "%s@example.com"
email = "%s"
first_name = "first"
last_name = "last"
phone_number = "123456"
@@ -236,10 +234,5 @@ resource "azurerm_logz_monitor" "test" {
ENV = "Test"
}
}
`, template, getLogzInstanceName(data.RandomInteger), effectiveDate, email)
}

func getLogzInstanceName(randomInteger int) string {
// The prefix of `liftr_test_only_` is used for test only which should not be used in production environment. Whenever creating a new Logz monitor/subaccount resource with an unused email address, a new email account will also be created in https://logz.io/. When the resource name starts with `liftr_test_only_`, the Azure service will notify https://logz.io/ that this resource is for test only and the email account could be deleted after this resource is deleted, which will not cause data pollution in https://logz.io/
return fmt.Sprintf("liftr_test_only_m%s", strconv.Itoa(randomInteger)[3:])
`, template, data.RandomInteger, effectiveDate, email)
}
34 changes: 13 additions & 21 deletions internal/services/logz/logz_sub_account_resource_test.go
Original file line number Diff line number Diff line change
@@ -3,12 +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"
@@ -23,7 +20,7 @@ func TestAccLogzSubAccount_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_logz_sub_account", "test")
r := LogzSubAccountResource{}
effectiveDate := time.Now().Add(time.Hour * 7).Format(time.RFC3339)
email := uuid.New().String()
email := "0bc0fe71-6e2f-4552-bc48-6ca0c22f4db0@example.com"
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data, effectiveDate, email),
@@ -39,7 +36,7 @@ func TestAccLogzSubAccount_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_logz_sub_account", "test")
r := LogzSubAccountResource{}
effectiveDate := time.Now().Add(time.Hour * 7).Format(time.RFC3339)
email := uuid.New().String()
email := "429420d4-0abf-4cd8-b149-fe63fa141fc6@example.com"
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data, effectiveDate, email),
@@ -58,7 +55,7 @@ func TestAccLogzSubAccount_complete(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_logz_sub_account", "test")
r := LogzSubAccountResource{}
effectiveDate := time.Now().Add(time.Hour * 7).Format(time.RFC3339)
email := uuid.New().String()
email := "253e466c-3a78-4a79-9260-98854eef2b5c@example.com"
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.complete(data, effectiveDate, email),
@@ -74,7 +71,7 @@ func TestAccLogzSubAccount_update(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_logz_sub_account", "test")
r := LogzSubAccountResource{}
effectiveDate := time.Now().Add(time.Hour * 7).Format(time.RFC3339)
email := uuid.New().String()
email := "5c3b9a35-06c5-4c75-928e-6505a10541a5@example.com"
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data, effectiveDate, email),
@@ -129,7 +126,7 @@ resource "azurerm_resource_group" "test" {
}

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 {
@@ -140,13 +137,13 @@ resource "azurerm_logz_monitor" "test" {
}

user {
email = "%s@example.com"
email = "%s"
first_name = "first"
last_name = "last"
phone_number = "123456"
}
}
`, data.RandomInteger, data.Locations.Primary, getLogzInstanceName(data.RandomInteger), effectiveDate, email)
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, effectiveDate, email)
}

func (r LogzSubAccountResource) basic(data acceptance.TestData, effectiveDate string, email string) string {
@@ -155,7 +152,7 @@ func (r LogzSubAccountResource) basic(data acceptance.TestData, effectiveDate st
%s

resource "azurerm_logz_sub_account" "test" {
name = "%s"
name = "acctest-lsa-%d"
logz_monitor_id = azurerm_logz_monitor.test.id
user {
email = azurerm_logz_monitor.test.user[0].email
@@ -164,7 +161,7 @@ resource "azurerm_logz_sub_account" "test" {
phone_number = azurerm_logz_monitor.test.user[0].phone_number
}
}
`, template, getLogzSubAccountName(data.RandomInteger))
`, template, data.RandomInteger)
}

func (r LogzSubAccountResource) update(data acceptance.TestData, effectiveDate string, email string) string {
@@ -173,7 +170,7 @@ func (r LogzSubAccountResource) update(data acceptance.TestData, effectiveDate s
%s

resource "azurerm_logz_sub_account" "test" {
name = "%s"
name = "acctest-lsa-%d"
logz_monitor_id = azurerm_logz_monitor.test.id
user {
email = azurerm_logz_monitor.test.user[0].email
@@ -183,7 +180,7 @@ resource "azurerm_logz_sub_account" "test" {
}
enabled = false
}
`, template, getLogzSubAccountName(data.RandomInteger))
`, template, data.RandomInteger)
}

func (r LogzSubAccountResource) requiresImport(data acceptance.TestData, effectiveDate string, email string) string {
@@ -210,7 +207,7 @@ func (r LogzSubAccountResource) complete(data acceptance.TestData, effectiveDate
%s

resource "azurerm_logz_sub_account" "test" {
name = "%s"
name = "acctest-lsa-%d"
logz_monitor_id = azurerm_logz_monitor.test.id
user {
email = azurerm_logz_monitor.test.user[0].email
@@ -223,10 +220,5 @@ resource "azurerm_logz_sub_account" "test" {
ENV = "Test"
}
}
`, template, getLogzSubAccountName(data.RandomInteger))
}

func getLogzSubAccountName(randomInteger int) string {
// The prefix of `liftr_test_only_` is used for test only which should not be used in production environment. Whenever creating a new Logz monitor/subaccount resource with an unused email address, a new email account will also be created in https://logz.io/. When the resource name starts with `liftr_test_only_`, the Azure service will notify https://logz.io/ that this resource is for test only and the email account could be deleted after this resource is deleted, which will not cause data pollution in https://logz.io/.
return fmt.Sprintf("liftr_test_only_s%s", strconv.Itoa(randomInteger)[3:])
`, template, data.RandomInteger)
}
15 changes: 7 additions & 8 deletions internal/services/logz/logz_tag_rule_resource_test.go
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@ import (
"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"
@@ -20,7 +19,7 @@ type LogzTagRuleResource struct{}
func TestAccLogzTagRule_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_logz_tag_rule", "test")
r := LogzTagRuleResource{}
email := uuid.New().String()
email := "71212724-7a73-48c3-9399-de59313d4905@example.com"
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data, email),
@@ -35,7 +34,7 @@ func TestAccLogzTagRule_basic(t *testing.T) {
func TestAccLogzTagRule_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_logz_tag_rule", "test")
r := LogzTagRuleResource{}
email := uuid.New().String()
email := "b993f18e-9094-4a38-9e80-a0530ebbc6e2@example.com"
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data, email),
@@ -53,7 +52,7 @@ func TestAccLogzTagRule_requiresImport(t *testing.T) {
func TestAccLogzTagRule_complete(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_logz_tag_rule", "test")
r := LogzTagRuleResource{}
email := uuid.New().String()
email := "9121e724-355c-4b74-9d73-ff118ce7241e@example.com"
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.complete(data, email),
@@ -68,7 +67,7 @@ func TestAccLogzTagRule_complete(t *testing.T) {
func TestAccLogzTagRule_update(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_logz_tag_rule", "test")
r := LogzTagRuleResource{}
email := uuid.New().String()
email := "41a35aed-12d8-46f3-a2a7-9f89404d7989@example.com"
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data, email),
@@ -121,7 +120,7 @@ resource "azurerm_resource_group" "test" {
}

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 {
@@ -132,13 +131,13 @@ resource "azurerm_logz_monitor" "test" {
}

user {
email = "%s@example.com"
email = "%s"
first_name = "first"
last_name = "last"
phone_number = "123456"
}
}
`, data.RandomInteger, data.Locations.Primary, getLogzInstanceName(data.RandomInteger), getEffectiveDate(), email)
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, getEffectiveDate(), email)
}

func (r LogzTagRuleResource) basic(data acceptance.TestData, email string) string {