From 5c756f799925959d0f5abef08102730d7ca5e664 Mon Sep 17 00:00:00 2001 From: jackofallops Date: Wed, 3 Jun 2020 10:47:55 +0100 Subject: [PATCH] refactor for IDs --- .../blueprint_assignment_resource.go | 88 +++++---------- .../blueprint_definition_datasource.go | 29 ++--- .../blueprint_published_version_datasource.go | 45 +++----- .../blueprints/parse/blueprint_definition.go | 2 +- .../blueprint_assignment_resource_test.go | 101 +++++++++--------- .../blueprint_definition_data_source_test.go | 28 ++--- ...rint_published_version_data_source_test.go | 25 +++-- .../services/blueprints/validate/blueprint.go | 6 +- .../docs/d/blueprint_definition.html.markdown | 13 ++- .../blueprint_published_version.html.markdown | 18 ++-- .../docs/r/blueprint_assignment.html.markdown | 14 +-- 11 files changed, 145 insertions(+), 224 deletions(-) diff --git a/azurerm/internal/services/blueprints/blueprint_assignment_resource.go b/azurerm/internal/services/blueprints/blueprint_assignment_resource.go index e1ddcd185888..c1a7cf0004d6 100644 --- a/azurerm/internal/services/blueprints/blueprint_assignment_resource.go +++ b/azurerm/internal/services/blueprints/blueprint_assignment_resource.go @@ -3,7 +3,6 @@ package blueprints import ( "fmt" "log" - "strings" "time" "github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint" @@ -43,46 +42,38 @@ func resourceArmBlueprintAssignment() *schema.Resource { "name": { Type: schema.TypeString, Required: true, + ForceNew: true, ValidateFunc: validation.StringIsNotEmpty, }, - "scope_type": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice([]string{ - "subscriptions", - "managementGroup", - }, true), - }, - - "scope": { + "target_subscription_id": { Type: schema.TypeString, Required: true, - ValidateFunc: validation.StringIsNotEmpty, + ForceNew: true, + ValidateFunc: azure.ValidateResourceID, }, "location": location.Schema(), "identity": ManagedIdentitySchema(), - "blueprint_id": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validate.BlueprintID, - }, - - "version_name": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringIsNotEmpty, - }, - + //"blueprint_id": { + // Type: schema.TypeString, + // Optional: true, + // Computed: true, + // ValidateFunc: validate.BlueprintID, + //}, + // + //"version_name": { + // Type: schema.TypeString, + // Optional: true, + // Computed: true, + // ValidateFunc: validation.StringIsNotEmpty, + //}, + // "version_id": { Type: schema.TypeString, - Optional: true, - Computed: true, + Required: true, ValidateFunc: validate.BlueprintVersionID, }, @@ -153,31 +144,9 @@ func resourceArmBlueprintAssignmentCreateUpdate(d *schema.ResourceData, meta int ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - var name, targetScope, blueprintId string - - if versionIdRaw, ok := d.GetOk("version_id"); ok { - if _, ok := d.GetOk("blueprint_id"); ok { - return fmt.Errorf("cannot specify `blueprint_id` when `version_id` is specified") - } - - if _, ok := d.GetOk("version_name"); ok { - return fmt.Errorf("cannot specify `version_name` when `version_id` is specified") - } - blueprintId = versionIdRaw.(string) - } else { - if bpIDRaw, ok := d.GetOk("blueprint_id"); ok { - if versionName, ok := d.GetOk("version_name"); ok { - blueprintId = fmt.Sprintf("%s/versions/%s", bpIDRaw.(string), versionName.(string)) - } else { - return fmt.Errorf("`version_name` must be specified if `version_id` is not supplied") - } - } else { - return fmt.Errorf("`blueprint_id` must be specified if `version_id` is not supplied") - } - } - - targetScope = fmt.Sprintf("%s/%s", d.Get("scope_type"), d.Get("scope")) - name = d.Get("name").(string) + name := d.Get("name").(string) + blueprintId := d.Get("version_id").(string) + targetScope := d.Get("target_subscription_id").(string) assignment := blueprint.Assignment{ AssignmentProperties: &blueprint.AssignmentProperties{ @@ -237,7 +206,7 @@ func resourceArmBlueprintAssignmentCreateUpdate(d *schema.ResourceData, meta int } if _, err := stateConf.WaitForState(); err != nil { - return fmt.Errorf("Failed waiting for Blueprint Assignment %q (Scope %q): %+v", name, targetScope, err) + return fmt.Errorf("failed waiting for Blueprint Assignment %q (Scope %q): %+v", name, targetScope, err) } d.SetId(*resp.ID) @@ -274,13 +243,7 @@ func resourceArmBlueprintAssignmentRead(d *schema.ResourceData, meta interface{} } if resp.Scope != nil { - scopeParts := strings.Split(strings.Trim(*resp.Scope, "/"), "/") - if len(scopeParts) == 2 { - d.Set("scope_type", scopeParts[0]) - d.Set("scope", scopeParts[1]) - } else { - return fmt.Errorf("read on Assignment scope failed, got: %+v", *resp.Scope) - } + d.Set("target_subscription_id", resp.Scope) } if resp.Location != nil { @@ -294,9 +257,6 @@ func resourceArmBlueprintAssignmentRead(d *schema.ResourceData, meta interface{} if resp.AssignmentProperties != nil { if resp.AssignmentProperties.BlueprintID != nil { d.Set("version_id", resp.AssignmentProperties.BlueprintID) - bpID, versionName := splitPublishedVersionID(*resp.BlueprintID) - d.Set("blueprint_id", bpID) - d.Set("version_name", versionName) } if resp.Parameters != nil { diff --git a/azurerm/internal/services/blueprints/blueprint_definition_datasource.go b/azurerm/internal/services/blueprints/blueprint_definition_datasource.go index 6781ae8e4552..cb40b72f09a1 100644 --- a/azurerm/internal/services/blueprints/blueprint_definition_datasource.go +++ b/azurerm/internal/services/blueprints/blueprint_definition_datasource.go @@ -6,8 +6,10 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/blueprints/validate" + mgValidate "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/managementgroup/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -27,19 +29,13 @@ func dataSourceArmBlueprintDefinition() *schema.Resource { ValidateFunc: validate.BlueprintName, }, - "scope_type": { + "scope_id": { Type: schema.TypeString, Required: true, - ValidateFunc: validation.StringInSlice([]string{ - "subscriptions", - "managementGroup", - }, false), - }, - - "scope_name": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringIsNotEmpty, + ValidateFunc: validation.Any( + azure.ValidateResourceID, + mgValidate.ManagementGroupID, + ), }, // Computed @@ -85,15 +81,7 @@ func dataSourceArmBlueprintDefinitionRead(d *schema.ResourceData, meta interface defer cancel() name := d.Get("name").(string) - var scope string - scopeName := d.Get("scope_name").(string) - scopeType := d.Get("scope_type").(string) - switch scopeType { - case "subscriptions": - scope = fmt.Sprintf("subscriptions/%s", scopeName) - case "managementGroup": - scope = fmt.Sprintf("providers/Microsoft.Management/managementGroups/%s", scopeName) - } + scope := d.Get("scope_id").(string) resp, err := client.Get(ctx, scope, name) if err != nil { @@ -130,3 +118,4 @@ func dataSourceArmBlueprintDefinitionRead(d *schema.ResourceData, meta interface return nil } + diff --git a/azurerm/internal/services/blueprints/blueprint_published_version_datasource.go b/azurerm/internal/services/blueprints/blueprint_published_version_datasource.go index 4aa81ec64e9d..fdb856dd3238 100644 --- a/azurerm/internal/services/blueprints/blueprint_published_version_datasource.go +++ b/azurerm/internal/services/blueprints/blueprint_published_version_datasource.go @@ -2,6 +2,9 @@ package blueprints import ( "fmt" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + mgValidate "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/managementgroup/validate" "time" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -20,16 +23,13 @@ func dataSourceArmBlueprintPublishedVersion() *schema.Resource { }, Schema: map[string]*schema.Schema{ - "subscription_id": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validate.UUID, - }, - - "management_group": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validate.NoEmptyStrings, + "scope_id": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.Any( + azure.ValidateResourceID, + mgValidate.ManagementGroupID, + ), }, "blueprint_name": { @@ -84,28 +84,7 @@ func dataSourceArmBlueprintPublishedVersionRead(d *schema.ResourceData, meta int ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - subscriptionRaw := d.Get("subscription_id") - var subscription, managementGroup string - if subscriptionRaw != nil { - subscription = subscriptionRaw.(string) - } - managementGroupRaw := d.Get("management_group") - if managementGroupRaw != nil { - managementGroup = managementGroupRaw.(string) - } - - var scope string - - if subscription == "" && managementGroup == "" { - return fmt.Errorf("One of subscription or management group must be specified") - } - - if subscription != "" { - scope = fmt.Sprintf("subscriptions/%s", subscription) - } else { - scope = fmt.Sprintf("providers/Microsoft.Management/managementGroups/%s", managementGroup) - } - + scope := d.Get("scope_id").(string) blueprintName := d.Get("blueprint_name").(string) versionID := d.Get("version").(string) @@ -124,7 +103,7 @@ func dataSourceArmBlueprintPublishedVersionRead(d *schema.ResourceData, meta int d.SetId(*resp.ID) } - if resp.Type == nil { + if resp.Type != nil { d.Set("type", resp.Type) } diff --git a/azurerm/internal/services/blueprints/parse/blueprint_definition.go b/azurerm/internal/services/blueprints/parse/blueprint_definition.go index 684272a70adf..6f5133e23c07 100644 --- a/azurerm/internal/services/blueprints/parse/blueprint_definition.go +++ b/azurerm/internal/services/blueprints/parse/blueprint_definition.go @@ -45,7 +45,7 @@ func DefinitionID(input string) (*DefinitionId, error) { case "subscriptions": id, err := azure.ParseAzureResourceID(input) if err != nil { - return nil, fmt.Errorf("[ERROR] Unable to parse Image ID %q: %+v", input, err) + return nil, fmt.Errorf("[ERROR] Unable to parse Blueprint Definition ID %q: %+v", input, err) } definitionId.Scope = fmt.Sprintf("subscriptions/%s", id.SubscriptionID) diff --git a/azurerm/internal/services/blueprints/tests/blueprint_assignment_resource_test.go b/azurerm/internal/services/blueprints/tests/blueprint_assignment_resource_test.go index e66c3e7d606f..ceb670372a7a 100644 --- a/azurerm/internal/services/blueprints/tests/blueprint_assignment_resource_test.go +++ b/azurerm/internal/services/blueprints/tests/blueprint_assignment_resource_test.go @@ -22,7 +22,7 @@ func TestAccBlueprintAssignment_basic(t *testing.T) { CheckDestroy: testCheckAzureRMBlueprintAssignmentDestroy, Steps: []resource.TestStep{ { - Config: testAccBlueprintAssignment_basic(data, "testAcc_basicSubscription"), + Config: testAccBlueprintAssignment_basic(data, "testAcc_basicSubscription", "v0.1_testAcc"), Check: resource.ComposeTestCheckFunc( testCheckBlueprintAssignmentExists(data.ResourceName), ), @@ -42,7 +42,7 @@ func TestAccBlueprintAssignment_subscriptionComplete(t *testing.T) { CheckDestroy: testCheckAzureRMBlueprintAssignmentDestroy, Steps: []resource.TestStep{ { - Config: testAccBlueprintAssignment_subscriptionComplete(data, "testAcc_subscriptionComplete"), + Config: testAccBlueprintAssignment_subscriptionComplete(data, "testAcc_subscriptionComplete", "v0.1_testAcc"), Check: resource.ComposeTestCheckFunc( testCheckBlueprintAssignmentExists(data.ResourceName), ), @@ -62,7 +62,7 @@ func TestAccBlueprintAssignment_managementGroup(t *testing.T) { CheckDestroy: testCheckAzureRMBlueprintAssignmentDestroy, Steps: []resource.TestStep{ { - Config: testAccBlueprintAssignment_rootManagementGroup(data, "testAcc_basicRootManagementGroup"), + Config: testAccBlueprintAssignment_rootManagementGroup(data, "testAcc_basicRootManagementGroup", "v0.1_testAcc"), Check: resource.ComposeTestCheckFunc( testCheckBlueprintAssignmentExists(data.ResourceName), ), @@ -122,7 +122,7 @@ func testCheckAzureRMBlueprintAssignmentDestroy(s *terraform.State) error { return nil } -func testAccBlueprintAssignment_basic(data acceptance.TestData, bpName string) string { +func testAccBlueprintAssignment_basic(data acceptance.TestData, bpName string, version string) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -133,15 +133,14 @@ data "azurerm_client_config" "current" {} data "azurerm_subscription" "test" {} data "azurerm_blueprint_definition" "test" { - name = "%s" - scope_type = "subscriptions" - scope_name = data.azurerm_client_config.current.subscription_id + name = "%s" + scope_id = data.azurerm_subscription.test.id } data "azurerm_blueprint_published_version" "test" { - subscription_id = data.azurerm_client_config.current.subscription_id - blueprint_name = data.azurerm_blueprint_definition.test.name - version = "v0.1_testAcc" + scope_id = data.azurerm_blueprint_definition.test.scope_id + blueprint_name = data.azurerm_blueprint_definition.test.name + version = "%s" } resource "azurerm_resource_group" "test" { @@ -162,27 +161,27 @@ resource "azurerm_role_assignment" "test" { } resource "azurerm_blueprint_assignment" "test" { - name = "testAccBPAssignment" - scope_type = "subscriptions" - scope = data.azurerm_client_config.current.subscription_id - location = "%s" + name = "testAccBPAssignment" + target_subscription_id = data.azurerm_subscription.test.id + version_id = data.azurerm_blueprint_published_version.test.id + location = "%s" + identity { type = "UserAssigned" identity_ids = [azurerm_user_assigned_identity.test.id] } - version_id = data.azurerm_blueprint_published_version.test.id depends_on = [ azurerm_role_assignment.test ] } -`, bpName, data.RandomInteger, data.RandomInteger, data.Locations.Primary) +`, bpName, version, data.RandomInteger, data.RandomInteger, data.Locations.Primary) } // This test config creates a UM-MSI and assigns Owner to the target subscription. This is necessary due to the changes -// the referenced Blueprint Version needs to make to successfully apply. If the test panics or otherwise fails, -// Dangling resources can include the Role Assignment(s) at the Subscription, which will need to be removed -func testAccBlueprintAssignment_subscriptionComplete(data acceptance.TestData, bpName string) string { +// the referenced Blueprint Version needs to make to successfully apply. If the test does not exit cleanly, "dangling" +// resources can include the Role Assignment(s) at the Subscription, which will need to be removed +func testAccBlueprintAssignment_subscriptionComplete(data acceptance.TestData, bpName string, version string) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -194,14 +193,13 @@ data "azurerm_subscription" "test" {} data "azurerm_blueprint_definition" "test" { name = "%s" - scope_type = "subscriptions" - scope_name = data.azurerm_client_config.current.subscription_id + scope_id = data.azurerm_subscription.test.id } data "azurerm_blueprint_published_version" "test" { - subscription_id = data.azurerm_client_config.current.subscription_id - blueprint_name = data.azurerm_blueprint_definition.test.name - version = "v0.1_testAcc" + scope_id = data.azurerm_blueprint_definition.test.scope_id + blueprint_name = data.azurerm_blueprint_definition.test.name + version = "%s" } resource "azurerm_resource_group" "test" { @@ -219,24 +217,23 @@ resource "azurerm_user_assigned_identity" "test" { name = "bp-user-%d" } -resource "azurerm_role_assignment" "test" { +resource "azurerm_role_assignment" "operator" { scope = data.azurerm_subscription.test.id role_definition_name = "Blueprint Operator" principal_id = azurerm_user_assigned_identity.test.principal_id } -resource "azurerm_role_assignment" "test2" { +resource "azurerm_role_assignment" "owner" { scope = data.azurerm_subscription.test.id role_definition_name = "Owner" principal_id = azurerm_user_assigned_identity.test.principal_id } resource "azurerm_blueprint_assignment" "test" { - name = "testAccBPAssignment" - scope_type = "subscriptions" - scope = data.azurerm_client_config.current.subscription_id - version_id = data.azurerm_blueprint_published_version.test.id - location = "%s" + name = "testAccBPAssignment" + target_subscription_id = data.azurerm_subscription.test.id + version_id = data.azurerm_blueprint_published_version.test.id + location = "%s" lock_mode = "AllResourcesDoNotDelete" @@ -266,14 +263,14 @@ resource "azurerm_blueprint_assignment" "test" { VALUES depends_on = [ - azurerm_role_assignment.test, - azurerm_role_assignment.test2 + azurerm_role_assignment.operator, + azurerm_role_assignment.owner ] } -`, bpName, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +`, bpName, version, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccBlueprintAssignment_rootManagementGroup(data acceptance.TestData, bpName string) string { +func testAccBlueprintAssignment_rootManagementGroup(data acceptance.TestData, bpName string, version string) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -283,16 +280,19 @@ data "azurerm_client_config" "current" {} data "azurerm_subscription" "test" {} +data "azurerm_management_group" "root" { + group_id = data.azurerm_client_config.current.tenant_id +} + data "azurerm_blueprint_definition" "test" { - name = "%s" - scope_type = "managementGroup" - scope_name = data.azurerm_client_config.current.tenant_id + name = "%s" + scope_id = data.azurerm_management_group.root.id } data "azurerm_blueprint_published_version" "test" { - management_group = data.azurerm_client_config.current.tenant_id - blueprint_name = data.azurerm_blueprint_definition.test.name - version = "v0.1_testAcc" + scope_id = data.azurerm_blueprint_definition.test.scope_id + blueprint_name = data.azurerm_blueprint_definition.test.name + version = "%s" } resource "azurerm_resource_group" "test" { @@ -310,24 +310,23 @@ resource "azurerm_user_assigned_identity" "test" { name = "bp-user-%d" } -resource "azurerm_role_assignment" "test" { +resource "azurerm_role_assignment" "operator" { scope = data.azurerm_subscription.test.id role_definition_name = "Blueprint Operator" principal_id = azurerm_user_assigned_identity.test.principal_id } -resource "azurerm_role_assignment" "test2" { +resource "azurerm_role_assignment" "owner" { scope = data.azurerm_subscription.test.id role_definition_name = "Owner" principal_id = azurerm_user_assigned_identity.test.principal_id } resource "azurerm_blueprint_assignment" "test" { - name = "testAccBPAssignment" - scope_type = "subscriptions" - scope = data.azurerm_client_config.current.subscription_id - version_id = data.azurerm_blueprint_published_version.test.id - location = "%s" + name = "testAccBPAssignment" + target_subscription_id = data.azurerm_subscription.test.id + version_id = data.azurerm_blueprint_published_version.test.id + location = "%s" identity { type = "UserAssigned" @@ -335,9 +334,9 @@ resource "azurerm_blueprint_assignment" "test" { } depends_on = [ - azurerm_role_assignment.test, - azurerm_role_assignment.test2 + azurerm_role_assignment.operator, + azurerm_role_assignment.owner ] } -`, bpName, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary) +`, bpName, version, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary) } diff --git a/azurerm/internal/services/blueprints/tests/blueprint_definition_data_source_test.go b/azurerm/internal/services/blueprints/tests/blueprint_definition_data_source_test.go index 2dd267fb120e..42c65e537574 100644 --- a/azurerm/internal/services/blueprints/tests/blueprint_definition_data_source_test.go +++ b/azurerm/internal/services/blueprints/tests/blueprint_definition_data_source_test.go @@ -24,7 +24,6 @@ func TestAccDataSourceBlueprintDefinition_basic(t *testing.T) { resource.TestCheckResourceAttrSet(data.ResourceName, "last_modified"), resource.TestCheckResourceAttr(data.ResourceName, "target_scope", "subscription"), // Only subscriptions can be targets resource.TestCheckResourceAttrSet(data.ResourceName, "time_created"), - resource.TestCheckResourceAttr(data.ResourceName, "scope_type", "subscriptions"), ), }, }, @@ -46,7 +45,6 @@ func TestAccDataSourceBlueprintDefinition_basicAtRootManagementGroup(t *testing. resource.TestCheckResourceAttrSet(data.ResourceName, "time_created"), resource.TestCheckResourceAttrSet(data.ResourceName, "last_modified"), resource.TestCheckResourceAttr(data.ResourceName, "target_scope", "subscription"), // Only subscriptions can be targets - resource.TestCheckResourceAttr(data.ResourceName, "scope_type", "managementGroup"), ), }, }, @@ -67,7 +65,6 @@ func TestAccDataSourceBlueprintDefinition_basicAtChildManagementGroup(t *testing resource.TestCheckResourceAttrSet(data.ResourceName, "time_created"), resource.TestCheckResourceAttrSet(data.ResourceName, "last_modified"), resource.TestCheckResourceAttr(data.ResourceName, "target_scope", "subscription"), // Only subscriptions can be targets - resource.TestCheckResourceAttr(data.ResourceName, "scope_type", "managementGroup"), ), }, }, @@ -80,12 +77,11 @@ provider "azurerm" { features {} } -data "azurerm_client_config" "current" {} +data "azurerm_subscription" "current" {} data "azurerm_blueprint_definition" "test" { - name = "testAcc_basicSubscription" - scope_type = "subscriptions" - scope_name = data.azurerm_client_config.current.subscription_id + name = "testAcc_basicSubscription" + scope_id = data.azurerm_subscription.current.id } ` @@ -97,12 +93,13 @@ provider "azurerm" { features {} } -data "azurerm_client_config" "current" {} +data "azurerm_management_group" "test" { + name = "%s" +} data "azurerm_blueprint_definition" "test" { - name = "testAcc_staticStubManagementGroup" - scope_type = "managementGroup" - scope_name = "%s" + name = "testAcc_staticStubManagementGroup" + scope_id = data.azurerm_management_group.test.id } `, managementGroup) @@ -116,10 +113,13 @@ provider "azurerm" { data "azurerm_client_config" "current" {} +data "azurerm_management_group" "root" { + name = data.azurerm_client_config.current.tenant_id +} + data "azurerm_blueprint_definition" "test" { - name = "testAcc_basicRootManagementGroup" - scope_type = "managementGroup" - scope_name = data.azurerm_client_config.current.tenant_id + name = "testAcc_basicRootManagementGroup" + scope_id = data.azurerm_management_group.root.id } ` diff --git a/azurerm/internal/services/blueprints/tests/blueprint_published_version_data_source_test.go b/azurerm/internal/services/blueprints/tests/blueprint_published_version_data_source_test.go index 4d413ebfa781..2fc9f2612e39 100644 --- a/azurerm/internal/services/blueprints/tests/blueprint_published_version_data_source_test.go +++ b/azurerm/internal/services/blueprints/tests/blueprint_published_version_data_source_test.go @@ -75,13 +75,12 @@ provider "azurerm" { features {} } -data "azurerm_client_config" "current" { -} +data "azurerm_subscription" "current" {} data "azurerm_blueprint_published_version" "test" { - subscription_id = data.azurerm_client_config.current.subscription_id - blueprint_name = "%s" - version = "%s" + scope_id = data.azurerm_subscription.current.id + blueprint_name = "%s" + version = "%s" } `, bpName, version) } @@ -92,13 +91,16 @@ provider "azurerm" { features {} } -data "azurerm_client_config" "current" { +data "azurerm_client_config" "current" {} + +data "azurerm_management_group" "root" { + name = data.azurerm_client_config.current.tenant_id } data "azurerm_blueprint_published_version" "test" { - management_group = data.azurerm_client_config.current.tenant_id - blueprint_name = "%s" - version = "%s" + scope_id = data.azurerm_management_group.root.id + blueprint_name = "%s" + version = "%s" } `, bpName, version) } @@ -109,11 +111,12 @@ provider "azurerm" { features {} } -data "azurerm_client_config" "current" { +data "azurerm_management_group" "test" { + name = "%s" } data "azurerm_blueprint_published_version" "test" { - management_group = "%s" + management_group = data.azurerm_management_group.test.id blueprint_name = "%s" version = "%s" } diff --git a/azurerm/internal/services/blueprints/validate/blueprint.go b/azurerm/internal/services/blueprints/validate/blueprint.go index 16bb84203515..e25de337c686 100644 --- a/azurerm/internal/services/blueprints/validate/blueprint.go +++ b/azurerm/internal/services/blueprints/validate/blueprint.go @@ -2,9 +2,8 @@ package validate import ( "fmt" - "regexp" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/blueprints/parse" + "regexp" ) func BlueprintID(i interface{}, k string) (warnings []string, errors []error) { @@ -32,5 +31,6 @@ func BlueprintName(i interface{}, k string) (warnings []string, errors []error) if matched := regexp.MustCompile(`^[A-Za-z0-9-_]{1,48}$`).Match([]byte(v)); !matched { errors = append(errors, fmt.Errorf("%s can include letters, numbers, underscores or dashes. Spaces and other special characters are not allowed.", k)) } - return + + return warnings, errors } diff --git a/website/docs/d/blueprint_definition.html.markdown b/website/docs/d/blueprint_definition.html.markdown index 8c2ce02fd8f5..a36bed0a082b 100644 --- a/website/docs/d/blueprint_definition.html.markdown +++ b/website/docs/d/blueprint_definition.html.markdown @@ -13,8 +13,15 @@ Use this data source to access information about an existing Azure Blueprint Def ## Example Usage ```hcl -data "azurerm_blueprint_definition" "example" { +data "azurerm_client_config" "current" {} +data "azurerm_management_group" "root" { + name = data.azurerm_client_config.current.tenant_id +} + +data "azurerm_blueprint_definition" "example" { + name = "exampleManagementGroupBP" + scope_id = data.azurerm_management_group.root.id } ``` @@ -23,9 +30,7 @@ data "azurerm_blueprint_definition" "example" { * `name` - (Required) The name of the Blueprint -* `scope_type` - (Required) The scope at which the blueprint definition is stored. Possible values are `subscriptions` and `managementGroup`. - -* `scope_name` - (Required) The name of the scope. This is a subscription ID or Management Group name, depending on the `scope_type`. +* `scope_id` - (Required) The Resource ID of the scope at which the blueprint definition is stored. This will be with either a Subscription ID or Management Group ID. ## Attribute Reference diff --git a/website/docs/d/blueprint_published_version.html.markdown b/website/docs/d/blueprint_published_version.html.markdown index 743dee37e07b..dcb0340e8dc6 100644 --- a/website/docs/d/blueprint_published_version.html.markdown +++ b/website/docs/d/blueprint_published_version.html.markdown @@ -12,25 +12,19 @@ Use this data source to access information about an existing Azure Blueprint Pub ## Example Usage ```hcl -data "azurerm_blueprint_published_version" "subscription_example" { - subscription_id = "00000000-0000-0000-0000-0000000000000" - blueprint_name = "exampleBluePrint" - version = "v1.0" -} +data "azurerm_subscription" "current" {} -data "azurerm_blueprint_published_version" "management_group_example" { - management_group = "devManagementGroup" - blueprint_name = "exampleMGBluePrint" - version = "dev_v2.3" +data "azurerm_blueprint_published_version" "test" { + scope_id = data.azurerm_subscription.current.id + blueprint_name = "exampleMGBluePrint" + version = "dev_v2.3" } ``` ## Argument Reference -* `subscription_id` - (Optional) The ID of the Subscription where the Blueprint is stored. One of `subscription_id` or `management_group` is required. - -* `management_group` - (Optional) The ID of the Management Group where the Blueprint is stored. One of `management_group` or `subscription_id` is required. +* `scope_id` - (Required) The Resource ID of the scope where the Blueprint Definition is stored. This will be with either a Subscription ID or Management Group ID. * `blueprint_name` - (Required) The name of the Blueprint Definition diff --git a/website/docs/r/blueprint_assignment.html.markdown b/website/docs/r/blueprint_assignment.html.markdown index e77ad439523f..20253ddec8a0 100644 --- a/website/docs/r/blueprint_assignment.html.markdown +++ b/website/docs/r/blueprint_assignment.html.markdown @@ -16,21 +16,13 @@ Manages a Blueprint Assignment resource * `name` - (Required) The name of the Blueprint Assignment -* `scope_type` - (Required) The target scope type of the Blueprint Assignment. One of `subscription` or `managementGroup` (case sensitive) +* `target_subscription_id` - (Required) The Subscription ID the Blueprint Published Version is to be applied to. -* `scope` - (Required) The ID of the subscription or name of the Management group of the target scope type. - -* `location` - (Required) The Azure location of the Assignment +* `location` - (Required) The Azure location of the Assignment. * `identitiy` - (Required) an identity block, as detailed below. -* `blueprint_id` - (Optional) The ID of the Blueprint Definition to be assigned. - -* `version_name` - (Optional) The version name of the Published Blueprint to be assigned. - -* `version_id` - (Optional) The ID of the Published Version of the blueprint to be assigned. - -~> **NOTE:** Either `version_id`, or the `blueprint_id` and `version_name` need to be specified. +* `version_id` - (Required) The ID of the Published Version of the blueprint to be assigned. * `parameter_values` - (Optional) a JSON string to supply Blueprint Assignment parameter values.