Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
neil-yechenwei committed May 13, 2021
1 parent 415baf2 commit da5a9cb
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package parse

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import (
"fmt"
"strings"
Expand Down Expand Up @@ -34,7 +32,7 @@ func (id TenantConfigurationId) ID() string {

// TenantConfigurationID parses a TenantConfiguration ID into an TenantConfigurationId struct
func TenantConfigurationID(input string) (*TenantConfigurationId, error) {
id, err := azure.ParseAzureResourceID(input)
id, err := azure.ParseAzureResourceIDWithoutSubscription(input)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package parse

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import (
"testing"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,24 @@ import (

type PortalTenantConfigurationResource struct{}

func TestAccPortalTenantConfiguration_basic(t *testing.T) {
func TestAccPortalTenantConfiguration(t *testing.T) {
// NOTE: this is a combined test rather than separate split out tests due to
// Azure only being able provision one default Tenant Configuration at a time
acceptance.RunTestsInSequence(t, map[string]map[string]func(t *testing.T){
"resource": {
"basic": testAccPortalTenantConfiguration_basic,
"update": testAccPortalTenantConfiguration_update,
"requiresImport": testAccPortalTenantConfiguration_requiresImport,
},
})
}

func testAccPortalTenantConfiguration_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_tenant_configuration", "test")
r := PortalTenantConfigurationResource{}
data.ResourceTest(t, r, []resource.TestStep{
data.ResourceSequentialTest(t, r, []resource.TestStep{
{
Config: r.basic(),
Config: r.basic(true),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
Expand All @@ -30,12 +42,12 @@ func TestAccPortalTenantConfiguration_basic(t *testing.T) {
})
}

func TestAccPortalTenantConfiguration_requiresImport(t *testing.T) {
func testAccPortalTenantConfiguration_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_tenant_configuration", "test")
r := PortalTenantConfigurationResource{}
data.ResourceTest(t, r, []resource.TestStep{
data.ResourceSequentialTest(t, r, []resource.TestStep{
{
Config: r.basic(),
Config: r.basic(true),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
Expand All @@ -44,6 +56,27 @@ func TestAccPortalTenantConfiguration_requiresImport(t *testing.T) {
})
}

func testAccPortalTenantConfiguration_update(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_tenant_configuration", "test")
r := PortalTenantConfigurationResource{}
data.ResourceSequentialTest(t, r, []resource.TestStep{
{
Config: r.basic(true),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.basic(false),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (r PortalTenantConfigurationResource) Exists(ctx context.Context, client *clients.Client, state *terraform.InstanceState) (*bool, error) {
id, err := parse.TenantConfigurationID(state.ID)
if err != nil {
Expand All @@ -58,24 +91,24 @@ func (r PortalTenantConfigurationResource) Exists(ctx context.Context, client *c
return utils.Bool(resp.ConfigurationProperties != nil), nil
}

func (r PortalTenantConfigurationResource) basic() string {
func (r PortalTenantConfigurationResource) basic(enforcePrivateMarkdownStorage bool) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_tenant_configuration" "test" {
enforce_private_markdown_storage = true
enforce_private_markdown_storage = %t
}
`)
`, enforcePrivateMarkdownStorage)
}

func (r PortalTenantConfigurationResource) requiresImport(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
resource "azurerm_portal_tenant_configuration" "import" {
enforce_private_markdown_storage = azurerm_portal_tenant_configuration.test.enforce_private_markdown_storage
resource "azurerm_tenant_configuration" "import" {
enforce_private_markdown_storage = azurerm_tenant_configuration.test.enforce_private_markdown_storage
}
`, r.basic())
`, r.basic(true))
}
1 change: 0 additions & 1 deletion azurerm/internal/services/portal/resourceids.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package portal

//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=Dashboard -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Portal/dashboards/dashboard1
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=TenantConfiguration -id=/providers/Microsoft.Portal/tenantConfigurations/default
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package validate

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import (
"fmt"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package validate

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import "testing"

func TestTenantConfigurationID(t *testing.T) {
Expand Down

0 comments on commit da5a9cb

Please sign in to comment.