From 20b368085b3444335f3be4d507abb628e50d93f7 Mon Sep 17 00:00:00 2001 From: xiaxyi Date: Thu, 7 Apr 2022 16:26:06 +0800 Subject: [PATCH 1/6] add version data --- .../blueprint_definition_data_source.go | 20 +++++++++++++++++-- .../blueprint_definition_data_source_test.go | 19 ++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/internal/services/blueprints/blueprint_definition_data_source.go b/internal/services/blueprints/blueprint_definition_data_source.go index e8285ed16c8b..f408ba282e7f 100644 --- a/internal/services/blueprints/blueprint_definition_data_source.go +++ b/internal/services/blueprints/blueprint_definition_data_source.go @@ -77,6 +77,7 @@ func dataSourceBlueprintDefinition() *pluginsdk.Resource { func dataSourceBlueprintDefinitionRead(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Blueprints.BlueprintsClient + publishedClient := meta.(*clients.Client).Blueprints.PublishedBlueprintsClient ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() @@ -112,9 +113,24 @@ func dataSourceBlueprintDefinitionRead(d *pluginsdk.ResourceData, meta interface d.Set("target_scope", resp.TargetScope) - if resp.Versions != nil { - d.Set("versions", resp.Versions) + versionList := make([]string, 0) + versions, err := publishedClient.List(ctx, scope, name) + if err != nil { + return fmt.Errorf("listing blue print versions for %s error: %+v", *resp.ID, err) + } + + if versions.Values() == nil { + return fmt.Errorf("no version is published for this blue print definition") } + for _, version := range versions.Values() { + if version.PublishedBlueprintProperties == nil || version.Name == nil { + continue + } + versionList = append(versionList, *version.Name) + } + + d.Set("versions", versionList) + return nil } diff --git a/internal/services/blueprints/blueprint_definition_data_source_test.go b/internal/services/blueprints/blueprint_definition_data_source_test.go index 30e640a4cb78..f54fbf90a511 100644 --- a/internal/services/blueprints/blueprint_definition_data_source_test.go +++ b/internal/services/blueprints/blueprint_definition_data_source_test.go @@ -29,6 +29,25 @@ func TestAccBlueprintDefinitionDataSource_basic(t *testing.T) { }) } +func TestAccBlueprintDefinitionDataSource_basicWithVersion(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_blueprint_definition", "test") + r := BlueprintDefinitionDataSource{} + + data.DataSourceTest(t, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).Key("description").HasValue("Acceptance Test stub for Blueprints at Subscription"), + check.That(data.ResourceName).Key("name").HasValue("testAcc_basicSubscription"), + check.That(data.ResourceName).Key("last_modified").Exists(), + check.That(data.ResourceName).Key("target_scope").HasValue("subscription"), + check.That(data.ResourceName).Key("time_created").Exists(), + check.That(data.ResourceName).Key("versions").Exists(), + ), + }, + }) +} + //lintignore:AT001 func TestAccBlueprintDefinitionDataSource_basicAtRootManagementGroup(t *testing.T) { data := acceptance.BuildTestData(t, "data.azurerm_blueprint_definition", "test") From d645f64c11b9bebf9eaf07af4bdb0be74295b271 Mon Sep 17 00:00:00 2001 From: xiaxyi Date: Fri, 8 Apr 2022 17:38:36 +0800 Subject: [PATCH 2/6] update --- .../blueprint_definition_data_source_test.go | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/internal/services/blueprints/blueprint_definition_data_source_test.go b/internal/services/blueprints/blueprint_definition_data_source_test.go index f54fbf90a511..30e640a4cb78 100644 --- a/internal/services/blueprints/blueprint_definition_data_source_test.go +++ b/internal/services/blueprints/blueprint_definition_data_source_test.go @@ -29,25 +29,6 @@ func TestAccBlueprintDefinitionDataSource_basic(t *testing.T) { }) } -func TestAccBlueprintDefinitionDataSource_basicWithVersion(t *testing.T) { - data := acceptance.BuildTestData(t, "data.azurerm_blueprint_definition", "test") - r := BlueprintDefinitionDataSource{} - - data.DataSourceTest(t, []acceptance.TestStep{ - { - Config: r.basic(data), - Check: acceptance.ComposeTestCheckFunc( - check.That(data.ResourceName).Key("description").HasValue("Acceptance Test stub for Blueprints at Subscription"), - check.That(data.ResourceName).Key("name").HasValue("testAcc_basicSubscription"), - check.That(data.ResourceName).Key("last_modified").Exists(), - check.That(data.ResourceName).Key("target_scope").HasValue("subscription"), - check.That(data.ResourceName).Key("time_created").Exists(), - check.That(data.ResourceName).Key("versions").Exists(), - ), - }, - }) -} - //lintignore:AT001 func TestAccBlueprintDefinitionDataSource_basicAtRootManagementGroup(t *testing.T) { data := acceptance.BuildTestData(t, "data.azurerm_blueprint_definition", "test") From 0e82b2170e9c3ef3c991c511eabc9e9235d59587 Mon Sep 17 00:00:00 2001 From: xiaxin18 Date: Fri, 22 Jul 2022 16:08:22 +0800 Subject: [PATCH 3/6] updating test case --- .../blueprint_definition_data_source.go | 4 --- .../blueprint_definition_data_source_test.go | 32 +++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/internal/services/blueprints/blueprint_definition_data_source.go b/internal/services/blueprints/blueprint_definition_data_source.go index f408ba282e7f..d76986f3bbbc 100644 --- a/internal/services/blueprints/blueprint_definition_data_source.go +++ b/internal/services/blueprints/blueprint_definition_data_source.go @@ -119,10 +119,6 @@ func dataSourceBlueprintDefinitionRead(d *pluginsdk.ResourceData, meta interface return fmt.Errorf("listing blue print versions for %s error: %+v", *resp.ID, err) } - if versions.Values() == nil { - return fmt.Errorf("no version is published for this blue print definition") - } - for _, version := range versions.Values() { if version.PublishedBlueprintProperties == nil || version.Name == nil { continue diff --git a/internal/services/blueprints/blueprint_definition_data_source_test.go b/internal/services/blueprints/blueprint_definition_data_source_test.go index 30e640a4cb78..e60d5ac551b5 100644 --- a/internal/services/blueprints/blueprint_definition_data_source_test.go +++ b/internal/services/blueprints/blueprint_definition_data_source_test.go @@ -29,6 +29,21 @@ func TestAccBlueprintDefinitionDataSource_basic(t *testing.T) { }) } +func TestAccBlueprintDefinitionDataSource_blueprintVersions(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_blueprint_definition", "test") + r := BlueprintDefinitionDataSource{} + + data.DataSourceTest(t, []acceptance.TestStep{ + { + Config: r.versions(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).Key("name").HasValue("testAcc_basicSubscription"), + check.That(data.ResourceName).Key("versions.#").HasValue("0"), + ), + }, + }) +} + //lintignore:AT001 func TestAccBlueprintDefinitionDataSource_basicAtRootManagementGroup(t *testing.T) { data := acceptance.BuildTestData(t, "data.azurerm_blueprint_definition", "test") @@ -81,6 +96,23 @@ data "azurerm_blueprint_definition" "test" { `, subscription) } +func (BlueprintDefinitionDataSource) versions(data acceptance.TestData) string { + subscription := data.Client().SubscriptionID + return fmt.Sprintf(` +provider "azurerm" { +subscription_id = "%s" + features {} +} + +data "azurerm_subscription" "current" {} + +data "azurerm_blueprint_definition" "test" { + name = "testAcc_basicSubscriptions" + scope_id = data.azurerm_subscription.current.id +} +`, subscription) +} + func (BlueprintDefinitionDataSource) basicAtManagementGroup(managementGroup string) string { return fmt.Sprintf(` provider "azurerm" { From bfec85dfb48db44260de0f1d64b97c03266fa824 Mon Sep 17 00:00:00 2001 From: xiaxin18 Date: Fri, 22 Jul 2022 16:23:16 +0800 Subject: [PATCH 4/6] updating test case --- .../blueprints/blueprint_definition_data_source_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/services/blueprints/blueprint_definition_data_source_test.go b/internal/services/blueprints/blueprint_definition_data_source_test.go index e60d5ac551b5..45f39e3bd3a8 100644 --- a/internal/services/blueprints/blueprint_definition_data_source_test.go +++ b/internal/services/blueprints/blueprint_definition_data_source_test.go @@ -100,14 +100,14 @@ func (BlueprintDefinitionDataSource) versions(data acceptance.TestData) string { subscription := data.Client().SubscriptionID return fmt.Sprintf(` provider "azurerm" { -subscription_id = "%s" + subscription_id = "%s" features {} } data "azurerm_subscription" "current" {} data "azurerm_blueprint_definition" "test" { - name = "testAcc_basicSubscriptions" + name = "testAcc_basicSubscription" scope_id = data.azurerm_subscription.current.id } `, subscription) From 6fb00f94d085aedfcd1637b51f0bbc4e54ba2538 Mon Sep 17 00:00:00 2001 From: xiaxin18 Date: Fri, 22 Jul 2022 16:36:59 +0800 Subject: [PATCH 5/6] update test cases --- .../blueprint_definition_data_source_test.go | 33 +------------------ 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/internal/services/blueprints/blueprint_definition_data_source_test.go b/internal/services/blueprints/blueprint_definition_data_source_test.go index 45f39e3bd3a8..84f068502342 100644 --- a/internal/services/blueprints/blueprint_definition_data_source_test.go +++ b/internal/services/blueprints/blueprint_definition_data_source_test.go @@ -21,6 +21,7 @@ func TestAccBlueprintDefinitionDataSource_basic(t *testing.T) { Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("description").HasValue("Acceptance Test stub for Blueprints at Subscription"), check.That(data.ResourceName).Key("name").HasValue("testAcc_basicSubscription"), + check.That(data.ResourceName).Key("versions.#").HasValue("0"), check.That(data.ResourceName).Key("last_modified").Exists(), check.That(data.ResourceName).Key("target_scope").HasValue("subscription"), check.That(data.ResourceName).Key("time_created").Exists(), @@ -29,21 +30,6 @@ func TestAccBlueprintDefinitionDataSource_basic(t *testing.T) { }) } -func TestAccBlueprintDefinitionDataSource_blueprintVersions(t *testing.T) { - data := acceptance.BuildTestData(t, "data.azurerm_blueprint_definition", "test") - r := BlueprintDefinitionDataSource{} - - data.DataSourceTest(t, []acceptance.TestStep{ - { - Config: r.versions(data), - Check: acceptance.ComposeTestCheckFunc( - check.That(data.ResourceName).Key("name").HasValue("testAcc_basicSubscription"), - check.That(data.ResourceName).Key("versions.#").HasValue("0"), - ), - }, - }) -} - //lintignore:AT001 func TestAccBlueprintDefinitionDataSource_basicAtRootManagementGroup(t *testing.T) { data := acceptance.BuildTestData(t, "data.azurerm_blueprint_definition", "test") @@ -96,23 +82,6 @@ data "azurerm_blueprint_definition" "test" { `, subscription) } -func (BlueprintDefinitionDataSource) versions(data acceptance.TestData) string { - subscription := data.Client().SubscriptionID - return fmt.Sprintf(` -provider "azurerm" { - subscription_id = "%s" - features {} -} - -data "azurerm_subscription" "current" {} - -data "azurerm_blueprint_definition" "test" { - name = "testAcc_basicSubscription" - scope_id = data.azurerm_subscription.current.id -} -`, subscription) -} - func (BlueprintDefinitionDataSource) basicAtManagementGroup(managementGroup string) string { return fmt.Sprintf(` provider "azurerm" { From e4041599f04a392681f95c52fdd9c85408516e77 Mon Sep 17 00:00:00 2001 From: xiaxin18 Date: Fri, 22 Jul 2022 16:49:58 +0800 Subject: [PATCH 6/6] update --- .../blueprints/blueprint_definition_data_source_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/blueprints/blueprint_definition_data_source_test.go b/internal/services/blueprints/blueprint_definition_data_source_test.go index 84f068502342..4f7f836a8a06 100644 --- a/internal/services/blueprints/blueprint_definition_data_source_test.go +++ b/internal/services/blueprints/blueprint_definition_data_source_test.go @@ -21,7 +21,7 @@ func TestAccBlueprintDefinitionDataSource_basic(t *testing.T) { Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).Key("description").HasValue("Acceptance Test stub for Blueprints at Subscription"), check.That(data.ResourceName).Key("name").HasValue("testAcc_basicSubscription"), - check.That(data.ResourceName).Key("versions.#").HasValue("0"), + check.That(data.ResourceName).Key("versions.#").HasValue("2"), check.That(data.ResourceName).Key("last_modified").Exists(), check.That(data.ResourceName).Key("target_scope").HasValue("subscription"), check.That(data.ResourceName).Key("time_created").Exists(),