feat: rp registration (#215)
* feat: rp registration * test: add deployment test * test: fold rp test into valid * docs: update docs * feat: add rp feature reg * fix: testing bugs ready for review * docs: make docs & fmt * docs: add url to var * test: rename to work with filter * test: rename test * test: fix deploy test * refactor: use terratest retry
This commit is contained in:
Родитель
52a68dbdf1
Коммит
f7debc59ff
83
README.md
83
README.md
|
@ -350,6 +350,89 @@ Type: `string`
|
|||
|
||||
Default: `""`
|
||||
|
||||
### <a name="input_subscription_register_resource_providers_and_features"></a> [subscription\_register\_resource\_providers\_and\_features](#input\_subscription\_register\_resource\_providers\_and\_features)
|
||||
|
||||
Description: The map of resource providers to register.
|
||||
The map keys are the resource provider namespace, e.g. `Microsoft.Compute`.
|
||||
The map values are a list of provider features to enable.
|
||||
Leave the value empty to not register any resource provider features.
|
||||
|
||||
The default values are taken from [Hashicorp's AzureRM provider](https://github.com/hashicorp/terraform-provider-azurerm/blob/main/internal/resourceproviders/required.go).
|
||||
|
||||
Type: `map(set(string))`
|
||||
|
||||
Default:
|
||||
|
||||
```json
|
||||
{
|
||||
"Microsoft.AVS": [],
|
||||
"Microsoft.ApiManagement": [],
|
||||
"Microsoft.AppPlatform": [],
|
||||
"Microsoft.Authorization": [],
|
||||
"Microsoft.Automation": [],
|
||||
"Microsoft.Blueprint": [],
|
||||
"Microsoft.BotService": [],
|
||||
"Microsoft.Cache": [],
|
||||
"Microsoft.Cdn": [],
|
||||
"Microsoft.CognitiveServices": [],
|
||||
"Microsoft.Compute": [],
|
||||
"Microsoft.ContainerInstance": [],
|
||||
"Microsoft.ContainerRegistry": [],
|
||||
"Microsoft.ContainerService": [],
|
||||
"Microsoft.CostManagement": [],
|
||||
"Microsoft.CustomProviders": [],
|
||||
"Microsoft.DBforMariaDB": [],
|
||||
"Microsoft.DBforMySQL": [],
|
||||
"Microsoft.DBforPostgreSQL": [],
|
||||
"Microsoft.DataLakeAnalytics": [],
|
||||
"Microsoft.DataLakeStore": [],
|
||||
"Microsoft.DataMigration": [],
|
||||
"Microsoft.DataProtection": [],
|
||||
"Microsoft.Databricks": [],
|
||||
"Microsoft.DesktopVirtualization": [],
|
||||
"Microsoft.DevTestLab": [],
|
||||
"Microsoft.Devices": [],
|
||||
"Microsoft.DocumentDB": [],
|
||||
"Microsoft.EventGrid": [],
|
||||
"Microsoft.EventHub": [],
|
||||
"Microsoft.GuestConfiguration": [],
|
||||
"Microsoft.HDInsight": [],
|
||||
"Microsoft.HealthcareApis": [],
|
||||
"Microsoft.KeyVault": [],
|
||||
"Microsoft.Kusto": [],
|
||||
"Microsoft.Logic": [],
|
||||
"Microsoft.MachineLearningServices": [],
|
||||
"Microsoft.Maintenance": [],
|
||||
"Microsoft.ManagedIdentity": [],
|
||||
"Microsoft.ManagedServices": [],
|
||||
"Microsoft.Management": [],
|
||||
"Microsoft.Maps": [],
|
||||
"Microsoft.MarketplaceOrdering": [],
|
||||
"Microsoft.Media": [],
|
||||
"Microsoft.MixedReality": [],
|
||||
"Microsoft.Network": [],
|
||||
"Microsoft.NotificationHubs": [],
|
||||
"Microsoft.OperationalInsights": [],
|
||||
"Microsoft.OperationsManagement": [],
|
||||
"Microsoft.PolicyInsights": [],
|
||||
"Microsoft.PowerBIDedicated": [],
|
||||
"Microsoft.RecoveryServices": [],
|
||||
"Microsoft.Relay": [],
|
||||
"Microsoft.Resources": [],
|
||||
"Microsoft.Search": [],
|
||||
"Microsoft.Security": [],
|
||||
"Microsoft.SecurityInsights": [],
|
||||
"Microsoft.ServiceBus": [],
|
||||
"Microsoft.ServiceFabric": [],
|
||||
"Microsoft.Sql": [],
|
||||
"Microsoft.Storage": [],
|
||||
"Microsoft.StreamAnalytics": [],
|
||||
"Microsoft.TimeSeriesInsights": [],
|
||||
"Microsoft.Web": [],
|
||||
"microsoft.insights": []
|
||||
}
|
||||
```
|
||||
|
||||
### <a name="input_subscription_tags"></a> [subscription\_tags](#input\_subscription\_tags)
|
||||
|
||||
Description: A map of tags to assign to the newly created subscription.
|
||||
|
|
|
@ -5,13 +5,14 @@ module "subscription" {
|
|||
source = "./modules/subscription"
|
||||
count = var.subscription_alias_enabled || var.subscription_management_group_association_enabled ? 1 : 0
|
||||
|
||||
subscription_alias_enabled = var.subscription_alias_enabled
|
||||
subscription_alias_name = var.subscription_alias_name
|
||||
subscription_billing_scope = var.subscription_billing_scope
|
||||
subscription_display_name = var.subscription_display_name
|
||||
subscription_management_group_association_enabled = var.subscription_management_group_association_enabled
|
||||
subscription_management_group_id = var.subscription_management_group_id
|
||||
subscription_workload = var.subscription_workload
|
||||
subscription_tags = var.subscription_tags
|
||||
subscription_id = var.subscription_id
|
||||
subscription_alias_enabled = var.subscription_alias_enabled
|
||||
subscription_alias_name = var.subscription_alias_name
|
||||
subscription_billing_scope = var.subscription_billing_scope
|
||||
subscription_display_name = var.subscription_display_name
|
||||
subscription_id = var.subscription_id
|
||||
subscription_management_group_association_enabled = var.subscription_management_group_association_enabled
|
||||
subscription_management_group_id = var.subscription_management_group_id
|
||||
subscription_register_resource_providers_and_features = var.subscription_register_resource_providers_and_features
|
||||
subscription_tags = var.subscription_tags
|
||||
subscription_workload = var.subscription_workload
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@ The following requirements are needed by this module:
|
|||
|
||||
- <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) (>= 1.3.0)
|
||||
|
||||
- <a name="requirement_azapi"></a> [azapi](#requirement\_azapi) (>= 1.0.0)
|
||||
|
||||
- <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) (>= 3.7.0)
|
||||
|
||||
## Modules
|
||||
|
@ -151,6 +153,17 @@ Type: `string`
|
|||
|
||||
Default: `""`
|
||||
|
||||
### <a name="input_subscription_register_resource_providers_and_features"></a> [subscription\_register\_resource\_providers\_and\_features](#input\_subscription\_register\_resource\_providers\_and\_features)
|
||||
|
||||
Description: The map of resource providers to register.
|
||||
The map keys are the resource provider namespace, e.g. `Microsoft.Compute`.
|
||||
The map values are a list of provider features to enable.
|
||||
Leave the value empty to not register any resource provider features.
|
||||
|
||||
Type: `map(set(string))`
|
||||
|
||||
Default: `{}`
|
||||
|
||||
### <a name="input_subscription_tags"></a> [subscription\_tags](#input\_subscription\_tags)
|
||||
|
||||
Description: A map of tags to assign to the newly created subscription.
|
||||
|
@ -186,6 +199,8 @@ Default: `""`
|
|||
|
||||
The following resources are used by this module:
|
||||
|
||||
- [azapi_resource_action.resource_provider_feature_registration](https://registry.terraform.io/providers/Azure/azapi/latest/docs/resources/resource_action) (resource)
|
||||
- [azapi_resource_action.resource_provider_registration](https://registry.terraform.io/providers/Azure/azapi/latest/docs/resources/resource_action) (resource)
|
||||
- [azurerm_management_group_subscription_association.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/management_group_subscription_association) (resource)
|
||||
- [azurerm_subscription.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subscription) (resource)
|
||||
|
||||
|
|
|
@ -4,4 +4,21 @@ locals {
|
|||
|
||||
# subscription_id is the id of the newly created subscription, or the id supplied by var.subscription_id.
|
||||
subscription_id = coalesce(local.subscription_id_alias, var.subscription_id)
|
||||
|
||||
# get a set of the RP names and features to register
|
||||
resource_provider_feature_set = toset(flatten([
|
||||
for rp, features in var.subscription_register_resource_providers_and_features : [
|
||||
for feature in features : {
|
||||
resource_provider_name = rp
|
||||
feature_name = feature
|
||||
} if length(features) > 0
|
||||
]
|
||||
]))
|
||||
|
||||
# Turn the above into a map for the resource for_each
|
||||
resource_provider_feature_map = {
|
||||
for i in local.resource_provider_feature_set : "${i.resource_provider_name}/${i.feature_name}" => {
|
||||
resource_provider_name = i.resource_provider_name
|
||||
feature_name = i.feature_name
|
||||
} }
|
||||
}
|
||||
|
|
|
@ -22,3 +22,20 @@ resource "azurerm_management_group_subscription_association" "this" {
|
|||
management_group_id = "/providers/Microsoft.Management/managementGroups/${var.subscription_management_group_id}"
|
||||
subscription_id = "/subscriptions/${local.subscription_id}"
|
||||
}
|
||||
|
||||
# Register resource providers
|
||||
resource "azapi_resource_action" "resource_provider_registration" {
|
||||
for_each = var.subscription_register_resource_providers_and_features
|
||||
type = "Microsoft.Resources/subscriptions@2021-04-01"
|
||||
resource_id = "/subscriptions/${local.subscription_id}"
|
||||
action = "providers/${each.key}/register"
|
||||
method = "POST"
|
||||
}
|
||||
|
||||
resource "azapi_resource_action" "resource_provider_feature_registration" {
|
||||
for_each = local.resource_provider_feature_map
|
||||
type = "${each.value.resource_provider_name}/features@2021-07-01"
|
||||
resource_id = "/subscriptions/${local.subscription_id}/providers/Microsoft.Features/providers/${each.value.resource_provider_name}/features/${each.value.feature_name}"
|
||||
action = "register"
|
||||
method = "POST"
|
||||
}
|
||||
|
|
|
@ -5,5 +5,9 @@ terraform {
|
|||
source = "hashicorp/azurerm"
|
||||
version = ">= 3.7.0"
|
||||
}
|
||||
azapi = {
|
||||
source = "Azure/azapi"
|
||||
version = ">= 1.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
variable "subscription_register_resource_providers_and_features" {
|
||||
type = map(set(string))
|
||||
description = <<DESCRIPTION
|
||||
The map of resource providers to register.
|
||||
The map keys are the resource provider namespace, e.g. `Microsoft.Compute`.
|
||||
The map values are a list of provider features to enable.
|
||||
Leave the value empty to not register any resource provider features.
|
||||
DESCRIPTION
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "subscription_alias_enabled" {
|
||||
type = bool
|
||||
description = <<DESCRIPTION
|
||||
|
|
|
@ -13,6 +13,9 @@ module "lz_vending" {
|
|||
subscription_alias_name = each.value.name
|
||||
subscription_workload = each.value.workload
|
||||
|
||||
# Turn off RP registration in this test
|
||||
subscription_register_resource_providers_and_features = {}
|
||||
|
||||
# management group association variables
|
||||
subscription_management_group_association_enabled = true
|
||||
subscription_management_group_id = each.value.management_group_id
|
||||
|
|
|
@ -3,24 +3,20 @@ package azureutils
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/managementgroups/armmanagementgroups"
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/subscription/armsubscription"
|
||||
"github.com/Azure/terratest-terraform-fluent/setuptest"
|
||||
"github.com/google/uuid"
|
||||
"github.com/matryer/try"
|
||||
"github.com/gruntwork-io/terratest/modules/retry"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
// CancelSubscription cancels the supplied Azure subscription.
|
||||
// it retries a few times as the subscription api is eventually consistent.
|
||||
func CancelSubscription(t *testing.T, id *uuid.UUID) error {
|
||||
const (
|
||||
max = 3
|
||||
delaysec = 20
|
||||
)
|
||||
|
||||
t.Logf("cancelling subscription %s", id.String())
|
||||
|
||||
sub, err := GetSubscription(*id)
|
||||
|
@ -61,15 +57,20 @@ func CancelSubscription(t *testing.T, id *uuid.UUID) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
ctx = context.TODO()
|
||||
err = try.Do(func(attempt int) (bool, error) {
|
||||
ctx, cancel := context.WithCancel(context.TODO())
|
||||
defer cancel()
|
||||
|
||||
_, err = retry.DoWithRetryE(t, "cancel subscription", setuptest.FastRetry.Max, setuptest.FastRetry.Wait, func() (string, error) {
|
||||
_, err := client.Cancel(ctx, id.String(), nil)
|
||||
if err != nil {
|
||||
t.Logf("subscription id %s cancel failed, attempt %d/%d: %v", id, attempt, max, err)
|
||||
time.Sleep(delaysec * time.Second)
|
||||
if strings.Contains(err.Error(), "Subscription is not in active state") {
|
||||
return "", nil
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
return attempt < max, err
|
||||
return "", nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot cancel subscription %s, %v", id, err)
|
||||
}
|
||||
|
@ -107,12 +108,6 @@ func GetSubscription(id uuid.UUID) (armsubscription.SubscriptionsClientGetRespon
|
|||
|
||||
// IsSubscriptionInManagementGroup returns true if the subscription is a management group.
|
||||
func IsSubscriptionInManagementGroup(t *testing.T, id uuid.UUID, mg string) error {
|
||||
// constants for retry loop in try.Do
|
||||
const (
|
||||
max = 8
|
||||
delaysec = 20
|
||||
)
|
||||
|
||||
if exists, err := SubscriptionExists(id); err != nil || !exists {
|
||||
return fmt.Errorf("subscription %s does not exist, or could not successfully check, %s", id, err)
|
||||
}
|
||||
|
@ -126,13 +121,12 @@ func IsSubscriptionInManagementGroup(t *testing.T, id uuid.UUID, mg string) erro
|
|||
cc := "no-cache"
|
||||
mgopts.CacheControl = &cc
|
||||
|
||||
err = try.Do(func(attempt int) (bool, error) {
|
||||
_, err = retry.DoWithRetryE(t, "is subscription in management group", setuptest.FastRetry.Max, setuptest.FastRetry.Wait, func() (string, error) {
|
||||
_, err := client.GetSubscription(context.Background(), mg, id.String(), &mgopts)
|
||||
if err != nil {
|
||||
t.Logf("failed to get subscription %s in management group %s, attempt %d/%d", id.String(), mg, attempt, max)
|
||||
time.Sleep(delaysec * time.Second)
|
||||
return "", err
|
||||
}
|
||||
return attempt < max, err
|
||||
return "", nil
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed determine if subscription %s in management group %s: %v", id.String(), mg, err)
|
||||
|
|
|
@ -12,7 +12,6 @@ require (
|
|||
github.com/Azure/terratest-terraform-fluent v0.6.2
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/gruntwork-io/terratest v0.43.3
|
||||
github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2
|
||||
github.com/stretchr/testify v1.8.4
|
||||
golang.org/x/sync v0.3.0
|
||||
)
|
||||
|
@ -30,7 +29,6 @@ require (
|
|||
github.com/aws/aws-sdk-go v1.44.267 // indirect
|
||||
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
|
||||
github.com/boombuler/barcode v1.0.1 // indirect
|
||||
github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927 // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/emicklei/go-restful/v3 v3.10.2 // indirect
|
||||
|
|
|
@ -227,8 +227,6 @@ github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx2
|
|||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
||||
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927 h1:SKI1/fuSdodxmNNyVBR8d7X/HuLnRpvvFO0AgyQk764=
|
||||
github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927/go.mod h1:h/aW8ynjgkuj+NQRlZcDbAbM1ORAbXjXX77sX7T289U=
|
||||
github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
|
||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||
|
@ -448,8 +446,6 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
|
|||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
|
||||
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||
github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2 h1:JAEbJn3j/FrhdWA9jW8B5ajsLIjeuEHLi8xE4fk997o=
|
||||
github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2/go.mod h1:0KeJpeMD6o+O4hW7qJOT7vyQPKrWmj26uf5wMc/IiIs=
|
||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||
|
|
|
@ -260,10 +260,11 @@ func getMockInputVariables() map[string]any {
|
|||
return map[string]any{
|
||||
"location": "northeurope",
|
||||
// subscription variables
|
||||
"subscription_billing_scope": "/providers/Microsoft.Billing/billingAccounts/0000000/enrollmentAccounts/000000",
|
||||
"subscription_display_name": "test-subscription-alias",
|
||||
"subscription_alias_name": "test-subscription-alias",
|
||||
"subscription_workload": "Production",
|
||||
"subscription_billing_scope": "/providers/Microsoft.Billing/billingAccounts/0000000/enrollmentAccounts/000000",
|
||||
"subscription_register_resource_providers_and_features": map[string][]any{},
|
||||
"subscription_display_name": "test-subscription-alias",
|
||||
"subscription_alias_name": "test-subscription-alias",
|
||||
"subscription_workload": "Production",
|
||||
"subscription_tags": map[string]any{
|
||||
"test-tag": "test-value",
|
||||
"test-tag-2": "test-value-2",
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"github.com/Azure/terraform-azurerm-lz-vending/tests/azureutils"
|
||||
"github.com/Azure/terraform-azurerm-lz-vending/tests/utils"
|
||||
"github.com/Azure/terratest-terraform-fluent/check"
|
||||
"github.com/Azure/terratest-terraform-fluent/setuptest"
|
||||
"github.com/google/uuid"
|
||||
"github.com/gruntwork-io/terratest/modules/terraform"
|
||||
|
@ -19,6 +20,7 @@ var billingScope = os.Getenv("AZURE_BILLING_SCOPE")
|
|||
|
||||
// TestDeploySubscriptionAliasValid tests the deployment of a subscription alias
|
||||
// with valid input variables.
|
||||
// We also test RP registration here.
|
||||
func TestDeploySubscriptionAliasValid(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
@ -30,6 +32,8 @@ func TestDeploySubscriptionAliasValid(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
defer test.Cleanup()
|
||||
|
||||
check.InPlan(test.PlanStruct).NumberOfResourcesEquals(1).ErrorIsNil(t)
|
||||
|
||||
// Defer the cleanup of the subscription alias to the end of the test.
|
||||
// Should be run after the Terraform destroy.
|
||||
// We don't know the sub ID yet, so use zeros for now and then
|
||||
|
@ -94,6 +98,30 @@ func TestDeploySubscriptionAliasManagementGroupValid(t *testing.T) {
|
|||
assert.NoErrorf(t, err, "subscription %s is not in management group %s", sid, v["subscription_management_group_id"].(string))
|
||||
}
|
||||
|
||||
func TestDeploySubscriptionDeployExistingWithRpFeatureRegistration(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
utils.PreCheckDeployTests(t)
|
||||
|
||||
v, err := getValidInputVariables(billingScope)
|
||||
v["subscription_alias_enabled"] = false
|
||||
v["subscription_id"] = os.Getenv("AZURE_SUBSCRIPTION_ID")
|
||||
v["subscription_register_resource_providers_and_features"] = map[string][]any{
|
||||
"Microsoft.PowerBI": {"DailyPrivateLinkServicesForPowerBI"},
|
||||
"Microsoft.Compute": {},
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
test, err := setuptest.Dirs(moduleDir, "").WithVars(v).InitPlanShowWithPrepFunc(t, utils.AzureRmAndRequiredProviders)
|
||||
require.NoError(t, err)
|
||||
defer test.Cleanup()
|
||||
|
||||
defer test.DestroyRetry(setuptest.DefaultRetry) //nolint:errcheck
|
||||
test.ApplyIdempotent().ErrorIsNil(t)
|
||||
|
||||
check.InPlan(test.PlanStruct).NumberOfResourcesEquals(3).ErrorIsNil(t)
|
||||
}
|
||||
|
||||
// getValidInputVariables returns a set of valid input variables that can be used and modified for testing scenarios.
|
||||
func getValidInputVariables(billingScope string) (map[string]any, error) {
|
||||
r, err := utils.RandomHex(4)
|
||||
|
|
|
@ -32,6 +32,27 @@ func TestSubscriptionAliasCreateValid(t *testing.T) {
|
|||
check.InPlan(test.PlanStruct).That("azurerm_subscription.this[0]").Key("tags").HasValue(v["subscription_tags"]).ErrorIsNil(t)
|
||||
}
|
||||
|
||||
func TestSubscriptionRPRegistration(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
v := getMockInputVariables()
|
||||
v["subscription_register_resource_providers_and_features"] = map[string][]any{
|
||||
"Microsoft.Storage": {"Feature1", "Feature2"},
|
||||
"Microsoft.KeyVault": {},
|
||||
}
|
||||
v["subscription_id"] = "00000000-0000-0000-0000-000000000000"
|
||||
v["subscription_alias_enabled"] = false
|
||||
test, err := setuptest.Dirs(moduleDir, "").WithVars(v).InitPlanShowWithPrepFunc(t, utils.AzureRmAndRequiredProviders)
|
||||
require.NoError(t, err)
|
||||
defer test.Cleanup()
|
||||
|
||||
check.InPlan(test.PlanStruct).NumberOfResourcesEquals(4).ErrorIsNil(t)
|
||||
check.InPlan(test.PlanStruct).That("azapi_resource_action.resource_provider_registration[\"Microsoft.Storage\"]").Exists().ErrorIsNil(t)
|
||||
check.InPlan(test.PlanStruct).That("azapi_resource_action.resource_provider_registration[\"Microsoft.KeyVault\"]").Exists().ErrorIsNil(t)
|
||||
check.InPlan(test.PlanStruct).That("azapi_resource_action.resource_provider_feature_registration[\"Microsoft.Storage/Feature2\"]").Exists().ErrorIsNil(t)
|
||||
check.InPlan(test.PlanStruct).That("azapi_resource_action.resource_provider_feature_registration[\"Microsoft.Storage/Feature1\"]").Exists().ErrorIsNil(t)
|
||||
}
|
||||
|
||||
// TestSubscriptionAliasCreateValidWithManagementGroup tests the
|
||||
// validation functions with valid data, including a destination management group,
|
||||
// then creates a plan and compares the input variables to the planned values.
|
||||
|
@ -131,8 +152,8 @@ func getMockInputVariables() map[string]any {
|
|||
return map[string]any{
|
||||
"subscription_alias_enabled": true,
|
||||
"subscription_alias_name": "test-subscription-alias",
|
||||
"subscription_display_name": "test-subscription-alias",
|
||||
"subscription_billing_scope": "/providers/Microsoft.Billing/billingAccounts/0000000/enrollmentAccounts/000000",
|
||||
"subscription_display_name": "test-subscription-alias",
|
||||
"subscription_workload": "Production",
|
||||
"subscription_tags": map[string]any{
|
||||
"test-tag": "test-value",
|
||||
|
|
|
@ -1,3 +1,82 @@
|
|||
variable "subscription_register_resource_providers_and_features" {
|
||||
type = map(set(string))
|
||||
description = <<DESCRIPTION
|
||||
The map of resource providers to register.
|
||||
The map keys are the resource provider namespace, e.g. `Microsoft.Compute`.
|
||||
The map values are a list of provider features to enable.
|
||||
Leave the value empty to not register any resource provider features.
|
||||
|
||||
The default values are taken from [Hashicorp's AzureRM provider](https://github.com/hashicorp/terraform-provider-azurerm/blob/main/internal/resourceproviders/required.go).
|
||||
DESCRIPTION
|
||||
default = {
|
||||
"Microsoft.ApiManagement" = [],
|
||||
"Microsoft.AppPlatform" = [],
|
||||
"Microsoft.Authorization" = [],
|
||||
"Microsoft.Automation" = [],
|
||||
"Microsoft.AVS" = [],
|
||||
"Microsoft.Blueprint" = [],
|
||||
"Microsoft.BotService" = [],
|
||||
"Microsoft.Cache" = [],
|
||||
"Microsoft.Cdn" = [],
|
||||
"Microsoft.CognitiveServices" = [],
|
||||
"Microsoft.Compute" = [],
|
||||
"Microsoft.ContainerInstance" = [],
|
||||
"Microsoft.ContainerRegistry" = [],
|
||||
"Microsoft.ContainerService" = [],
|
||||
"Microsoft.CostManagement" = [],
|
||||
"Microsoft.CustomProviders" = [],
|
||||
"Microsoft.Databricks" = [],
|
||||
"Microsoft.DataLakeAnalytics" = [],
|
||||
"Microsoft.DataLakeStore" = [],
|
||||
"Microsoft.DataMigration" = [],
|
||||
"Microsoft.DataProtection" = [],
|
||||
"Microsoft.DBforMariaDB" = [],
|
||||
"Microsoft.DBforMySQL" = [],
|
||||
"Microsoft.DBforPostgreSQL" = [],
|
||||
"Microsoft.DesktopVirtualization" = [],
|
||||
"Microsoft.Devices" = [],
|
||||
"Microsoft.DevTestLab" = [],
|
||||
"Microsoft.DocumentDB" = [],
|
||||
"Microsoft.EventGrid" = [],
|
||||
"Microsoft.EventHub" = [],
|
||||
"Microsoft.HDInsight" = [],
|
||||
"Microsoft.HealthcareApis" = [],
|
||||
"Microsoft.GuestConfiguration" = [],
|
||||
"Microsoft.KeyVault" = [],
|
||||
"Microsoft.Kusto" = [],
|
||||
"microsoft.insights" = [],
|
||||
"Microsoft.Logic" = [],
|
||||
"Microsoft.MachineLearningServices" = [],
|
||||
"Microsoft.Maintenance" = [],
|
||||
"Microsoft.ManagedIdentity" = [],
|
||||
"Microsoft.ManagedServices" = [],
|
||||
"Microsoft.Management" = [],
|
||||
"Microsoft.Maps" = [],
|
||||
"Microsoft.MarketplaceOrdering" = [],
|
||||
"Microsoft.Media" = [],
|
||||
"Microsoft.MixedReality" = [],
|
||||
"Microsoft.Network" = [],
|
||||
"Microsoft.NotificationHubs" = [],
|
||||
"Microsoft.OperationalInsights" = [],
|
||||
"Microsoft.OperationsManagement" = [],
|
||||
"Microsoft.PolicyInsights" = [],
|
||||
"Microsoft.PowerBIDedicated" = [],
|
||||
"Microsoft.Relay" = [],
|
||||
"Microsoft.RecoveryServices" = [],
|
||||
"Microsoft.Resources" = [],
|
||||
"Microsoft.Search" = [],
|
||||
"Microsoft.Security" = [],
|
||||
"Microsoft.SecurityInsights" = [],
|
||||
"Microsoft.ServiceBus" = [],
|
||||
"Microsoft.ServiceFabric" = [],
|
||||
"Microsoft.Sql" = [],
|
||||
"Microsoft.Storage" = [],
|
||||
"Microsoft.StreamAnalytics" = [],
|
||||
"Microsoft.TimeSeriesInsights" = [],
|
||||
"Microsoft.Web" = [],
|
||||
}
|
||||
}
|
||||
|
||||
variable "subscription_alias_enabled" {
|
||||
default = false
|
||||
type = bool
|
||||
|
|
Загрузка…
Ссылка в новой задаче