From 3cc65df6c291e1797511718258ecad059d5c390c Mon Sep 17 00:00:00 2001 From: jackofallops Date: Tue, 21 Apr 2020 09:01:56 +0100 Subject: [PATCH 01/26] new DS, modules and some tests --- azurerm/internal/clients/client.go | 3 + azurerm/internal/provider/services.go | 2 + .../blueprint_assignment_resource.go | 33 + .../blueprint_definition_datasource.go | 7 + .../blueprint_published_version_datasource.go | 146 + .../services/blueprints/client/client.go | 24 + .../blueprints/parse/blueprint_assignment.go | 63 + .../parse/blueprint_assignment_test.go | 91 + .../blueprints/parse/blueprint_version.go | 63 + .../parse/blueprint_version_test.go | 68 + .../services/blueprints/registration.go | 32 + ...print_published_version_datasource_test.go | 46 + .../2018-11-01-preview/blueprint/artifacts.go | 397 +++ .../blueprint/assignmentoperations.go | 237 ++ .../blueprint/assignments.go | 477 ++++ .../blueprint/blueprints.go | 396 +++ .../2018-11-01-preview/blueprint/client.go | 50 + .../2018-11-01-preview/blueprint/models.go | 2401 +++++++++++++++++ .../blueprint/publishedartifacts.go | 241 ++ .../blueprint/publishedblueprints.go | 414 +++ .../2018-11-01-preview/blueprint/version.go | 30 + vendor/modules.txt | 1 + website/allowed-subcategories | 1 + 23 files changed, 5223 insertions(+) create mode 100644 azurerm/internal/services/blueprints/blueprint_assignment_resource.go create mode 100644 azurerm/internal/services/blueprints/blueprint_definition_datasource.go create mode 100644 azurerm/internal/services/blueprints/blueprint_published_version_datasource.go create mode 100644 azurerm/internal/services/blueprints/client/client.go create mode 100644 azurerm/internal/services/blueprints/parse/blueprint_assignment.go create mode 100644 azurerm/internal/services/blueprints/parse/blueprint_assignment_test.go create mode 100644 azurerm/internal/services/blueprints/parse/blueprint_version.go create mode 100644 azurerm/internal/services/blueprints/parse/blueprint_version_test.go create mode 100644 azurerm/internal/services/blueprints/registration.go create mode 100644 azurerm/internal/services/blueprints/tests/blueprint_published_version_datasource_test.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/artifacts.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/assignmentoperations.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/assignments.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/blueprints.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/client.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/models.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/publishedartifacts.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/publishedblueprints.go create mode 100644 vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/version.go diff --git a/azurerm/internal/clients/client.go b/azurerm/internal/clients/client.go index 305e8b78c514..d2e8ccd52f87 100644 --- a/azurerm/internal/clients/client.go +++ b/azurerm/internal/clients/client.go @@ -15,6 +15,7 @@ import ( authorization "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/authorization/client" automation "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/automation/client" batch "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/batch/client" + blueprints "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/blueprints/client" bot "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/bot/client" cdn "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/cdn/client" cognitiveServices "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/cognitive/client" @@ -97,6 +98,7 @@ type Client struct { Authorization *authorization.Client Automation *automation.Client Batch *batch.Client + Blueprints *blueprints.Client Bot *bot.Client Cdn *cdn.Client Cognitive *cognitiveServices.Client @@ -180,6 +182,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error client.Authorization = authorization.NewClient(o) client.Automation = automation.NewClient(o) client.Batch = batch.NewClient(o) + client.Blueprints = blueprints.NewClient(o) client.Bot = bot.NewClient(o) client.Cdn = cdn.NewClient(o) client.Cognitive = cognitiveServices.NewClient(o) diff --git a/azurerm/internal/provider/services.go b/azurerm/internal/provider/services.go index b95deb04e9ef..cf83395153c9 100644 --- a/azurerm/internal/provider/services.go +++ b/azurerm/internal/provider/services.go @@ -10,6 +10,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/authorization" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/automation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/batch" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/blueprints" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/bot" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/cdn" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/cognitive" @@ -90,6 +91,7 @@ func SupportedServices() []common.ServiceRegistration { authorization.Registration{}, automation.Registration{}, batch.Registration{}, + blueprints.Registration{}, bot.Registration{}, cdn.Registration{}, cognitive.Registration{}, diff --git a/azurerm/internal/services/blueprints/blueprint_assignment_resource.go b/azurerm/internal/services/blueprints/blueprint_assignment_resource.go new file mode 100644 index 000000000000..4caeecf07d04 --- /dev/null +++ b/azurerm/internal/services/blueprints/blueprint_assignment_resource.go @@ -0,0 +1,33 @@ +package blueprints + +import "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + +func resourceArmBlueprintAssignment() *schema.Resource { + return &schema.Resource{ + Create: resourceArmBlueprintAssignmentCreateUpdate, + Update: nil, + Read: resourceArmBlueprintAssignmentRead, + Delete: resourceArmBlueprintAssignmentDelete, + + Importer: nil, + + Timeouts: nil, + + Schema: nil, + } +} + +func resourceArmBlueprintAssignmentCreateUpdate(d *schema.ResourceData, meta interface{}) error { + + return resourceArmBlueprintAssignmentRead(d, meta) +} + +func resourceArmBlueprintAssignmentRead(d *schema.ResourceData, meta interface{}) error { + + return nil +} + +func resourceArmBlueprintAssignmentDelete(d *schema.ResourceData, meta interface{}) error { + + return nil +} diff --git a/azurerm/internal/services/blueprints/blueprint_definition_datasource.go b/azurerm/internal/services/blueprints/blueprint_definition_datasource.go new file mode 100644 index 000000000000..2c5e9f077ad8 --- /dev/null +++ b/azurerm/internal/services/blueprints/blueprint_definition_datasource.go @@ -0,0 +1,7 @@ +package blueprints + +import "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + +func dataSourceArmBlueprintDefinition() *schema.Resource { + return &schema.Resource{} +} diff --git a/azurerm/internal/services/blueprints/blueprint_published_version_datasource.go b/azurerm/internal/services/blueprints/blueprint_published_version_datasource.go new file mode 100644 index 000000000000..8e677e4588ed --- /dev/null +++ b/azurerm/internal/services/blueprints/blueprint_published_version_datasource.go @@ -0,0 +1,146 @@ +package blueprints + +import ( + "fmt" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/terraform-providers/terraform-provider-azuread/azuread/helpers/validate" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" + "time" +) + +func dataSourceArmBlueprintPublishedVersion() *schema.Resource { + return &schema.Resource{ + Read: dataSourceArmBlueprintPublishedVersionRead, + + Timeouts: &schema.ResourceTimeout{ + Read: schema.DefaultTimeout(5 * time.Minute), + }, + + 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, + }, + + "blueprint_name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "version": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + // Computed + + "type": { + Type: schema.TypeString, + Computed: true, + }, + + "time_created": { + Type: schema.TypeString, + Computed: true, + }, + + "last_modified": { + Type: schema.TypeString, + Computed: true, + }, + + "target_scope": { + Type: schema.TypeString, + Computed: true, + }, + + "display_name": { + Type: schema.TypeString, + Computed: true, + }, + + "description": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func dataSourceArmBlueprintPublishedVersionRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Blueprints.PublishedBlueprintsClient + 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("managementGroup") + 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) + } + + blueprintName := d.Get("blueprint_name").(string) + versionID := d.Get("version").(string) + + resp, err := client.Get(ctx, scope, blueprintName, versionID) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Published Blueprint Version %q not found: %+v", versionID, err) + } + + return fmt.Errorf("Read failed for Published Blueprint (%q) Version (%q): %+v", blueprintName, versionID, err) + } + + d.SetId(*resp.ID) + if resp.Type != nil { + d.Set("type", resp.Type) + } + + if resp.Status != nil { + if resp.Status.TimeCreated != nil { + d.Set("time_created", resp.Status.TimeCreated.String()) + } + + if resp.Status.LastModified != nil { + d.Set("last_modified", resp.Status.LastModified.String()) + } + } + + d.Set("target_scope", resp.TargetScope) + + if resp.DisplayName != nil { + d.Set("display_name", resp.DisplayName) + } + + if resp.Description != nil { + d.Set("description", resp.Description) + } + + return nil +} diff --git a/azurerm/internal/services/blueprints/client/client.go b/azurerm/internal/services/blueprints/client/client.go new file mode 100644 index 000000000000..463bfe31bae1 --- /dev/null +++ b/azurerm/internal/services/blueprints/client/client.go @@ -0,0 +1,24 @@ +package client + +import ( + "github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common" +) + +type Client struct { + AssignmentsClient *blueprint.AssignmentsClient + PublishedBlueprintsClient *blueprint.PublishedBlueprintsClient +} + +func NewClient(o *common.ClientOptions) *Client { + assignmentsClient := blueprint.NewAssignmentsClientWithBaseURI(o.ResourceManagerEndpoint) + o.ConfigureClient(&assignmentsClient.Client, o.ResourceManagerAuthorizer) + + publishedBlueprintsClient := blueprint.NewPublishedBlueprintsClientWithBaseURI(o.ResourceManagerEndpoint) + o.ConfigureClient(&publishedBlueprintsClient.Client, o.ResourceManagerAuthorizer) + + return &Client{ + AssignmentsClient: &assignmentsClient, + PublishedBlueprintsClient: &publishedBlueprintsClient, + } +} diff --git a/azurerm/internal/services/blueprints/parse/blueprint_assignment.go b/azurerm/internal/services/blueprints/parse/blueprint_assignment.go new file mode 100644 index 000000000000..593810563ebb --- /dev/null +++ b/azurerm/internal/services/blueprints/parse/blueprint_assignment.go @@ -0,0 +1,63 @@ +package parse + +import ( + "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "strings" +) + +type BlueprintAssignmentId struct { + // "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Blueprint/blueprintAssignments/assignSimpleBlueprint", + // "/managementGroups/ContosoOnlineGroup/providers/Microsoft.Blueprint/blueprintAssignments/assignSimpleBlueprint", + + Scope string + Subscription string + ManagementGroup string + Name string +} + +func BlueprintAssignmentID(input string) (*BlueprintAssignmentId, error) { + if len(input) == 0 { + return nil, fmt.Errorf("Bad: Assignment ID is empty string") + } + + assignmentID := BlueprintAssignmentId{} + + idParts := strings.Split(strings.Trim(input, "/"), "/") + if len(idParts) != 6 { + return nil, fmt.Errorf("Bad: Blueprint Assignment ID invalid: %q", input) + } + + // check casing on segments + if idParts[2] != "providers" || idParts[3] != "Microsoft.Blueprint" { + return nil, fmt.Errorf("ID has invalid provider segment (should be `providers/Microsoft.Blueprint` case sensitive): %q", input) + } + + if idParts[4] != "blueprintAssignments" { + return nil, fmt.Errorf("ID missing `blueprintAssignments` segment (case sensitive): %q", input) + } + + switch idParts[0] { + case "managementGroups": + assignmentID = BlueprintAssignmentId{ + Scope: fmt.Sprintf("%s/%s", idParts[0], idParts[1]), + ManagementGroup: idParts[1], + } + + case "subscriptions": + id, err := azure.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("[ERROR] Unable to parse Image ID %q: %+v", input, err) + } + + assignmentID.Scope = fmt.Sprintf("subscriptions/%s", id.SubscriptionID) + assignmentID.Subscription = id.SubscriptionID + + default: + return nil, fmt.Errorf("Bad: Invalid ID, should start with one of `/managementGroups` or `/subscriptions`: %q", input) + } + + assignmentID.Name = idParts[5] + + return &assignmentID, nil +} diff --git a/azurerm/internal/services/blueprints/parse/blueprint_assignment_test.go b/azurerm/internal/services/blueprints/parse/blueprint_assignment_test.go new file mode 100644 index 000000000000..c6d83a3560a4 --- /dev/null +++ b/azurerm/internal/services/blueprints/parse/blueprint_assignment_test.go @@ -0,0 +1,91 @@ +package parse + +import ( + "testing" +) + +func TestBlueprintAssignmentID(t *testing.T) { + testData := []struct { + Name string + Input string + Error bool + Expected *BlueprintAssignmentId + }{ + { + Name: "Empty", + Input: "", + Error: true, + }, + { + Name: "No Resource Groups Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", + Error: true, + }, + { + Name: "Invalid scope", + Input: "/providers/Microsoft.Management/managementGroups/testAccManagementGroup", + Error: true, + }, + // We have two valid possibilities to check for + { + Name: "Valid subscription scoped", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Blueprint/blueprintAssignments/assignSimpleBlueprint", + Error: false, + Expected: &BlueprintAssignmentId{ + Scope: "subscriptions/00000000-0000-0000-0000-000000000000", + Subscription: "00000000-0000-0000-0000-000000000000", + Name: "assignSimpleBlueprint", + }, + }, + { + Name: "Valid managementGroup scoped", + Input: "/managementGroups/testAccManagementGroup/providers/Microsoft.Blueprint/blueprintAssignments/assignSimpleBlueprint", + Error: false, + Expected: &BlueprintAssignmentId{ + Scope: "managementGroups/testAccManagementGroup", + ManagementGroup: "testAccManagementGroup", + Name: "assignSimpleBlueprint", + }, + }, + { + Name: "wrong case - subscription scoped", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Blueprint/blueprintassignments/assignSimpleBlueprint", + Error: true, + }, + { + Name: "wrong case - managementGroup scoped", + Input: "/managementGroups/testAccManagementGroup/providers/Microsoft.Blueprint/blueprintassignments/assignSimpleBlueprint", + Error: true, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Name) + + actual, err := BlueprintAssignmentID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + } + + if actual.ManagementGroup == "" && actual.Subscription != v.Expected.Subscription { + t.Fatalf("Expected %q but got %q for Subscription", v.Expected.Subscription, actual.Subscription) + } + + if actual.Subscription == "" && actual.ManagementGroup != v.Expected.ManagementGroup { + t.Fatalf("Expected %q but got %q for ManagementGroup", v.Expected.ManagementGroup, actual.ManagementGroup) + } + + } +} diff --git a/azurerm/internal/services/blueprints/parse/blueprint_version.go b/azurerm/internal/services/blueprints/parse/blueprint_version.go new file mode 100644 index 000000000000..81ec6c5a260d --- /dev/null +++ b/azurerm/internal/services/blueprints/parse/blueprint_version.go @@ -0,0 +1,63 @@ +package parse + +import ( + "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "strings" +) + +type BlueprintVersionId struct { + // "/{resourceScope}/providers/Microsoft.Blueprint/blueprints/{blueprintName}/versions/{versionId}" + // "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Blueprint/blueprints/simpleBlueprint/versions/v1" + // "/providers/Microsoft.Management/managementGroups/ContosoOnlineGroup/providers/Microsoft.Blueprint/blueprints/simpleBlueprint/versions/v1" + + Scope string + Blueprint string + Name string +} + +func BlueprintVersionID(input string) (*BlueprintVersionId, error) { + if len(input) == 0 { + return nil, fmt.Errorf("Bad: Blueprint version ID cannot be an empty string") + } + + versionId := BlueprintVersionId{} + + idParts := strings.Split(strings.Trim(input, "/"), "/") + if len(idParts) != 8 && len(idParts) != 10 { + return nil, fmt.Errorf("Bad: Blueprint Version ID invalid: %q", input) + } + + switch idParts[0] { + case "providers": + // check casing on segments + if idParts[1] != "Microsoft.Management" || idParts[2] != "managementGroups" { + return nil, fmt.Errorf("ID has invalid provider scope segment (should be `/providers/Microsoft.Management/managementGroups` case sensitive): %q", input) + } + if idParts[4] != "providers" || idParts[5] != "Microsoft.Blueprint" || idParts[6] != "blueprints" { + return nil, fmt.Errorf("Bad: ID has invalid resource provider segment(s), shoud be `/providers/Microsoft.Blueprint/blueprints/`, case sensitive: %q", input) + + } + + versionId = BlueprintVersionId{ + Scope: fmt.Sprintf("providers/Microsoft.Management/managementGroups/%s", idParts[3]), + Blueprint: idParts[6], + Name: idParts[9], + } + + case "subscriptions": + id, err := azure.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("[ERROR] Unable to parse Image ID %q: %+v", input, err) + } + + versionId.Scope = fmt.Sprintf("subscriptions/%s", id.SubscriptionID) + versionId.Blueprint = idParts[5] + versionId.Name = idParts[7] + + default: + return nil, fmt.Errorf("Bad: Invalid ID, should start with one of `/provider` or `/subscriptions`: %q", input) + } + + return &versionId, nil +} diff --git a/azurerm/internal/services/blueprints/parse/blueprint_version_test.go b/azurerm/internal/services/blueprints/parse/blueprint_version_test.go new file mode 100644 index 000000000000..cb4acce48bae --- /dev/null +++ b/azurerm/internal/services/blueprints/parse/blueprint_version_test.go @@ -0,0 +1,68 @@ +package parse + +import "testing" + +func TestBlueprintVersionID(t *testing.T) { + testData := []struct { + Name string + Input string + Error bool + Expected *BlueprintVersionId + }{ + { + Name: "Empty", + Input: "", + Error: true, + }, + { + Name: "No Resource Groups Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", + Error: true, + }, + { + Name: "Invalid scope", + Input: "/managementGroups/testAccManagementGroup", + Error: true, + }, + // We have two valid possibilities to check for + { + Name: "Valid subscription scoped", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Blueprint/blueprints/simpleBlueprint/versions/v1-test", + Expected: &BlueprintVersionId{ + Scope: "subscriptions/00000000-0000-0000-0000-000000000000", + Blueprint: "simpleBlueprint", + Name: "v1-test", + }, + }, + { + Name: "Valid management group scoped", + Input: "/providers/Microsoft.Management/managementGroups/testAccManagementGroup/providers/Microsoft.Blueprint/blueprints/simpleBlueprint/versions/v1-test", + Expected: &BlueprintVersionId{ + Scope: "providers/Microsoft.Management/managementGroups/testAccManagementGroup", + Blueprint: "simpleBlueprint", + Name: "v1-test", + }, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Name) + + actual, err := BlueprintVersionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Name, actual.Name) + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + } +} diff --git a/azurerm/internal/services/blueprints/registration.go b/azurerm/internal/services/blueprints/registration.go new file mode 100644 index 000000000000..b9a310f3ac97 --- /dev/null +++ b/azurerm/internal/services/blueprints/registration.go @@ -0,0 +1,32 @@ +package blueprints + +import "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + +type Registration struct{} + +// Name is the name of this Service +func (r Registration) Name() string { + return "Blueprints" +} + +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Blueprints", + } +} + +// SupportedDataSources returns the supported Data Sources supported by this Service +func (r Registration) SupportedDataSources() map[string]*schema.Resource { + return map[string]*schema.Resource{ + "azurerm_blueprint_definition": dataSourceArmBlueprintDefinition(), + "azurerm_blueprint_published_version": dataSourceArmBlueprintPublishedVersion(), + } +} + +// SupportedResources returns the supported Resources supported by this Service +func (r Registration) SupportedResources() map[string]*schema.Resource { + return map[string]*schema.Resource{ + "azurerm_blueprint_assignment": resourceArmBlueprintAssignment(), + } +} diff --git a/azurerm/internal/services/blueprints/tests/blueprint_published_version_datasource_test.go b/azurerm/internal/services/blueprints/tests/blueprint_published_version_datasource_test.go new file mode 100644 index 000000000000..dacac9242ee8 --- /dev/null +++ b/azurerm/internal/services/blueprints/tests/blueprint_published_version_datasource_test.go @@ -0,0 +1,46 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceBlueprintPublishedVersion_basicSubscription(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_blueprint_published_version", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceBlueprintPublishedVersion_basicSubscription("testAcc_basicSubscription", "testAcc"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "target_scope", "subscription"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "Acceptance Test stub for Blueprints at Subscription"), + resource.TestCheckResourceAttrSet(data.ResourceName, "time_created"), + resource.TestCheckResourceAttrSet(data.ResourceName, "type"), + ), + }, + }, + }) +} + +func testAccDataSourceBlueprintPublishedVersion_basicSubscription(bpName, version string) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" { +} + +data "azurerm_blueprint_published_version" "test" { + subscription_id = data.azurerm_client_config.current.subscription_id + blueprint_name = "%s" + version = "%s" +} +`, bpName, version) +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/artifacts.go b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/artifacts.go new file mode 100644 index 000000000000..acb1c0367026 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/artifacts.go @@ -0,0 +1,397 @@ +package blueprint + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// ArtifactsClient is the blueprint Client +type ArtifactsClient struct { + BaseClient +} + +// NewArtifactsClient creates an instance of the ArtifactsClient client. +func NewArtifactsClient() ArtifactsClient { + return NewArtifactsClientWithBaseURI(DefaultBaseURI) +} + +// NewArtifactsClientWithBaseURI creates an instance of the ArtifactsClient client using a custom endpoint. Use this +// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). +func NewArtifactsClientWithBaseURI(baseURI string) ArtifactsClient { + return ArtifactsClient{NewWithBaseURI(baseURI)} +} + +// CreateOrUpdate create or update blueprint artifact. +// Parameters: +// resourceScope - the scope of the resource. Valid scopes are: management group (format: +// '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: +// '/subscriptions/{subscriptionId}'). +// blueprintName - name of the blueprint definition. +// artifactName - name of the blueprint artifact. +// artifact - blueprint artifact to create or update. +func (client ArtifactsClient) CreateOrUpdate(ctx context.Context, resourceScope string, blueprintName string, artifactName string, artifact BasicArtifact) (result ArtifactModel, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ArtifactsClient.CreateOrUpdate") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.CreateOrUpdatePreparer(ctx, resourceScope, blueprintName, artifactName, artifact) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.ArtifactsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "blueprint.ArtifactsClient", "CreateOrUpdate", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.ArtifactsClient", "CreateOrUpdate", resp, "Failure responding to request") + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client ArtifactsClient) CreateOrUpdatePreparer(ctx context.Context, resourceScope string, blueprintName string, artifactName string, artifact BasicArtifact) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "artifactName": autorest.Encode("path", artifactName), + "blueprintName": autorest.Encode("path", blueprintName), + "resourceScope": resourceScope, + } + + const APIVersion = "2018-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceScope}/providers/Microsoft.Blueprint/blueprints/{blueprintName}/artifacts/{artifactName}", pathParameters), + autorest.WithJSON(artifact), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (client ArtifactsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client ArtifactsClient) CreateOrUpdateResponder(resp *http.Response) (result ArtifactModel, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete delete a blueprint artifact. +// Parameters: +// resourceScope - the scope of the resource. Valid scopes are: management group (format: +// '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: +// '/subscriptions/{subscriptionId}'). +// blueprintName - name of the blueprint definition. +// artifactName - name of the blueprint artifact. +func (client ArtifactsClient) Delete(ctx context.Context, resourceScope string, blueprintName string, artifactName string) (result ArtifactModel, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ArtifactsClient.Delete") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.DeletePreparer(ctx, resourceScope, blueprintName, artifactName) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.ArtifactsClient", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "blueprint.ArtifactsClient", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.ArtifactsClient", "Delete", resp, "Failure responding to request") + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client ArtifactsClient) DeletePreparer(ctx context.Context, resourceScope string, blueprintName string, artifactName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "artifactName": autorest.Encode("path", artifactName), + "blueprintName": autorest.Encode("path", blueprintName), + "resourceScope": resourceScope, + } + + const APIVersion = "2018-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceScope}/providers/Microsoft.Blueprint/blueprints/{blueprintName}/artifacts/{artifactName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client ArtifactsClient) DeleteSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client ArtifactsClient) DeleteResponder(resp *http.Response) (result ArtifactModel, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Get get a blueprint artifact. +// Parameters: +// resourceScope - the scope of the resource. Valid scopes are: management group (format: +// '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: +// '/subscriptions/{subscriptionId}'). +// blueprintName - name of the blueprint definition. +// artifactName - name of the blueprint artifact. +func (client ArtifactsClient) Get(ctx context.Context, resourceScope string, blueprintName string, artifactName string) (result ArtifactModel, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ArtifactsClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetPreparer(ctx, resourceScope, blueprintName, artifactName) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.ArtifactsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "blueprint.ArtifactsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.ArtifactsClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client ArtifactsClient) GetPreparer(ctx context.Context, resourceScope string, blueprintName string, artifactName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "artifactName": autorest.Encode("path", artifactName), + "blueprintName": autorest.Encode("path", blueprintName), + "resourceScope": resourceScope, + } + + const APIVersion = "2018-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceScope}/providers/Microsoft.Blueprint/blueprints/{blueprintName}/artifacts/{artifactName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client ArtifactsClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client ArtifactsClient) GetResponder(resp *http.Response) (result ArtifactModel, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List list artifacts for a given blueprint definition. +// Parameters: +// resourceScope - the scope of the resource. Valid scopes are: management group (format: +// '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: +// '/subscriptions/{subscriptionId}'). +// blueprintName - name of the blueprint definition. +func (client ArtifactsClient) List(ctx context.Context, resourceScope string, blueprintName string) (result ArtifactListPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ArtifactsClient.List") + defer func() { + sc := -1 + if result.al.Response.Response != nil { + sc = result.al.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, resourceScope, blueprintName) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.ArtifactsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.al.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "blueprint.ArtifactsClient", "List", resp, "Failure sending request") + return + } + + result.al, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.ArtifactsClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client ArtifactsClient) ListPreparer(ctx context.Context, resourceScope string, blueprintName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "blueprintName": autorest.Encode("path", blueprintName), + "resourceScope": resourceScope, + } + + const APIVersion = "2018-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceScope}/providers/Microsoft.Blueprint/blueprints/{blueprintName}/artifacts", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client ArtifactsClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client ArtifactsClient) ListResponder(resp *http.Response) (result ArtifactList, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client ArtifactsClient) listNextResults(ctx context.Context, lastResults ArtifactList) (result ArtifactList, err error) { + req, err := lastResults.artifactListPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "blueprint.ArtifactsClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "blueprint.ArtifactsClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.ArtifactsClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client ArtifactsClient) ListComplete(ctx context.Context, resourceScope string, blueprintName string) (result ArtifactListIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ArtifactsClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx, resourceScope, blueprintName) + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/assignmentoperations.go b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/assignmentoperations.go new file mode 100644 index 000000000000..c8edd7d63086 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/assignmentoperations.go @@ -0,0 +1,237 @@ +package blueprint + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// AssignmentOperationsClient is the blueprint Client +type AssignmentOperationsClient struct { + BaseClient +} + +// NewAssignmentOperationsClient creates an instance of the AssignmentOperationsClient client. +func NewAssignmentOperationsClient() AssignmentOperationsClient { + return NewAssignmentOperationsClientWithBaseURI(DefaultBaseURI) +} + +// NewAssignmentOperationsClientWithBaseURI creates an instance of the AssignmentOperationsClient client using a custom +// endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure +// stack). +func NewAssignmentOperationsClientWithBaseURI(baseURI string) AssignmentOperationsClient { + return AssignmentOperationsClient{NewWithBaseURI(baseURI)} +} + +// Get get a blueprint assignment operation. +// Parameters: +// resourceScope - the scope of the resource. Valid scopes are: management group (format: +// '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: +// '/subscriptions/{subscriptionId}'). +// assignmentName - name of the blueprint assignment. +// assignmentOperationName - name of the blueprint assignment operation. +func (client AssignmentOperationsClient) Get(ctx context.Context, resourceScope string, assignmentName string, assignmentOperationName string) (result AssignmentOperation, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentOperationsClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetPreparer(ctx, resourceScope, assignmentName, assignmentOperationName) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.AssignmentOperationsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "blueprint.AssignmentOperationsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.AssignmentOperationsClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client AssignmentOperationsClient) GetPreparer(ctx context.Context, resourceScope string, assignmentName string, assignmentOperationName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "assignmentName": autorest.Encode("path", assignmentName), + "assignmentOperationName": autorest.Encode("path", assignmentOperationName), + "resourceScope": resourceScope, + } + + const APIVersion = "2018-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceScope}/providers/Microsoft.Blueprint/blueprintAssignments/{assignmentName}/assignmentOperations/{assignmentOperationName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client AssignmentOperationsClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client AssignmentOperationsClient) GetResponder(resp *http.Response) (result AssignmentOperation, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List list operations for given blueprint assignment within a subscription or a management group. +// Parameters: +// resourceScope - the scope of the resource. Valid scopes are: management group (format: +// '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: +// '/subscriptions/{subscriptionId}'). +// assignmentName - name of the blueprint assignment. +func (client AssignmentOperationsClient) List(ctx context.Context, resourceScope string, assignmentName string) (result AssignmentOperationListPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentOperationsClient.List") + defer func() { + sc := -1 + if result.aol.Response.Response != nil { + sc = result.aol.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, resourceScope, assignmentName) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.AssignmentOperationsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.aol.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "blueprint.AssignmentOperationsClient", "List", resp, "Failure sending request") + return + } + + result.aol, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.AssignmentOperationsClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client AssignmentOperationsClient) ListPreparer(ctx context.Context, resourceScope string, assignmentName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "assignmentName": autorest.Encode("path", assignmentName), + "resourceScope": resourceScope, + } + + const APIVersion = "2018-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceScope}/providers/Microsoft.Blueprint/blueprintAssignments/{assignmentName}/assignmentOperations", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client AssignmentOperationsClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client AssignmentOperationsClient) ListResponder(resp *http.Response) (result AssignmentOperationList, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client AssignmentOperationsClient) listNextResults(ctx context.Context, lastResults AssignmentOperationList) (result AssignmentOperationList, err error) { + req, err := lastResults.assignmentOperationListPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "blueprint.AssignmentOperationsClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "blueprint.AssignmentOperationsClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.AssignmentOperationsClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client AssignmentOperationsClient) ListComplete(ctx context.Context, resourceScope string, assignmentName string) (result AssignmentOperationListIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentOperationsClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx, resourceScope, assignmentName) + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/assignments.go b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/assignments.go new file mode 100644 index 000000000000..7510379d963a --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/assignments.go @@ -0,0 +1,477 @@ +package blueprint + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// AssignmentsClient is the blueprint Client +type AssignmentsClient struct { + BaseClient +} + +// NewAssignmentsClient creates an instance of the AssignmentsClient client. +func NewAssignmentsClient() AssignmentsClient { + return NewAssignmentsClientWithBaseURI(DefaultBaseURI) +} + +// NewAssignmentsClientWithBaseURI creates an instance of the AssignmentsClient client using a custom endpoint. Use +// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). +func NewAssignmentsClientWithBaseURI(baseURI string) AssignmentsClient { + return AssignmentsClient{NewWithBaseURI(baseURI)} +} + +// CreateOrUpdate create or update a blueprint assignment. +// Parameters: +// resourceScope - the scope of the resource. Valid scopes are: management group (format: +// '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: +// '/subscriptions/{subscriptionId}'). +// assignmentName - name of the blueprint assignment. +// assignment - blueprint assignment object to save. +func (client AssignmentsClient) CreateOrUpdate(ctx context.Context, resourceScope string, assignmentName string, assignment Assignment) (result Assignment, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.CreateOrUpdate") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: assignment, + Constraints: []validation.Constraint{{Target: "assignment.Identity", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "assignment.AssignmentProperties", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "assignment.AssignmentProperties.Parameters", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "assignment.AssignmentProperties.ResourceGroups", Name: validation.Null, Rule: true, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("blueprint.AssignmentsClient", "CreateOrUpdate", err.Error()) + } + + req, err := client.CreateOrUpdatePreparer(ctx, resourceScope, assignmentName, assignment) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.AssignmentsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "blueprint.AssignmentsClient", "CreateOrUpdate", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.AssignmentsClient", "CreateOrUpdate", resp, "Failure responding to request") + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client AssignmentsClient) CreateOrUpdatePreparer(ctx context.Context, resourceScope string, assignmentName string, assignment Assignment) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "assignmentName": autorest.Encode("path", assignmentName), + "resourceScope": resourceScope, + } + + const APIVersion = "2018-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceScope}/providers/Microsoft.Blueprint/blueprintAssignments/{assignmentName}", pathParameters), + autorest.WithJSON(assignment), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (client AssignmentsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client AssignmentsClient) CreateOrUpdateResponder(resp *http.Response) (result Assignment, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete delete a blueprint assignment. +// Parameters: +// resourceScope - the scope of the resource. Valid scopes are: management group (format: +// '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: +// '/subscriptions/{subscriptionId}'). +// assignmentName - name of the blueprint assignment. +func (client AssignmentsClient) Delete(ctx context.Context, resourceScope string, assignmentName string) (result Assignment, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.Delete") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.DeletePreparer(ctx, resourceScope, assignmentName) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.AssignmentsClient", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "blueprint.AssignmentsClient", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.AssignmentsClient", "Delete", resp, "Failure responding to request") + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client AssignmentsClient) DeletePreparer(ctx context.Context, resourceScope string, assignmentName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "assignmentName": autorest.Encode("path", assignmentName), + "resourceScope": resourceScope, + } + + const APIVersion = "2018-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceScope}/providers/Microsoft.Blueprint/blueprintAssignments/{assignmentName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client AssignmentsClient) DeleteSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client AssignmentsClient) DeleteResponder(resp *http.Response) (result Assignment, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Get get a blueprint assignment. +// Parameters: +// resourceScope - the scope of the resource. Valid scopes are: management group (format: +// '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: +// '/subscriptions/{subscriptionId}'). +// assignmentName - name of the blueprint assignment. +func (client AssignmentsClient) Get(ctx context.Context, resourceScope string, assignmentName string) (result Assignment, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetPreparer(ctx, resourceScope, assignmentName) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.AssignmentsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "blueprint.AssignmentsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.AssignmentsClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client AssignmentsClient) GetPreparer(ctx context.Context, resourceScope string, assignmentName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "assignmentName": autorest.Encode("path", assignmentName), + "resourceScope": resourceScope, + } + + const APIVersion = "2018-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceScope}/providers/Microsoft.Blueprint/blueprintAssignments/{assignmentName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client AssignmentsClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client AssignmentsClient) GetResponder(resp *http.Response) (result Assignment, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List list blueprint assignments within a subscription or a management group. +// Parameters: +// resourceScope - the scope of the resource. Valid scopes are: management group (format: +// '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: +// '/subscriptions/{subscriptionId}'). +func (client AssignmentsClient) List(ctx context.Context, resourceScope string) (result AssignmentListPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.List") + defer func() { + sc := -1 + if result.al.Response.Response != nil { + sc = result.al.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, resourceScope) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.AssignmentsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.al.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "blueprint.AssignmentsClient", "List", resp, "Failure sending request") + return + } + + result.al, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.AssignmentsClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client AssignmentsClient) ListPreparer(ctx context.Context, resourceScope string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceScope": resourceScope, + } + + const APIVersion = "2018-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceScope}/providers/Microsoft.Blueprint/blueprintAssignments", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client AssignmentsClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client AssignmentsClient) ListResponder(resp *http.Response) (result AssignmentList, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client AssignmentsClient) listNextResults(ctx context.Context, lastResults AssignmentList) (result AssignmentList, err error) { + req, err := lastResults.assignmentListPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "blueprint.AssignmentsClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "blueprint.AssignmentsClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.AssignmentsClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client AssignmentsClient) ListComplete(ctx context.Context, resourceScope string) (result AssignmentListIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx, resourceScope) + return +} + +// WhoIsBlueprint get Blueprints service SPN objectId +// Parameters: +// resourceScope - the scope of the resource. Valid scopes are: management group (format: +// '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: +// '/subscriptions/{subscriptionId}'). +// assignmentName - name of the blueprint assignment. +func (client AssignmentsClient) WhoIsBlueprint(ctx context.Context, resourceScope string, assignmentName string) (result WhoIsBlueprintContract, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.WhoIsBlueprint") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.WhoIsBlueprintPreparer(ctx, resourceScope, assignmentName) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.AssignmentsClient", "WhoIsBlueprint", nil, "Failure preparing request") + return + } + + resp, err := client.WhoIsBlueprintSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "blueprint.AssignmentsClient", "WhoIsBlueprint", resp, "Failure sending request") + return + } + + result, err = client.WhoIsBlueprintResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.AssignmentsClient", "WhoIsBlueprint", resp, "Failure responding to request") + } + + return +} + +// WhoIsBlueprintPreparer prepares the WhoIsBlueprint request. +func (client AssignmentsClient) WhoIsBlueprintPreparer(ctx context.Context, resourceScope string, assignmentName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "assignmentName": autorest.Encode("path", assignmentName), + "resourceScope": resourceScope, + } + + const APIVersion = "2018-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceScope}/providers/Microsoft.Blueprint/blueprintAssignments/{assignmentName}/WhoIsBlueprint", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// WhoIsBlueprintSender sends the WhoIsBlueprint request. The method will close the +// http.Response Body if it receives an error. +func (client AssignmentsClient) WhoIsBlueprintSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// WhoIsBlueprintResponder handles the response to the WhoIsBlueprint request. The method always +// closes the http.Response Body. +func (client AssignmentsClient) WhoIsBlueprintResponder(resp *http.Response) (result WhoIsBlueprintContract, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/blueprints.go b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/blueprints.go new file mode 100644 index 000000000000..666f6d23920b --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/blueprints.go @@ -0,0 +1,396 @@ +package blueprint + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// BlueprintsClient is the blueprint Client +type BlueprintsClient struct { + BaseClient +} + +// NewBlueprintsClient creates an instance of the BlueprintsClient client. +func NewBlueprintsClient() BlueprintsClient { + return NewBlueprintsClientWithBaseURI(DefaultBaseURI) +} + +// NewBlueprintsClientWithBaseURI creates an instance of the BlueprintsClient client using a custom endpoint. Use this +// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). +func NewBlueprintsClientWithBaseURI(baseURI string) BlueprintsClient { + return BlueprintsClient{NewWithBaseURI(baseURI)} +} + +// CreateOrUpdate create or update a blueprint definition. +// Parameters: +// resourceScope - the scope of the resource. Valid scopes are: management group (format: +// '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: +// '/subscriptions/{subscriptionId}'). +// blueprintName - name of the blueprint definition. +// blueprint - blueprint definition. +func (client BlueprintsClient) CreateOrUpdate(ctx context.Context, resourceScope string, blueprintName string, blueprint Model) (result Model, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/BlueprintsClient.CreateOrUpdate") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: blueprint, + Constraints: []validation.Constraint{{Target: "blueprint.Properties", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("blueprint.BlueprintsClient", "CreateOrUpdate", err.Error()) + } + + req, err := client.CreateOrUpdatePreparer(ctx, resourceScope, blueprintName, blueprint) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.BlueprintsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "blueprint.BlueprintsClient", "CreateOrUpdate", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.BlueprintsClient", "CreateOrUpdate", resp, "Failure responding to request") + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client BlueprintsClient) CreateOrUpdatePreparer(ctx context.Context, resourceScope string, blueprintName string, blueprint Model) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "blueprintName": autorest.Encode("path", blueprintName), + "resourceScope": resourceScope, + } + + const APIVersion = "2018-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceScope}/providers/Microsoft.Blueprint/blueprints/{blueprintName}", pathParameters), + autorest.WithJSON(blueprint), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (client BlueprintsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client BlueprintsClient) CreateOrUpdateResponder(resp *http.Response) (result Model, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete delete a blueprint definition. +// Parameters: +// resourceScope - the scope of the resource. Valid scopes are: management group (format: +// '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: +// '/subscriptions/{subscriptionId}'). +// blueprintName - name of the blueprint definition. +func (client BlueprintsClient) Delete(ctx context.Context, resourceScope string, blueprintName string) (result Model, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/BlueprintsClient.Delete") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.DeletePreparer(ctx, resourceScope, blueprintName) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.BlueprintsClient", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "blueprint.BlueprintsClient", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.BlueprintsClient", "Delete", resp, "Failure responding to request") + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client BlueprintsClient) DeletePreparer(ctx context.Context, resourceScope string, blueprintName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "blueprintName": autorest.Encode("path", blueprintName), + "resourceScope": resourceScope, + } + + const APIVersion = "2018-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceScope}/providers/Microsoft.Blueprint/blueprints/{blueprintName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client BlueprintsClient) DeleteSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client BlueprintsClient) DeleteResponder(resp *http.Response) (result Model, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Get get a blueprint definition. +// Parameters: +// resourceScope - the scope of the resource. Valid scopes are: management group (format: +// '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: +// '/subscriptions/{subscriptionId}'). +// blueprintName - name of the blueprint definition. +func (client BlueprintsClient) Get(ctx context.Context, resourceScope string, blueprintName string) (result Model, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/BlueprintsClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetPreparer(ctx, resourceScope, blueprintName) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.BlueprintsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "blueprint.BlueprintsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.BlueprintsClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client BlueprintsClient) GetPreparer(ctx context.Context, resourceScope string, blueprintName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "blueprintName": autorest.Encode("path", blueprintName), + "resourceScope": resourceScope, + } + + const APIVersion = "2018-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceScope}/providers/Microsoft.Blueprint/blueprints/{blueprintName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client BlueprintsClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client BlueprintsClient) GetResponder(resp *http.Response) (result Model, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List list blueprint definitions. +// Parameters: +// resourceScope - the scope of the resource. Valid scopes are: management group (format: +// '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: +// '/subscriptions/{subscriptionId}'). +func (client BlueprintsClient) List(ctx context.Context, resourceScope string) (result ListPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/BlueprintsClient.List") + defer func() { + sc := -1 + if result.l.Response.Response != nil { + sc = result.l.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, resourceScope) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.BlueprintsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.l.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "blueprint.BlueprintsClient", "List", resp, "Failure sending request") + return + } + + result.l, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.BlueprintsClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client BlueprintsClient) ListPreparer(ctx context.Context, resourceScope string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceScope": resourceScope, + } + + const APIVersion = "2018-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceScope}/providers/Microsoft.Blueprint/blueprints", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client BlueprintsClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client BlueprintsClient) ListResponder(resp *http.Response) (result List, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client BlueprintsClient) listNextResults(ctx context.Context, lastResults List) (result List, err error) { + req, err := lastResults.listPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "blueprint.BlueprintsClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "blueprint.BlueprintsClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.BlueprintsClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client BlueprintsClient) ListComplete(ctx context.Context, resourceScope string) (result ListIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/BlueprintsClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx, resourceScope) + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/client.go b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/client.go new file mode 100644 index 000000000000..e20a4848b2cf --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/client.go @@ -0,0 +1,50 @@ +// Package blueprint implements the Azure ARM Blueprint service API version 2018-11-01-preview. +// +// Blueprint Client +package blueprint + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" +) + +const ( + // DefaultBaseURI is the default URI used for the service Blueprint + DefaultBaseURI = "https://management.azure.com" +) + +// BaseClient is the base client for Blueprint. +type BaseClient struct { + autorest.Client + BaseURI string +} + +// New creates an instance of the BaseClient client. +func New() BaseClient { + return NewWithBaseURI(DefaultBaseURI) +} + +// NewWithBaseURI creates an instance of the BaseClient client using a custom endpoint. Use this when interacting with +// an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). +func NewWithBaseURI(baseURI string) BaseClient { + return BaseClient{ + Client: autorest.NewClientWithUserAgent(UserAgent()), + BaseURI: baseURI, + } +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/models.go b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/models.go new file mode 100644 index 000000000000..28b29e6448ce --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/models.go @@ -0,0 +1,2401 @@ +package blueprint + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "encoding/json" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/date" + "github.com/Azure/go-autorest/autorest/to" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// The package's fully qualified name. +const fqdn = "github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint" + +// AssignmentLockMode enumerates the values for assignment lock mode. +type AssignmentLockMode string + +const ( + // AllResourcesDoNotDelete ... + AllResourcesDoNotDelete AssignmentLockMode = "AllResourcesDoNotDelete" + // AllResourcesReadOnly ... + AllResourcesReadOnly AssignmentLockMode = "AllResourcesReadOnly" + // None ... + None AssignmentLockMode = "None" +) + +// PossibleAssignmentLockModeValues returns an array of possible values for the AssignmentLockMode const type. +func PossibleAssignmentLockModeValues() []AssignmentLockMode { + return []AssignmentLockMode{AllResourcesDoNotDelete, AllResourcesReadOnly, None} +} + +// AssignmentProvisioningState enumerates the values for assignment provisioning state. +type AssignmentProvisioningState string + +const ( + // Canceled ... + Canceled AssignmentProvisioningState = "canceled" + // Cancelling ... + Cancelling AssignmentProvisioningState = "cancelling" + // Creating ... + Creating AssignmentProvisioningState = "creating" + // Deleting ... + Deleting AssignmentProvisioningState = "deleting" + // Deploying ... + Deploying AssignmentProvisioningState = "deploying" + // Failed ... + Failed AssignmentProvisioningState = "failed" + // Locking ... + Locking AssignmentProvisioningState = "locking" + // Succeeded ... + Succeeded AssignmentProvisioningState = "succeeded" + // Validating ... + Validating AssignmentProvisioningState = "validating" + // Waiting ... + Waiting AssignmentProvisioningState = "waiting" +) + +// PossibleAssignmentProvisioningStateValues returns an array of possible values for the AssignmentProvisioningState const type. +func PossibleAssignmentProvisioningStateValues() []AssignmentProvisioningState { + return []AssignmentProvisioningState{Canceled, Cancelling, Creating, Deleting, Deploying, Failed, Locking, Succeeded, Validating, Waiting} +} + +// Kind enumerates the values for kind. +type Kind string + +const ( + // KindArtifact ... + KindArtifact Kind = "Artifact" + // KindPolicyAssignment ... + KindPolicyAssignment Kind = "policyAssignment" + // KindRoleAssignment ... + KindRoleAssignment Kind = "roleAssignment" + // KindTemplate ... + KindTemplate Kind = "template" +) + +// PossibleKindValues returns an array of possible values for the Kind const type. +func PossibleKindValues() []Kind { + return []Kind{KindArtifact, KindPolicyAssignment, KindRoleAssignment, KindTemplate} +} + +// ManagedServiceIdentityType enumerates the values for managed service identity type. +type ManagedServiceIdentityType string + +const ( + // ManagedServiceIdentityTypeNone ... + ManagedServiceIdentityTypeNone ManagedServiceIdentityType = "None" + // ManagedServiceIdentityTypeSystemAssigned ... + ManagedServiceIdentityTypeSystemAssigned ManagedServiceIdentityType = "SystemAssigned" + // ManagedServiceIdentityTypeUserAssigned ... + ManagedServiceIdentityTypeUserAssigned ManagedServiceIdentityType = "UserAssigned" +) + +// PossibleManagedServiceIdentityTypeValues returns an array of possible values for the ManagedServiceIdentityType const type. +func PossibleManagedServiceIdentityTypeValues() []ManagedServiceIdentityType { + return []ManagedServiceIdentityType{ManagedServiceIdentityTypeNone, ManagedServiceIdentityTypeSystemAssigned, ManagedServiceIdentityTypeUserAssigned} +} + +// TargetScope enumerates the values for target scope. +type TargetScope string + +const ( + // ManagementGroup The blueprint targets a management group during blueprint assignment. This is reserved + // for future use. + ManagementGroup TargetScope = "managementGroup" + // Subscription The blueprint targets a subscription during blueprint assignment. + Subscription TargetScope = "subscription" +) + +// PossibleTargetScopeValues returns an array of possible values for the TargetScope const type. +func PossibleTargetScopeValues() []TargetScope { + return []TargetScope{ManagementGroup, Subscription} +} + +// TemplateParameterType enumerates the values for template parameter type. +type TemplateParameterType string + +const ( + // Array ... + Array TemplateParameterType = "array" + // Bool ... + Bool TemplateParameterType = "bool" + // Int ... + Int TemplateParameterType = "int" + // Object ... + Object TemplateParameterType = "object" + // SecureObject ... + SecureObject TemplateParameterType = "secureObject" + // SecureString ... + SecureString TemplateParameterType = "secureString" + // String ... + String TemplateParameterType = "string" +) + +// PossibleTemplateParameterTypeValues returns an array of possible values for the TemplateParameterType const type. +func PossibleTemplateParameterTypeValues() []TemplateParameterType { + return []TemplateParameterType{Array, Bool, Int, Object, SecureObject, SecureString, String} +} + +// BasicArtifact represents a blueprint artifact. +type BasicArtifact interface { + AsTemplateArtifact() (*TemplateArtifact, bool) + AsRoleAssignmentArtifact() (*RoleAssignmentArtifact, bool) + AsPolicyAssignmentArtifact() (*PolicyAssignmentArtifact, bool) + AsArtifact() (*Artifact, bool) +} + +// Artifact represents a blueprint artifact. +type Artifact struct { + autorest.Response `json:"-"` + // Kind - Possible values include: 'KindArtifact', 'KindTemplate', 'KindRoleAssignment', 'KindPolicyAssignment' + Kind Kind `json:"kind,omitempty"` + // ID - READ-ONLY; String Id used to locate any resource on Azure. + ID *string `json:"id,omitempty"` + // Type - READ-ONLY; Type of this resource. + Type *string `json:"type,omitempty"` + // Name - READ-ONLY; Name of this resource. + Name *string `json:"name,omitempty"` +} + +func unmarshalBasicArtifact(body []byte) (BasicArtifact, error) { + var m map[string]interface{} + err := json.Unmarshal(body, &m) + if err != nil { + return nil, err + } + + switch m["kind"] { + case string(KindTemplate): + var ta TemplateArtifact + err := json.Unmarshal(body, &ta) + return ta, err + case string(KindRoleAssignment): + var raa RoleAssignmentArtifact + err := json.Unmarshal(body, &raa) + return raa, err + case string(KindPolicyAssignment): + var paa PolicyAssignmentArtifact + err := json.Unmarshal(body, &paa) + return paa, err + default: + var a Artifact + err := json.Unmarshal(body, &a) + return a, err + } +} +func unmarshalBasicArtifactArray(body []byte) ([]BasicArtifact, error) { + var rawMessages []*json.RawMessage + err := json.Unmarshal(body, &rawMessages) + if err != nil { + return nil, err + } + + aArray := make([]BasicArtifact, len(rawMessages)) + + for index, rawMessage := range rawMessages { + a, err := unmarshalBasicArtifact(*rawMessage) + if err != nil { + return nil, err + } + aArray[index] = a + } + return aArray, nil +} + +// MarshalJSON is the custom marshaler for Artifact. +func (a Artifact) MarshalJSON() ([]byte, error) { + a.Kind = KindArtifact + objectMap := make(map[string]interface{}) + if a.Kind != "" { + objectMap["kind"] = a.Kind + } + return json.Marshal(objectMap) +} + +// AsTemplateArtifact is the BasicArtifact implementation for Artifact. +func (a Artifact) AsTemplateArtifact() (*TemplateArtifact, bool) { + return nil, false +} + +// AsRoleAssignmentArtifact is the BasicArtifact implementation for Artifact. +func (a Artifact) AsRoleAssignmentArtifact() (*RoleAssignmentArtifact, bool) { + return nil, false +} + +// AsPolicyAssignmentArtifact is the BasicArtifact implementation for Artifact. +func (a Artifact) AsPolicyAssignmentArtifact() (*PolicyAssignmentArtifact, bool) { + return nil, false +} + +// AsArtifact is the BasicArtifact implementation for Artifact. +func (a Artifact) AsArtifact() (*Artifact, bool) { + return &a, true +} + +// AsBasicArtifact is the BasicArtifact implementation for Artifact. +func (a Artifact) AsBasicArtifact() (BasicArtifact, bool) { + return &a, true +} + +// ArtifactList list of blueprint artifacts. +type ArtifactList struct { + autorest.Response `json:"-"` + // Value - List of blueprint artifacts. + Value *[]BasicArtifact `json:"value,omitempty"` + // NextLink - READ-ONLY; Link to the next page of results. + NextLink *string `json:"nextLink,omitempty"` +} + +// UnmarshalJSON is the custom unmarshaler for ArtifactList struct. +func (al *ArtifactList) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "value": + if v != nil { + value, err := unmarshalBasicArtifactArray(*v) + if err != nil { + return err + } + al.Value = &value + } + case "nextLink": + if v != nil { + var nextLink string + err = json.Unmarshal(*v, &nextLink) + if err != nil { + return err + } + al.NextLink = &nextLink + } + } + } + + return nil +} + +// ArtifactListIterator provides access to a complete listing of Artifact values. +type ArtifactListIterator struct { + i int + page ArtifactListPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *ArtifactListIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ArtifactListIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *ArtifactListIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter ArtifactListIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter ArtifactListIterator) Response() ArtifactList { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter ArtifactListIterator) Value() BasicArtifact { + if !iter.page.NotDone() { + return Artifact{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the ArtifactListIterator type. +func NewArtifactListIterator(page ArtifactListPage) ArtifactListIterator { + return ArtifactListIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (al ArtifactList) IsEmpty() bool { + return al.Value == nil || len(*al.Value) == 0 +} + +// artifactListPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (al ArtifactList) artifactListPreparer(ctx context.Context) (*http.Request, error) { + if al.NextLink == nil || len(to.String(al.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(al.NextLink))) +} + +// ArtifactListPage contains a page of BasicArtifact values. +type ArtifactListPage struct { + fn func(context.Context, ArtifactList) (ArtifactList, error) + al ArtifactList +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *ArtifactListPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ArtifactListPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + next, err := page.fn(ctx, page.al) + if err != nil { + return err + } + page.al = next + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *ArtifactListPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page ArtifactListPage) NotDone() bool { + return !page.al.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page ArtifactListPage) Response() ArtifactList { + return page.al +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page ArtifactListPage) Values() []BasicArtifact { + if page.al.IsEmpty() { + return nil + } + return *page.al.Value +} + +// Creates a new instance of the ArtifactListPage type. +func NewArtifactListPage(getNextPage func(context.Context, ArtifactList) (ArtifactList, error)) ArtifactListPage { + return ArtifactListPage{fn: getNextPage} +} + +// ArtifactModel ... +type ArtifactModel struct { + autorest.Response `json:"-"` + Value BasicArtifact `json:"value,omitempty"` +} + +// UnmarshalJSON is the custom unmarshaler for ArtifactModel struct. +func (am *ArtifactModel) UnmarshalJSON(body []byte) error { + a, err := unmarshalBasicArtifact(body) + if err != nil { + return err + } + am.Value = a + + return nil +} + +// ArtifactPropertiesBase common properties shared by different artifacts. +type ArtifactPropertiesBase struct { + // DependsOn - Artifacts which need to be deployed before the specified artifact. + DependsOn *[]string `json:"dependsOn,omitempty"` +} + +// Assignment represents a blueprint assignment. +type Assignment struct { + autorest.Response `json:"-"` + // Identity - Managed identity for this blueprint assignment. + Identity *ManagedServiceIdentity `json:"identity,omitempty"` + // AssignmentProperties - Properties for blueprint assignment object. + *AssignmentProperties `json:"properties,omitempty"` + // Location - The location of this blueprint assignment. + Location *string `json:"location,omitempty"` + // ID - READ-ONLY; String Id used to locate any resource on Azure. + ID *string `json:"id,omitempty"` + // Type - READ-ONLY; Type of this resource. + Type *string `json:"type,omitempty"` + // Name - READ-ONLY; Name of this resource. + Name *string `json:"name,omitempty"` +} + +// MarshalJSON is the custom marshaler for Assignment. +func (a Assignment) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if a.Identity != nil { + objectMap["identity"] = a.Identity + } + if a.AssignmentProperties != nil { + objectMap["properties"] = a.AssignmentProperties + } + if a.Location != nil { + objectMap["location"] = a.Location + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for Assignment struct. +func (a *Assignment) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "identity": + if v != nil { + var identity ManagedServiceIdentity + err = json.Unmarshal(*v, &identity) + if err != nil { + return err + } + a.Identity = &identity + } + case "properties": + if v != nil { + var assignmentProperties AssignmentProperties + err = json.Unmarshal(*v, &assignmentProperties) + if err != nil { + return err + } + a.AssignmentProperties = &assignmentProperties + } + case "location": + if v != nil { + var location string + err = json.Unmarshal(*v, &location) + if err != nil { + return err + } + a.Location = &location + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + a.ID = &ID + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + a.Type = &typeVar + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + a.Name = &name + } + } + } + + return nil +} + +// AssignmentDeploymentJob represents individual job in given blueprint assignment operation. +type AssignmentDeploymentJob struct { + // Kind - Kind of job. + Kind *string `json:"kind,omitempty"` + // Action - Name of the action performed in this job. + Action *string `json:"action,omitempty"` + // JobID - Id of this job. + JobID *string `json:"jobId,omitempty"` + // JobState - State of this job. + JobState *string `json:"jobState,omitempty"` + // Result - Deployment job result. + Result *AssignmentDeploymentJobResult `json:"result,omitempty"` + // History - Result of this deployment job for each retry. + History *[]AssignmentDeploymentJobResult `json:"history,omitempty"` + // RequestURI - Reference to deployment job resource id. + RequestURI *string `json:"requestUri,omitempty"` +} + +// AssignmentDeploymentJobResult result of each individual deployment in a blueprint assignment. +type AssignmentDeploymentJobResult struct { + // Error - Contains error details if deployment job failed. + Error *AzureResourceManagerError `json:"error,omitempty"` + // Resources - Resources created as result of the deployment job. + Resources *[]AssignmentJobCreatedResource `json:"resources,omitempty"` +} + +// AssignmentJobCreatedResource azure resource created from deployment job. +type AssignmentJobCreatedResource struct { + // Properties - Additional properties in a dictionary. + Properties map[string]*string `json:"properties"` + // ID - READ-ONLY; String Id used to locate any resource on Azure. + ID *string `json:"id,omitempty"` + // Type - READ-ONLY; Type of this resource. + Type *string `json:"type,omitempty"` + // Name - READ-ONLY; Name of this resource. + Name *string `json:"name,omitempty"` +} + +// MarshalJSON is the custom marshaler for AssignmentJobCreatedResource. +func (ajcr AssignmentJobCreatedResource) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if ajcr.Properties != nil { + objectMap["properties"] = ajcr.Properties + } + return json.Marshal(objectMap) +} + +// AssignmentList list of blueprint assignments +type AssignmentList struct { + autorest.Response `json:"-"` + // Value - List of blueprint assignments. + Value *[]Assignment `json:"value,omitempty"` + // NextLink - READ-ONLY; Link to the next page of results. + NextLink *string `json:"nextLink,omitempty"` +} + +// AssignmentListIterator provides access to a complete listing of Assignment values. +type AssignmentListIterator struct { + i int + page AssignmentListPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *AssignmentListIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentListIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *AssignmentListIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter AssignmentListIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter AssignmentListIterator) Response() AssignmentList { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter AssignmentListIterator) Value() Assignment { + if !iter.page.NotDone() { + return Assignment{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the AssignmentListIterator type. +func NewAssignmentListIterator(page AssignmentListPage) AssignmentListIterator { + return AssignmentListIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (al AssignmentList) IsEmpty() bool { + return al.Value == nil || len(*al.Value) == 0 +} + +// assignmentListPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (al AssignmentList) assignmentListPreparer(ctx context.Context) (*http.Request, error) { + if al.NextLink == nil || len(to.String(al.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(al.NextLink))) +} + +// AssignmentListPage contains a page of Assignment values. +type AssignmentListPage struct { + fn func(context.Context, AssignmentList) (AssignmentList, error) + al AssignmentList +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *AssignmentListPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentListPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + next, err := page.fn(ctx, page.al) + if err != nil { + return err + } + page.al = next + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *AssignmentListPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page AssignmentListPage) NotDone() bool { + return !page.al.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page AssignmentListPage) Response() AssignmentList { + return page.al +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page AssignmentListPage) Values() []Assignment { + if page.al.IsEmpty() { + return nil + } + return *page.al.Value +} + +// Creates a new instance of the AssignmentListPage type. +func NewAssignmentListPage(getNextPage func(context.Context, AssignmentList) (AssignmentList, error)) AssignmentListPage { + return AssignmentListPage{fn: getNextPage} +} + +// AssignmentLockSettings defines how resources deployed by a blueprint assignment are locked. +type AssignmentLockSettings struct { + // Mode - Lock mode. Possible values include: 'None', 'AllResourcesReadOnly', 'AllResourcesDoNotDelete' + Mode AssignmentLockMode `json:"mode,omitempty"` + // ExcludedPrincipals - List of AAD principals excluded from blueprint locks. Up to 5 principals are permitted. + ExcludedPrincipals *[]string `json:"excludedPrincipals,omitempty"` + // ExcludedActions - List of management operations that are excluded from blueprint locks. Up to 200 actions are permitted. If the lock mode is set to 'AllResourcesReadOnly', then the following actions are automatically appended to 'excludedActions': '*/read', 'Microsoft.Network/virtualNetworks/subnets/join/action' and 'Microsoft.Authorization/locks/delete'. If the lock mode is set to 'AllResourcesDoNotDelete', then the following actions are automatically appended to 'excludedActions': 'Microsoft.Authorization/locks/delete'. Duplicate actions will get removed. + ExcludedActions *[]string `json:"excludedActions,omitempty"` +} + +// AssignmentOperation represents underlying deployment detail for each update to the blueprint assignment. +type AssignmentOperation struct { + autorest.Response `json:"-"` + // AssignmentOperationProperties - Properties for AssignmentOperation. + *AssignmentOperationProperties `json:"properties,omitempty"` + // ID - READ-ONLY; String Id used to locate any resource on Azure. + ID *string `json:"id,omitempty"` + // Type - READ-ONLY; Type of this resource. + Type *string `json:"type,omitempty"` + // Name - READ-ONLY; Name of this resource. + Name *string `json:"name,omitempty"` +} + +// MarshalJSON is the custom marshaler for AssignmentOperation. +func (ao AssignmentOperation) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if ao.AssignmentOperationProperties != nil { + objectMap["properties"] = ao.AssignmentOperationProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for AssignmentOperation struct. +func (ao *AssignmentOperation) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "properties": + if v != nil { + var assignmentOperationProperties AssignmentOperationProperties + err = json.Unmarshal(*v, &assignmentOperationProperties) + if err != nil { + return err + } + ao.AssignmentOperationProperties = &assignmentOperationProperties + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + ao.ID = &ID + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + ao.Type = &typeVar + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + ao.Name = &name + } + } + } + + return nil +} + +// AssignmentOperationList list of AssignmentOperation. +type AssignmentOperationList struct { + autorest.Response `json:"-"` + // Value - List of AssignmentOperation. + Value *[]AssignmentOperation `json:"value,omitempty"` + // NextLink - READ-ONLY; Link to the next page of results. + NextLink *string `json:"nextLink,omitempty"` +} + +// AssignmentOperationListIterator provides access to a complete listing of AssignmentOperation values. +type AssignmentOperationListIterator struct { + i int + page AssignmentOperationListPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *AssignmentOperationListIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentOperationListIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *AssignmentOperationListIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter AssignmentOperationListIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter AssignmentOperationListIterator) Response() AssignmentOperationList { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter AssignmentOperationListIterator) Value() AssignmentOperation { + if !iter.page.NotDone() { + return AssignmentOperation{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the AssignmentOperationListIterator type. +func NewAssignmentOperationListIterator(page AssignmentOperationListPage) AssignmentOperationListIterator { + return AssignmentOperationListIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (aol AssignmentOperationList) IsEmpty() bool { + return aol.Value == nil || len(*aol.Value) == 0 +} + +// assignmentOperationListPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (aol AssignmentOperationList) assignmentOperationListPreparer(ctx context.Context) (*http.Request, error) { + if aol.NextLink == nil || len(to.String(aol.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(aol.NextLink))) +} + +// AssignmentOperationListPage contains a page of AssignmentOperation values. +type AssignmentOperationListPage struct { + fn func(context.Context, AssignmentOperationList) (AssignmentOperationList, error) + aol AssignmentOperationList +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *AssignmentOperationListPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentOperationListPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + next, err := page.fn(ctx, page.aol) + if err != nil { + return err + } + page.aol = next + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *AssignmentOperationListPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page AssignmentOperationListPage) NotDone() bool { + return !page.aol.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page AssignmentOperationListPage) Response() AssignmentOperationList { + return page.aol +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page AssignmentOperationListPage) Values() []AssignmentOperation { + if page.aol.IsEmpty() { + return nil + } + return *page.aol.Value +} + +// Creates a new instance of the AssignmentOperationListPage type. +func NewAssignmentOperationListPage(getNextPage func(context.Context, AssignmentOperationList) (AssignmentOperationList, error)) AssignmentOperationListPage { + return AssignmentOperationListPage{fn: getNextPage} +} + +// AssignmentOperationProperties properties of AssignmentOperation. +type AssignmentOperationProperties struct { + // BlueprintVersion - The published version of the blueprint definition used for the blueprint assignment operation. + BlueprintVersion *string `json:"blueprintVersion,omitempty"` + // AssignmentState - State of this blueprint assignment operation. + AssignmentState *string `json:"assignmentState,omitempty"` + // TimeCreated - Create time of this blueprint assignment operation. + TimeCreated *string `json:"timeCreated,omitempty"` + // TimeStarted - Start time of the underlying deployment. + TimeStarted *string `json:"timeStarted,omitempty"` + // TimeFinished - Finish time of the overall underlying deployments. + TimeFinished *string `json:"timeFinished,omitempty"` + // Deployments - List of jobs in this blueprint assignment operation. + Deployments *[]AssignmentDeploymentJob `json:"deployments,omitempty"` +} + +// AssignmentProperties detailed properties for a blueprint assignment. +type AssignmentProperties struct { + // BlueprintID - ID of the published version of a blueprint definition. + BlueprintID *string `json:"blueprintId,omitempty"` + // Scope - The target subscription scope of the blueprint assignment (format: '/subscriptions/{subscriptionId}'). For management group level assignments, the property is required. + Scope *string `json:"scope,omitempty"` + // Parameters - Blueprint assignment parameter values. + Parameters map[string]*ParameterValue `json:"parameters"` + // ResourceGroups - Names and locations of resource group placeholders. + ResourceGroups map[string]*ResourceGroupValue `json:"resourceGroups"` + // Status - READ-ONLY; Status of blueprint assignment. This field is readonly. + Status *AssignmentStatus `json:"status,omitempty"` + // Locks - Defines how resources deployed by a blueprint assignment are locked. + Locks *AssignmentLockSettings `json:"locks,omitempty"` + // ProvisioningState - READ-ONLY; State of the blueprint assignment. Possible values include: 'Creating', 'Validating', 'Waiting', 'Deploying', 'Cancelling', 'Locking', 'Succeeded', 'Failed', 'Canceled', 'Deleting' + ProvisioningState AssignmentProvisioningState `json:"provisioningState,omitempty"` + // DisplayName - One-liner string explain this resource. + DisplayName *string `json:"displayName,omitempty"` + // Description - Multi-line explain this resource. + Description *string `json:"description,omitempty"` +} + +// MarshalJSON is the custom marshaler for AssignmentProperties. +func (ap AssignmentProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if ap.BlueprintID != nil { + objectMap["blueprintId"] = ap.BlueprintID + } + if ap.Scope != nil { + objectMap["scope"] = ap.Scope + } + if ap.Parameters != nil { + objectMap["parameters"] = ap.Parameters + } + if ap.ResourceGroups != nil { + objectMap["resourceGroups"] = ap.ResourceGroups + } + if ap.Locks != nil { + objectMap["locks"] = ap.Locks + } + if ap.DisplayName != nil { + objectMap["displayName"] = ap.DisplayName + } + if ap.Description != nil { + objectMap["description"] = ap.Description + } + return json.Marshal(objectMap) +} + +// AssignmentStatus the status of a blueprint assignment. This field is readonly. +type AssignmentStatus struct { + // ManagedResources - READ-ONLY; List of resources that were created by the blueprint assignment. + ManagedResources *[]string `json:"managedResources,omitempty"` + // TimeCreated - READ-ONLY; Creation time of this blueprint definition. + TimeCreated *date.Time `json:"timeCreated,omitempty"` + // LastModified - READ-ONLY; Last modified time of this blueprint definition. + LastModified *date.Time `json:"lastModified,omitempty"` +} + +// AzureResourceBase common properties for all Azure resources. +type AzureResourceBase struct { + // ID - READ-ONLY; String Id used to locate any resource on Azure. + ID *string `json:"id,omitempty"` + // Type - READ-ONLY; Type of this resource. + Type *string `json:"type,omitempty"` + // Name - READ-ONLY; Name of this resource. + Name *string `json:"name,omitempty"` +} + +// AzureResourceManagerError error code and message +type AzureResourceManagerError struct { + // Code - Error code. + Code *string `json:"code,omitempty"` + // Message - Error message. + Message *string `json:"message,omitempty"` +} + +// KeyVaultReference specifies the link to a Key Vault. +type KeyVaultReference struct { + // ID - Azure resource ID of the Key Vault. + ID *string `json:"id,omitempty"` +} + +// List list of blueprint definitions. +type List struct { + autorest.Response `json:"-"` + // Value - List of blueprint definitions. + Value *[]Model `json:"value,omitempty"` + // NextLink - READ-ONLY; Link to the next page of results. + NextLink *string `json:"nextLink,omitempty"` +} + +// ListIterator provides access to a complete listing of Model values. +type ListIterator struct { + i int + page ListPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *ListIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ListIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *ListIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter ListIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter ListIterator) Response() List { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter ListIterator) Value() Model { + if !iter.page.NotDone() { + return Model{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the ListIterator type. +func NewListIterator(page ListPage) ListIterator { + return ListIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (l List) IsEmpty() bool { + return l.Value == nil || len(*l.Value) == 0 +} + +// listPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (l List) listPreparer(ctx context.Context) (*http.Request, error) { + if l.NextLink == nil || len(to.String(l.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(l.NextLink))) +} + +// ListPage contains a page of Model values. +type ListPage struct { + fn func(context.Context, List) (List, error) + l List +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *ListPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ListPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + next, err := page.fn(ctx, page.l) + if err != nil { + return err + } + page.l = next + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *ListPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page ListPage) NotDone() bool { + return !page.l.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page ListPage) Response() List { + return page.l +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page ListPage) Values() []Model { + if page.l.IsEmpty() { + return nil + } + return *page.l.Value +} + +// Creates a new instance of the ListPage type. +func NewListPage(getNextPage func(context.Context, List) (List, error)) ListPage { + return ListPage{fn: getNextPage} +} + +// ManagedServiceIdentity managed identity generic object. +type ManagedServiceIdentity struct { + // Type - Type of the managed identity. Possible values include: 'ManagedServiceIdentityTypeNone', 'ManagedServiceIdentityTypeSystemAssigned', 'ManagedServiceIdentityTypeUserAssigned' + Type ManagedServiceIdentityType `json:"type,omitempty"` + // PrincipalID - Azure Active Directory principal ID associated with this Identity. + PrincipalID *string `json:"principalId,omitempty"` + // TenantID - ID of the Azure Active Directory. + TenantID *string `json:"tenantId,omitempty"` + // UserAssignedIdentities - The list of user-assigned managed identities associated with the resource. Key is the Azure resource Id of the managed identity. + UserAssignedIdentities map[string]*UserAssignedIdentity `json:"userAssignedIdentities"` +} + +// MarshalJSON is the custom marshaler for ManagedServiceIdentity. +func (msi ManagedServiceIdentity) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if msi.Type != "" { + objectMap["type"] = msi.Type + } + if msi.PrincipalID != nil { + objectMap["principalId"] = msi.PrincipalID + } + if msi.TenantID != nil { + objectMap["tenantId"] = msi.TenantID + } + if msi.UserAssignedIdentities != nil { + objectMap["userAssignedIdentities"] = msi.UserAssignedIdentities + } + return json.Marshal(objectMap) +} + +// Model represents a Blueprint definition. +type Model struct { + autorest.Response `json:"-"` + // Properties - Detailed properties for blueprint definition. + *Properties `json:"properties,omitempty"` + // ID - READ-ONLY; String Id used to locate any resource on Azure. + ID *string `json:"id,omitempty"` + // Type - READ-ONLY; Type of this resource. + Type *string `json:"type,omitempty"` + // Name - READ-ONLY; Name of this resource. + Name *string `json:"name,omitempty"` +} + +// MarshalJSON is the custom marshaler for Model. +func (mVar Model) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if mVar.Properties != nil { + objectMap["properties"] = mVar.Properties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for Model struct. +func (mVar *Model) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "properties": + if v != nil { + var properties Properties + err = json.Unmarshal(*v, &properties) + if err != nil { + return err + } + mVar.Properties = &properties + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + mVar.ID = &ID + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + mVar.Type = &typeVar + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + mVar.Name = &name + } + } + } + + return nil +} + +// ParameterDefinition represent a parameter with constrains and metadata. +type ParameterDefinition struct { + // Type - Allowed data types for Resource Manager template parameters. Possible values include: 'String', 'Array', 'Bool', 'Int', 'Object', 'SecureObject', 'SecureString' + Type TemplateParameterType `json:"type,omitempty"` + // ParameterDefinitionMetadata - User-friendly properties for this parameter. + *ParameterDefinitionMetadata `json:"metadata,omitempty"` + // DefaultValue - Default Value for this parameter. + DefaultValue interface{} `json:"defaultValue,omitempty"` + // AllowedValues - Array of allowed values for this parameter. + AllowedValues *[]interface{} `json:"allowedValues,omitempty"` +} + +// MarshalJSON is the custom marshaler for ParameterDefinition. +func (pd ParameterDefinition) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if pd.Type != "" { + objectMap["type"] = pd.Type + } + if pd.ParameterDefinitionMetadata != nil { + objectMap["metadata"] = pd.ParameterDefinitionMetadata + } + if pd.DefaultValue != nil { + objectMap["defaultValue"] = pd.DefaultValue + } + if pd.AllowedValues != nil { + objectMap["allowedValues"] = pd.AllowedValues + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for ParameterDefinition struct. +func (pd *ParameterDefinition) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "type": + if v != nil { + var typeVar TemplateParameterType + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + pd.Type = typeVar + } + case "metadata": + if v != nil { + var parameterDefinitionMetadata ParameterDefinitionMetadata + err = json.Unmarshal(*v, ¶meterDefinitionMetadata) + if err != nil { + return err + } + pd.ParameterDefinitionMetadata = ¶meterDefinitionMetadata + } + case "defaultValue": + if v != nil { + var defaultValue interface{} + err = json.Unmarshal(*v, &defaultValue) + if err != nil { + return err + } + pd.DefaultValue = defaultValue + } + case "allowedValues": + if v != nil { + var allowedValues []interface{} + err = json.Unmarshal(*v, &allowedValues) + if err != nil { + return err + } + pd.AllowedValues = &allowedValues + } + } + } + + return nil +} + +// ParameterDefinitionMetadata user-friendly properties for this parameter. +type ParameterDefinitionMetadata struct { + // DisplayName - DisplayName of this parameter/resourceGroup. + DisplayName *string `json:"displayName,omitempty"` + // Description - Description of this parameter/resourceGroup. + Description *string `json:"description,omitempty"` + // StrongType - StrongType for UI to render rich experience during blueprint assignment. Supported strong types are resourceType, principalId and location. + StrongType *string `json:"strongType,omitempty"` +} + +// ParameterValue value for the specified parameter. Can be either 'value' or 'reference' but not both. +type ParameterValue struct { + // Value - Parameter value. Any valid JSON value is allowed including objects, arrays, strings, numbers and booleans. + Value interface{} `json:"value,omitempty"` + // Reference - Parameter value as reference type. + Reference *SecretValueReference `json:"reference,omitempty"` +} + +// PolicyAssignmentArtifact blueprint artifact that applies a Policy assignment. +type PolicyAssignmentArtifact struct { + // PolicyAssignmentArtifactProperties - properties for policyAssignment Artifact + *PolicyAssignmentArtifactProperties `json:"properties,omitempty"` + // Kind - Possible values include: 'KindArtifact', 'KindTemplate', 'KindRoleAssignment', 'KindPolicyAssignment' + Kind Kind `json:"kind,omitempty"` + // ID - READ-ONLY; String Id used to locate any resource on Azure. + ID *string `json:"id,omitempty"` + // Type - READ-ONLY; Type of this resource. + Type *string `json:"type,omitempty"` + // Name - READ-ONLY; Name of this resource. + Name *string `json:"name,omitempty"` +} + +// MarshalJSON is the custom marshaler for PolicyAssignmentArtifact. +func (paa PolicyAssignmentArtifact) MarshalJSON() ([]byte, error) { + paa.Kind = KindPolicyAssignment + objectMap := make(map[string]interface{}) + if paa.PolicyAssignmentArtifactProperties != nil { + objectMap["properties"] = paa.PolicyAssignmentArtifactProperties + } + if paa.Kind != "" { + objectMap["kind"] = paa.Kind + } + return json.Marshal(objectMap) +} + +// AsTemplateArtifact is the BasicArtifact implementation for PolicyAssignmentArtifact. +func (paa PolicyAssignmentArtifact) AsTemplateArtifact() (*TemplateArtifact, bool) { + return nil, false +} + +// AsRoleAssignmentArtifact is the BasicArtifact implementation for PolicyAssignmentArtifact. +func (paa PolicyAssignmentArtifact) AsRoleAssignmentArtifact() (*RoleAssignmentArtifact, bool) { + return nil, false +} + +// AsPolicyAssignmentArtifact is the BasicArtifact implementation for PolicyAssignmentArtifact. +func (paa PolicyAssignmentArtifact) AsPolicyAssignmentArtifact() (*PolicyAssignmentArtifact, bool) { + return &paa, true +} + +// AsArtifact is the BasicArtifact implementation for PolicyAssignmentArtifact. +func (paa PolicyAssignmentArtifact) AsArtifact() (*Artifact, bool) { + return nil, false +} + +// AsBasicArtifact is the BasicArtifact implementation for PolicyAssignmentArtifact. +func (paa PolicyAssignmentArtifact) AsBasicArtifact() (BasicArtifact, bool) { + return &paa, true +} + +// UnmarshalJSON is the custom unmarshaler for PolicyAssignmentArtifact struct. +func (paa *PolicyAssignmentArtifact) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "properties": + if v != nil { + var policyAssignmentArtifactProperties PolicyAssignmentArtifactProperties + err = json.Unmarshal(*v, &policyAssignmentArtifactProperties) + if err != nil { + return err + } + paa.PolicyAssignmentArtifactProperties = &policyAssignmentArtifactProperties + } + case "kind": + if v != nil { + var kind Kind + err = json.Unmarshal(*v, &kind) + if err != nil { + return err + } + paa.Kind = kind + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + paa.ID = &ID + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + paa.Type = &typeVar + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + paa.Name = &name + } + } + } + + return nil +} + +// PolicyAssignmentArtifactProperties properties of a Policy assignment blueprint artifact. +type PolicyAssignmentArtifactProperties struct { + // DisplayName - One-liner string explain this resource. + DisplayName *string `json:"displayName,omitempty"` + // Description - Multi-line explain this resource. + Description *string `json:"description,omitempty"` + // DependsOn - Artifacts which need to be deployed before the specified artifact. + DependsOn *[]string `json:"dependsOn,omitempty"` + // PolicyDefinitionID - Azure resource ID of the policy definition. + PolicyDefinitionID *string `json:"policyDefinitionId,omitempty"` + // Parameters - Parameter values for the policy definition. + Parameters map[string]*ParameterValue `json:"parameters"` + // ResourceGroup - Name of the resource group placeholder to which the policy will be assigned. + ResourceGroup *string `json:"resourceGroup,omitempty"` +} + +// MarshalJSON is the custom marshaler for PolicyAssignmentArtifactProperties. +func (paap PolicyAssignmentArtifactProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if paap.DisplayName != nil { + objectMap["displayName"] = paap.DisplayName + } + if paap.Description != nil { + objectMap["description"] = paap.Description + } + if paap.DependsOn != nil { + objectMap["dependsOn"] = paap.DependsOn + } + if paap.PolicyDefinitionID != nil { + objectMap["policyDefinitionId"] = paap.PolicyDefinitionID + } + if paap.Parameters != nil { + objectMap["parameters"] = paap.Parameters + } + if paap.ResourceGroup != nil { + objectMap["resourceGroup"] = paap.ResourceGroup + } + return json.Marshal(objectMap) +} + +// Properties schema for blueprint definition properties. +type Properties struct { + // Versions - Published versions of this blueprint definition. + Versions interface{} `json:"versions,omitempty"` + // Layout - Layout view of the blueprint definition for UI reference. + Layout interface{} `json:"layout,omitempty"` + // Status - READ-ONLY; Status of the blueprint. This field is readonly. + Status *Status `json:"status,omitempty"` + // TargetScope - The scope where this blueprint definition can be assigned. Possible values include: 'Subscription', 'ManagementGroup' + TargetScope TargetScope `json:"targetScope,omitempty"` + // Parameters - Parameters required by this blueprint definition. + Parameters map[string]*ParameterDefinition `json:"parameters"` + // ResourceGroups - Resource group placeholders defined by this blueprint definition. + ResourceGroups map[string]*ResourceGroupDefinition `json:"resourceGroups"` + // DisplayName - One-liner string explain this resource. + DisplayName *string `json:"displayName,omitempty"` + // Description - Multi-line explain this resource. + Description *string `json:"description,omitempty"` +} + +// MarshalJSON is the custom marshaler for Properties. +func (p Properties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if p.Versions != nil { + objectMap["versions"] = p.Versions + } + if p.Layout != nil { + objectMap["layout"] = p.Layout + } + if p.TargetScope != "" { + objectMap["targetScope"] = p.TargetScope + } + if p.Parameters != nil { + objectMap["parameters"] = p.Parameters + } + if p.ResourceGroups != nil { + objectMap["resourceGroups"] = p.ResourceGroups + } + if p.DisplayName != nil { + objectMap["displayName"] = p.DisplayName + } + if p.Description != nil { + objectMap["description"] = p.Description + } + return json.Marshal(objectMap) +} + +// PublishedBlueprint represents a published blueprint. +type PublishedBlueprint struct { + autorest.Response `json:"-"` + // PublishedBlueprintProperties - Detailed properties for published blueprint. + *PublishedBlueprintProperties `json:"properties,omitempty"` + // ID - READ-ONLY; String Id used to locate any resource on Azure. + ID *string `json:"id,omitempty"` + // Type - READ-ONLY; Type of this resource. + Type *string `json:"type,omitempty"` + // Name - READ-ONLY; Name of this resource. + Name *string `json:"name,omitempty"` +} + +// MarshalJSON is the custom marshaler for PublishedBlueprint. +func (pb PublishedBlueprint) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if pb.PublishedBlueprintProperties != nil { + objectMap["properties"] = pb.PublishedBlueprintProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for PublishedBlueprint struct. +func (pb *PublishedBlueprint) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "properties": + if v != nil { + var publishedBlueprintProperties PublishedBlueprintProperties + err = json.Unmarshal(*v, &publishedBlueprintProperties) + if err != nil { + return err + } + pb.PublishedBlueprintProperties = &publishedBlueprintProperties + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + pb.ID = &ID + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + pb.Type = &typeVar + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + pb.Name = &name + } + } + } + + return nil +} + +// PublishedBlueprintList list of published blueprint definitions. +type PublishedBlueprintList struct { + autorest.Response `json:"-"` + // Value - List of published blueprint definitions. + Value *[]PublishedBlueprint `json:"value,omitempty"` + // NextLink - READ-ONLY; Link to the next page of results. + NextLink *string `json:"nextLink,omitempty"` +} + +// PublishedBlueprintListIterator provides access to a complete listing of PublishedBlueprint values. +type PublishedBlueprintListIterator struct { + i int + page PublishedBlueprintListPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *PublishedBlueprintListIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PublishedBlueprintListIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *PublishedBlueprintListIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter PublishedBlueprintListIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter PublishedBlueprintListIterator) Response() PublishedBlueprintList { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter PublishedBlueprintListIterator) Value() PublishedBlueprint { + if !iter.page.NotDone() { + return PublishedBlueprint{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the PublishedBlueprintListIterator type. +func NewPublishedBlueprintListIterator(page PublishedBlueprintListPage) PublishedBlueprintListIterator { + return PublishedBlueprintListIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (pbl PublishedBlueprintList) IsEmpty() bool { + return pbl.Value == nil || len(*pbl.Value) == 0 +} + +// publishedBlueprintListPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (pbl PublishedBlueprintList) publishedBlueprintListPreparer(ctx context.Context) (*http.Request, error) { + if pbl.NextLink == nil || len(to.String(pbl.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(pbl.NextLink))) +} + +// PublishedBlueprintListPage contains a page of PublishedBlueprint values. +type PublishedBlueprintListPage struct { + fn func(context.Context, PublishedBlueprintList) (PublishedBlueprintList, error) + pbl PublishedBlueprintList +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *PublishedBlueprintListPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PublishedBlueprintListPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + next, err := page.fn(ctx, page.pbl) + if err != nil { + return err + } + page.pbl = next + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *PublishedBlueprintListPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page PublishedBlueprintListPage) NotDone() bool { + return !page.pbl.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page PublishedBlueprintListPage) Response() PublishedBlueprintList { + return page.pbl +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page PublishedBlueprintListPage) Values() []PublishedBlueprint { + if page.pbl.IsEmpty() { + return nil + } + return *page.pbl.Value +} + +// Creates a new instance of the PublishedBlueprintListPage type. +func NewPublishedBlueprintListPage(getNextPage func(context.Context, PublishedBlueprintList) (PublishedBlueprintList, error)) PublishedBlueprintListPage { + return PublishedBlueprintListPage{fn: getNextPage} +} + +// PublishedBlueprintProperties schema for published blueprint definition properties. +type PublishedBlueprintProperties struct { + // BlueprintName - Name of the published blueprint definition. + BlueprintName *string `json:"blueprintName,omitempty"` + // ChangeNotes - Version-specific change notes. + ChangeNotes *string `json:"changeNotes,omitempty"` + // Status - READ-ONLY; Status of the blueprint. This field is readonly. + Status *Status `json:"status,omitempty"` + // TargetScope - The scope where this blueprint definition can be assigned. Possible values include: 'Subscription', 'ManagementGroup' + TargetScope TargetScope `json:"targetScope,omitempty"` + // Parameters - Parameters required by this blueprint definition. + Parameters map[string]*ParameterDefinition `json:"parameters"` + // ResourceGroups - Resource group placeholders defined by this blueprint definition. + ResourceGroups map[string]*ResourceGroupDefinition `json:"resourceGroups"` + // DisplayName - One-liner string explain this resource. + DisplayName *string `json:"displayName,omitempty"` + // Description - Multi-line explain this resource. + Description *string `json:"description,omitempty"` +} + +// MarshalJSON is the custom marshaler for PublishedBlueprintProperties. +func (pbp PublishedBlueprintProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if pbp.BlueprintName != nil { + objectMap["blueprintName"] = pbp.BlueprintName + } + if pbp.ChangeNotes != nil { + objectMap["changeNotes"] = pbp.ChangeNotes + } + if pbp.TargetScope != "" { + objectMap["targetScope"] = pbp.TargetScope + } + if pbp.Parameters != nil { + objectMap["parameters"] = pbp.Parameters + } + if pbp.ResourceGroups != nil { + objectMap["resourceGroups"] = pbp.ResourceGroups + } + if pbp.DisplayName != nil { + objectMap["displayName"] = pbp.DisplayName + } + if pbp.Description != nil { + objectMap["description"] = pbp.Description + } + return json.Marshal(objectMap) +} + +// ResourceGroupDefinition represents an Azure resource group in a blueprint definition. +type ResourceGroupDefinition struct { + // Name - Name of this resourceGroup. Leave empty if the resource group name will be specified during the blueprint assignment. + Name *string `json:"name,omitempty"` + // Location - Location of this resourceGroup. Leave empty if the resource group location will be specified during the blueprint assignment. + Location *string `json:"location,omitempty"` + // ParameterDefinitionMetadata - User-friendly properties for this resource group. + *ParameterDefinitionMetadata `json:"metadata,omitempty"` + // DependsOn - Artifacts which need to be deployed before this resource group. + DependsOn *[]string `json:"dependsOn,omitempty"` + // Tags - Tags to be assigned to this resource group. + Tags map[string]*string `json:"tags"` +} + +// MarshalJSON is the custom marshaler for ResourceGroupDefinition. +func (rgd ResourceGroupDefinition) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if rgd.Name != nil { + objectMap["name"] = rgd.Name + } + if rgd.Location != nil { + objectMap["location"] = rgd.Location + } + if rgd.ParameterDefinitionMetadata != nil { + objectMap["metadata"] = rgd.ParameterDefinitionMetadata + } + if rgd.DependsOn != nil { + objectMap["dependsOn"] = rgd.DependsOn + } + if rgd.Tags != nil { + objectMap["tags"] = rgd.Tags + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for ResourceGroupDefinition struct. +func (rgd *ResourceGroupDefinition) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + rgd.Name = &name + } + case "location": + if v != nil { + var location string + err = json.Unmarshal(*v, &location) + if err != nil { + return err + } + rgd.Location = &location + } + case "metadata": + if v != nil { + var parameterDefinitionMetadata ParameterDefinitionMetadata + err = json.Unmarshal(*v, ¶meterDefinitionMetadata) + if err != nil { + return err + } + rgd.ParameterDefinitionMetadata = ¶meterDefinitionMetadata + } + case "dependsOn": + if v != nil { + var dependsOn []string + err = json.Unmarshal(*v, &dependsOn) + if err != nil { + return err + } + rgd.DependsOn = &dependsOn + } + case "tags": + if v != nil { + var tags map[string]*string + err = json.Unmarshal(*v, &tags) + if err != nil { + return err + } + rgd.Tags = tags + } + } + } + + return nil +} + +// ResourceGroupValue represents an Azure resource group. +type ResourceGroupValue struct { + // Name - Name of the resource group. + Name *string `json:"name,omitempty"` + // Location - Location of the resource group. + Location *string `json:"location,omitempty"` +} + +// ResourcePropertiesBase shared properties between all blueprint resources. +type ResourcePropertiesBase struct { + // DisplayName - One-liner string explain this resource. + DisplayName *string `json:"displayName,omitempty"` + // Description - Multi-line explain this resource. + Description *string `json:"description,omitempty"` +} + +// ResourceProviderOperation supported operations of this resource provider. +type ResourceProviderOperation struct { + // Name - Operation name, in format of {provider}/{resource}/{operation} + Name *string `json:"name,omitempty"` + // Display - Display metadata associated with the operation. + Display *ResourceProviderOperationDisplay `json:"display,omitempty"` +} + +// ResourceProviderOperationDisplay display metadata associated with the operation. +type ResourceProviderOperationDisplay struct { + // Provider - Resource provider: Microsoft Blueprint. + Provider *string `json:"provider,omitempty"` + // Resource - Resource on which the operation is performed. + Resource *string `json:"resource,omitempty"` + // Operation - Type of operation: get, read, delete, etc. + Operation *string `json:"operation,omitempty"` + // Description - Description of this operation. + Description *string `json:"description,omitempty"` +} + +// ResourceProviderOperationList results of the request to list operations. +type ResourceProviderOperationList struct { + // Value - List of operations supported by this resource provider. + Value *[]ResourceProviderOperation `json:"value,omitempty"` +} + +// ResourceStatusBase shared status properties between all blueprint resources. +type ResourceStatusBase struct { + // TimeCreated - READ-ONLY; Creation time of this blueprint definition. + TimeCreated *date.Time `json:"timeCreated,omitempty"` + // LastModified - READ-ONLY; Last modified time of this blueprint definition. + LastModified *date.Time `json:"lastModified,omitempty"` +} + +// RoleAssignmentArtifact blueprint artifact that applies a Role assignment. +type RoleAssignmentArtifact struct { + // RoleAssignmentArtifactProperties - Properties for a Role assignment blueprint artifact. + *RoleAssignmentArtifactProperties `json:"properties,omitempty"` + // Kind - Possible values include: 'KindArtifact', 'KindTemplate', 'KindRoleAssignment', 'KindPolicyAssignment' + Kind Kind `json:"kind,omitempty"` + // ID - READ-ONLY; String Id used to locate any resource on Azure. + ID *string `json:"id,omitempty"` + // Type - READ-ONLY; Type of this resource. + Type *string `json:"type,omitempty"` + // Name - READ-ONLY; Name of this resource. + Name *string `json:"name,omitempty"` +} + +// MarshalJSON is the custom marshaler for RoleAssignmentArtifact. +func (raa RoleAssignmentArtifact) MarshalJSON() ([]byte, error) { + raa.Kind = KindRoleAssignment + objectMap := make(map[string]interface{}) + if raa.RoleAssignmentArtifactProperties != nil { + objectMap["properties"] = raa.RoleAssignmentArtifactProperties + } + if raa.Kind != "" { + objectMap["kind"] = raa.Kind + } + return json.Marshal(objectMap) +} + +// AsTemplateArtifact is the BasicArtifact implementation for RoleAssignmentArtifact. +func (raa RoleAssignmentArtifact) AsTemplateArtifact() (*TemplateArtifact, bool) { + return nil, false +} + +// AsRoleAssignmentArtifact is the BasicArtifact implementation for RoleAssignmentArtifact. +func (raa RoleAssignmentArtifact) AsRoleAssignmentArtifact() (*RoleAssignmentArtifact, bool) { + return &raa, true +} + +// AsPolicyAssignmentArtifact is the BasicArtifact implementation for RoleAssignmentArtifact. +func (raa RoleAssignmentArtifact) AsPolicyAssignmentArtifact() (*PolicyAssignmentArtifact, bool) { + return nil, false +} + +// AsArtifact is the BasicArtifact implementation for RoleAssignmentArtifact. +func (raa RoleAssignmentArtifact) AsArtifact() (*Artifact, bool) { + return nil, false +} + +// AsBasicArtifact is the BasicArtifact implementation for RoleAssignmentArtifact. +func (raa RoleAssignmentArtifact) AsBasicArtifact() (BasicArtifact, bool) { + return &raa, true +} + +// UnmarshalJSON is the custom unmarshaler for RoleAssignmentArtifact struct. +func (raa *RoleAssignmentArtifact) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "properties": + if v != nil { + var roleAssignmentArtifactProperties RoleAssignmentArtifactProperties + err = json.Unmarshal(*v, &roleAssignmentArtifactProperties) + if err != nil { + return err + } + raa.RoleAssignmentArtifactProperties = &roleAssignmentArtifactProperties + } + case "kind": + if v != nil { + var kind Kind + err = json.Unmarshal(*v, &kind) + if err != nil { + return err + } + raa.Kind = kind + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + raa.ID = &ID + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + raa.Type = &typeVar + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + raa.Name = &name + } + } + } + + return nil +} + +// RoleAssignmentArtifactProperties properties of a Role assignment blueprint artifact. +type RoleAssignmentArtifactProperties struct { + // DisplayName - One-liner string explain this resource. + DisplayName *string `json:"displayName,omitempty"` + // Description - Multi-line explain this resource. + Description *string `json:"description,omitempty"` + // DependsOn - Artifacts which need to be deployed before the specified artifact. + DependsOn *[]string `json:"dependsOn,omitempty"` + // RoleDefinitionID - Azure resource ID of the RoleDefinition. + RoleDefinitionID *string `json:"roleDefinitionId,omitempty"` + // PrincipalIds - Array of user or group identities in Azure Active Directory. The roleDefinition will apply to each identity. + PrincipalIds interface{} `json:"principalIds,omitempty"` + // ResourceGroup - RoleAssignment will be scope to this resourceGroup. If empty, it scopes to the subscription. + ResourceGroup *string `json:"resourceGroup,omitempty"` +} + +// SecretValueReference reference to a Key Vault secret. +type SecretValueReference struct { + // KeyVault - Specifies the reference to a given Azure Key Vault. + KeyVault *KeyVaultReference `json:"keyVault,omitempty"` + // SecretName - Name of the secret. + SecretName *string `json:"secretName,omitempty"` + // SecretVersion - The version of the secret to use. If left blank, the latest version of the secret is used. + SecretVersion *string `json:"secretVersion,omitempty"` +} + +// SharedBlueprintProperties shared Schema for both blueprintProperties and publishedBlueprintProperties. +type SharedBlueprintProperties struct { + // Status - READ-ONLY; Status of the blueprint. This field is readonly. + Status *Status `json:"status,omitempty"` + // TargetScope - The scope where this blueprint definition can be assigned. Possible values include: 'Subscription', 'ManagementGroup' + TargetScope TargetScope `json:"targetScope,omitempty"` + // Parameters - Parameters required by this blueprint definition. + Parameters map[string]*ParameterDefinition `json:"parameters"` + // ResourceGroups - Resource group placeholders defined by this blueprint definition. + ResourceGroups map[string]*ResourceGroupDefinition `json:"resourceGroups"` + // DisplayName - One-liner string explain this resource. + DisplayName *string `json:"displayName,omitempty"` + // Description - Multi-line explain this resource. + Description *string `json:"description,omitempty"` +} + +// MarshalJSON is the custom marshaler for SharedBlueprintProperties. +func (sbp SharedBlueprintProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if sbp.TargetScope != "" { + objectMap["targetScope"] = sbp.TargetScope + } + if sbp.Parameters != nil { + objectMap["parameters"] = sbp.Parameters + } + if sbp.ResourceGroups != nil { + objectMap["resourceGroups"] = sbp.ResourceGroups + } + if sbp.DisplayName != nil { + objectMap["displayName"] = sbp.DisplayName + } + if sbp.Description != nil { + objectMap["description"] = sbp.Description + } + return json.Marshal(objectMap) +} + +// Status the status of the blueprint. This field is readonly. +type Status struct { + // TimeCreated - READ-ONLY; Creation time of this blueprint definition. + TimeCreated *date.Time `json:"timeCreated,omitempty"` + // LastModified - READ-ONLY; Last modified time of this blueprint definition. + LastModified *date.Time `json:"lastModified,omitempty"` +} + +// TemplateArtifact blueprint artifact that deploys a Resource Manager template. +type TemplateArtifact struct { + // TemplateArtifactProperties - Properties for a Resource Manager template blueprint artifact. + *TemplateArtifactProperties `json:"properties,omitempty"` + // Kind - Possible values include: 'KindArtifact', 'KindTemplate', 'KindRoleAssignment', 'KindPolicyAssignment' + Kind Kind `json:"kind,omitempty"` + // ID - READ-ONLY; String Id used to locate any resource on Azure. + ID *string `json:"id,omitempty"` + // Type - READ-ONLY; Type of this resource. + Type *string `json:"type,omitempty"` + // Name - READ-ONLY; Name of this resource. + Name *string `json:"name,omitempty"` +} + +// MarshalJSON is the custom marshaler for TemplateArtifact. +func (ta TemplateArtifact) MarshalJSON() ([]byte, error) { + ta.Kind = KindTemplate + objectMap := make(map[string]interface{}) + if ta.TemplateArtifactProperties != nil { + objectMap["properties"] = ta.TemplateArtifactProperties + } + if ta.Kind != "" { + objectMap["kind"] = ta.Kind + } + return json.Marshal(objectMap) +} + +// AsTemplateArtifact is the BasicArtifact implementation for TemplateArtifact. +func (ta TemplateArtifact) AsTemplateArtifact() (*TemplateArtifact, bool) { + return &ta, true +} + +// AsRoleAssignmentArtifact is the BasicArtifact implementation for TemplateArtifact. +func (ta TemplateArtifact) AsRoleAssignmentArtifact() (*RoleAssignmentArtifact, bool) { + return nil, false +} + +// AsPolicyAssignmentArtifact is the BasicArtifact implementation for TemplateArtifact. +func (ta TemplateArtifact) AsPolicyAssignmentArtifact() (*PolicyAssignmentArtifact, bool) { + return nil, false +} + +// AsArtifact is the BasicArtifact implementation for TemplateArtifact. +func (ta TemplateArtifact) AsArtifact() (*Artifact, bool) { + return nil, false +} + +// AsBasicArtifact is the BasicArtifact implementation for TemplateArtifact. +func (ta TemplateArtifact) AsBasicArtifact() (BasicArtifact, bool) { + return &ta, true +} + +// UnmarshalJSON is the custom unmarshaler for TemplateArtifact struct. +func (ta *TemplateArtifact) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "properties": + if v != nil { + var templateArtifactProperties TemplateArtifactProperties + err = json.Unmarshal(*v, &templateArtifactProperties) + if err != nil { + return err + } + ta.TemplateArtifactProperties = &templateArtifactProperties + } + case "kind": + if v != nil { + var kind Kind + err = json.Unmarshal(*v, &kind) + if err != nil { + return err + } + ta.Kind = kind + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + ta.ID = &ID + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + ta.Type = &typeVar + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + ta.Name = &name + } + } + } + + return nil +} + +// TemplateArtifactProperties properties of a Resource Manager template blueprint artifact. +type TemplateArtifactProperties struct { + // DisplayName - One-liner string explain this resource. + DisplayName *string `json:"displayName,omitempty"` + // Description - Multi-line explain this resource. + Description *string `json:"description,omitempty"` + // DependsOn - Artifacts which need to be deployed before the specified artifact. + DependsOn *[]string `json:"dependsOn,omitempty"` + // Template - The Resource Manager template blueprint artifact body. + Template interface{} `json:"template,omitempty"` + // ResourceGroup - If applicable, the name of the resource group placeholder to which the Resource Manager template blueprint artifact will be deployed. + ResourceGroup *string `json:"resourceGroup,omitempty"` + // Parameters - Resource Manager template blueprint artifact parameter values. + Parameters map[string]*ParameterValue `json:"parameters"` +} + +// MarshalJSON is the custom marshaler for TemplateArtifactProperties. +func (tap TemplateArtifactProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if tap.DisplayName != nil { + objectMap["displayName"] = tap.DisplayName + } + if tap.Description != nil { + objectMap["description"] = tap.Description + } + if tap.DependsOn != nil { + objectMap["dependsOn"] = tap.DependsOn + } + if tap.Template != nil { + objectMap["template"] = tap.Template + } + if tap.ResourceGroup != nil { + objectMap["resourceGroup"] = tap.ResourceGroup + } + if tap.Parameters != nil { + objectMap["parameters"] = tap.Parameters + } + return json.Marshal(objectMap) +} + +// TrackedResource common properties for all Azure tracked resources. +type TrackedResource struct { + // Location - The location of this blueprint assignment. + Location *string `json:"location,omitempty"` + // ID - READ-ONLY; String Id used to locate any resource on Azure. + ID *string `json:"id,omitempty"` + // Type - READ-ONLY; Type of this resource. + Type *string `json:"type,omitempty"` + // Name - READ-ONLY; Name of this resource. + Name *string `json:"name,omitempty"` +} + +// UserAssignedIdentity user-assigned managed identity. +type UserAssignedIdentity struct { + // PrincipalID - Azure Active Directory principal ID associated with this Identity. + PrincipalID *string `json:"principalId,omitempty"` + // ClientID - Client App Id associated with this identity. + ClientID *string `json:"clientId,omitempty"` +} + +// WhoIsBlueprintContract response schema for querying the Azure Blueprints service principal in the +// tenant. +type WhoIsBlueprintContract struct { + autorest.Response `json:"-"` + // ObjectID - AAD object Id of the Azure Blueprints service principal in the tenant. + ObjectID *string `json:"objectId,omitempty"` +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/publishedartifacts.go b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/publishedartifacts.go new file mode 100644 index 000000000000..4f93ed064ec2 --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/publishedartifacts.go @@ -0,0 +1,241 @@ +package blueprint + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// PublishedArtifactsClient is the blueprint Client +type PublishedArtifactsClient struct { + BaseClient +} + +// NewPublishedArtifactsClient creates an instance of the PublishedArtifactsClient client. +func NewPublishedArtifactsClient() PublishedArtifactsClient { + return NewPublishedArtifactsClientWithBaseURI(DefaultBaseURI) +} + +// NewPublishedArtifactsClientWithBaseURI creates an instance of the PublishedArtifactsClient client using a custom +// endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure +// stack). +func NewPublishedArtifactsClientWithBaseURI(baseURI string) PublishedArtifactsClient { + return PublishedArtifactsClient{NewWithBaseURI(baseURI)} +} + +// Get get an artifact for a published blueprint definition. +// Parameters: +// resourceScope - the scope of the resource. Valid scopes are: management group (format: +// '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: +// '/subscriptions/{subscriptionId}'). +// blueprintName - name of the blueprint definition. +// versionID - version of the published blueprint definition. +// artifactName - name of the blueprint artifact. +func (client PublishedArtifactsClient) Get(ctx context.Context, resourceScope string, blueprintName string, versionID string, artifactName string) (result ArtifactModel, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PublishedArtifactsClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetPreparer(ctx, resourceScope, blueprintName, versionID, artifactName) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.PublishedArtifactsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "blueprint.PublishedArtifactsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.PublishedArtifactsClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client PublishedArtifactsClient) GetPreparer(ctx context.Context, resourceScope string, blueprintName string, versionID string, artifactName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "artifactName": autorest.Encode("path", artifactName), + "blueprintName": autorest.Encode("path", blueprintName), + "resourceScope": resourceScope, + "versionId": autorest.Encode("path", versionID), + } + + const APIVersion = "2018-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceScope}/providers/Microsoft.Blueprint/blueprints/{blueprintName}/versions/{versionId}/artifacts/{artifactName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client PublishedArtifactsClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client PublishedArtifactsClient) GetResponder(resp *http.Response) (result ArtifactModel, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List list artifacts for a version of a published blueprint definition. +// Parameters: +// resourceScope - the scope of the resource. Valid scopes are: management group (format: +// '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: +// '/subscriptions/{subscriptionId}'). +// blueprintName - name of the blueprint definition. +// versionID - version of the published blueprint definition. +func (client PublishedArtifactsClient) List(ctx context.Context, resourceScope string, blueprintName string, versionID string) (result ArtifactListPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PublishedArtifactsClient.List") + defer func() { + sc := -1 + if result.al.Response.Response != nil { + sc = result.al.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, resourceScope, blueprintName, versionID) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.PublishedArtifactsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.al.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "blueprint.PublishedArtifactsClient", "List", resp, "Failure sending request") + return + } + + result.al, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.PublishedArtifactsClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client PublishedArtifactsClient) ListPreparer(ctx context.Context, resourceScope string, blueprintName string, versionID string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "blueprintName": autorest.Encode("path", blueprintName), + "resourceScope": resourceScope, + "versionId": autorest.Encode("path", versionID), + } + + const APIVersion = "2018-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceScope}/providers/Microsoft.Blueprint/blueprints/{blueprintName}/versions/{versionId}/artifacts", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client PublishedArtifactsClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client PublishedArtifactsClient) ListResponder(resp *http.Response) (result ArtifactList, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client PublishedArtifactsClient) listNextResults(ctx context.Context, lastResults ArtifactList) (result ArtifactList, err error) { + req, err := lastResults.artifactListPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "blueprint.PublishedArtifactsClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "blueprint.PublishedArtifactsClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.PublishedArtifactsClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client PublishedArtifactsClient) ListComplete(ctx context.Context, resourceScope string, blueprintName string, versionID string) (result ArtifactListIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PublishedArtifactsClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx, resourceScope, blueprintName, versionID) + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/publishedblueprints.go b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/publishedblueprints.go new file mode 100644 index 000000000000..a6402d647eec --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/publishedblueprints.go @@ -0,0 +1,414 @@ +package blueprint + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// PublishedBlueprintsClient is the blueprint Client +type PublishedBlueprintsClient struct { + BaseClient +} + +// NewPublishedBlueprintsClient creates an instance of the PublishedBlueprintsClient client. +func NewPublishedBlueprintsClient() PublishedBlueprintsClient { + return NewPublishedBlueprintsClientWithBaseURI(DefaultBaseURI) +} + +// NewPublishedBlueprintsClientWithBaseURI creates an instance of the PublishedBlueprintsClient client using a custom +// endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure +// stack). +func NewPublishedBlueprintsClientWithBaseURI(baseURI string) PublishedBlueprintsClient { + return PublishedBlueprintsClient{NewWithBaseURI(baseURI)} +} + +// Create publish a new version of the blueprint definition with the latest artifacts. Published blueprint definitions +// are immutable. +// Parameters: +// resourceScope - the scope of the resource. Valid scopes are: management group (format: +// '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: +// '/subscriptions/{subscriptionId}'). +// blueprintName - name of the blueprint definition. +// versionID - version of the published blueprint definition. +// publishedBlueprint - published Blueprint to create or update. +func (client PublishedBlueprintsClient) Create(ctx context.Context, resourceScope string, blueprintName string, versionID string, publishedBlueprint *PublishedBlueprint) (result PublishedBlueprint, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PublishedBlueprintsClient.Create") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: publishedBlueprint, + Constraints: []validation.Constraint{{Target: "publishedBlueprint", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "publishedBlueprint.PublishedBlueprintProperties", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "publishedBlueprint.PublishedBlueprintProperties.ChangeNotes", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "publishedBlueprint.PublishedBlueprintProperties.ChangeNotes", Name: validation.MaxLength, Rule: 500, Chain: nil}}}, + }}, + }}}}}); err != nil { + return result, validation.NewError("blueprint.PublishedBlueprintsClient", "Create", err.Error()) + } + + req, err := client.CreatePreparer(ctx, resourceScope, blueprintName, versionID, publishedBlueprint) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.PublishedBlueprintsClient", "Create", nil, "Failure preparing request") + return + } + + resp, err := client.CreateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "blueprint.PublishedBlueprintsClient", "Create", resp, "Failure sending request") + return + } + + result, err = client.CreateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.PublishedBlueprintsClient", "Create", resp, "Failure responding to request") + } + + return +} + +// CreatePreparer prepares the Create request. +func (client PublishedBlueprintsClient) CreatePreparer(ctx context.Context, resourceScope string, blueprintName string, versionID string, publishedBlueprint *PublishedBlueprint) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "blueprintName": autorest.Encode("path", blueprintName), + "resourceScope": resourceScope, + "versionId": autorest.Encode("path", versionID), + } + + const APIVersion = "2018-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceScope}/providers/Microsoft.Blueprint/blueprints/{blueprintName}/versions/{versionId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + if publishedBlueprint != nil { + preparer = autorest.DecoratePreparer(preparer, + autorest.WithJSON(publishedBlueprint)) + } + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateSender sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (client PublishedBlueprintsClient) CreateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CreateResponder handles the response to the Create request. The method always +// closes the http.Response Body. +func (client PublishedBlueprintsClient) CreateResponder(resp *http.Response) (result PublishedBlueprint, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete delete a published version of a blueprint definition. +// Parameters: +// resourceScope - the scope of the resource. Valid scopes are: management group (format: +// '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: +// '/subscriptions/{subscriptionId}'). +// blueprintName - name of the blueprint definition. +// versionID - version of the published blueprint definition. +func (client PublishedBlueprintsClient) Delete(ctx context.Context, resourceScope string, blueprintName string, versionID string) (result PublishedBlueprint, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PublishedBlueprintsClient.Delete") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.DeletePreparer(ctx, resourceScope, blueprintName, versionID) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.PublishedBlueprintsClient", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "blueprint.PublishedBlueprintsClient", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.PublishedBlueprintsClient", "Delete", resp, "Failure responding to request") + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client PublishedBlueprintsClient) DeletePreparer(ctx context.Context, resourceScope string, blueprintName string, versionID string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "blueprintName": autorest.Encode("path", blueprintName), + "resourceScope": resourceScope, + "versionId": autorest.Encode("path", versionID), + } + + const APIVersion = "2018-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceScope}/providers/Microsoft.Blueprint/blueprints/{blueprintName}/versions/{versionId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client PublishedBlueprintsClient) DeleteSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client PublishedBlueprintsClient) DeleteResponder(resp *http.Response) (result PublishedBlueprint, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Get get a published version of a blueprint definition. +// Parameters: +// resourceScope - the scope of the resource. Valid scopes are: management group (format: +// '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: +// '/subscriptions/{subscriptionId}'). +// blueprintName - name of the blueprint definition. +// versionID - version of the published blueprint definition. +func (client PublishedBlueprintsClient) Get(ctx context.Context, resourceScope string, blueprintName string, versionID string) (result PublishedBlueprint, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PublishedBlueprintsClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetPreparer(ctx, resourceScope, blueprintName, versionID) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.PublishedBlueprintsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "blueprint.PublishedBlueprintsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.PublishedBlueprintsClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client PublishedBlueprintsClient) GetPreparer(ctx context.Context, resourceScope string, blueprintName string, versionID string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "blueprintName": autorest.Encode("path", blueprintName), + "resourceScope": resourceScope, + "versionId": autorest.Encode("path", versionID), + } + + const APIVersion = "2018-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceScope}/providers/Microsoft.Blueprint/blueprints/{blueprintName}/versions/{versionId}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client PublishedBlueprintsClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client PublishedBlueprintsClient) GetResponder(resp *http.Response) (result PublishedBlueprint, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List list published versions of given blueprint definition. +// Parameters: +// resourceScope - the scope of the resource. Valid scopes are: management group (format: +// '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format: +// '/subscriptions/{subscriptionId}'). +// blueprintName - name of the blueprint definition. +func (client PublishedBlueprintsClient) List(ctx context.Context, resourceScope string, blueprintName string) (result PublishedBlueprintListPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PublishedBlueprintsClient.List") + defer func() { + sc := -1 + if result.pbl.Response.Response != nil { + sc = result.pbl.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, resourceScope, blueprintName) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.PublishedBlueprintsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.pbl.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "blueprint.PublishedBlueprintsClient", "List", resp, "Failure sending request") + return + } + + result.pbl, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.PublishedBlueprintsClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client PublishedBlueprintsClient) ListPreparer(ctx context.Context, resourceScope string, blueprintName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "blueprintName": autorest.Encode("path", blueprintName), + "resourceScope": resourceScope, + } + + const APIVersion = "2018-11-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceScope}/providers/Microsoft.Blueprint/blueprints/{blueprintName}/versions", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client PublishedBlueprintsClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client PublishedBlueprintsClient) ListResponder(resp *http.Response) (result PublishedBlueprintList, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client PublishedBlueprintsClient) listNextResults(ctx context.Context, lastResults PublishedBlueprintList) (result PublishedBlueprintList, err error) { + req, err := lastResults.publishedBlueprintListPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "blueprint.PublishedBlueprintsClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "blueprint.PublishedBlueprintsClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "blueprint.PublishedBlueprintsClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client PublishedBlueprintsClient) ListComplete(ctx context.Context, resourceScope string, blueprintName string) (result PublishedBlueprintListIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PublishedBlueprintsClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx, resourceScope, blueprintName) + return +} diff --git a/vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/version.go b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/version.go new file mode 100644 index 000000000000..f741ba4ddfcb --- /dev/null +++ b/vendor/github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint/version.go @@ -0,0 +1,30 @@ +package blueprint + +import "github.com/Azure/azure-sdk-for-go/version" + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +// UserAgent returns the UserAgent string to use when sending http.Requests. +func UserAgent() string { + return "Azure-SDK-For-Go/" + version.Number + " blueprint/2018-11-01-preview" +} + +// Version returns the semantic version (see http://semver.org) of the client. +func Version() string { + return version.Number +} diff --git a/vendor/modules.txt b/vendor/modules.txt index aedbbe98efe2..04bfbe009c71 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -56,6 +56,7 @@ github.com/Azure/azure-sdk-for-go/services/postgresql/mgmt/2017-12-01/postgresql github.com/Azure/azure-sdk-for-go/services/powerbidedicated/mgmt/2017-10-01/powerbidedicated github.com/Azure/azure-sdk-for-go/services/preview/appplatform/mgmt/2019-05-01-preview/appplatform github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2018-09-01-preview/authorization +github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint github.com/Azure/azure-sdk-for-go/services/preview/botservice/mgmt/2018-07-12/botservice github.com/Azure/azure-sdk-for-go/services/preview/customproviders/mgmt/2018-09-01-preview/customproviders github.com/Azure/azure-sdk-for-go/services/preview/eventgrid/mgmt/2020-04-01-preview/eventgrid diff --git a/website/allowed-subcategories b/website/allowed-subcategories index 3846653eef4d..6a21840f4688 100644 --- a/website/allowed-subcategories +++ b/website/allowed-subcategories @@ -8,6 +8,7 @@ Authorization Automation Base Batch +Blueprints Bot CDN Cognitive Services From 99200f4037a9cdbb7461bc40ddebb48642ffbc31 Mon Sep 17 00:00:00 2001 From: jackofallops Date: Thu, 23 Apr 2020 09:15:49 +0100 Subject: [PATCH 02/26] commit for testing --- azurerm/helpers/azure/identity.go | 34 +++ .../internal/services/blueprints/blueprint.go | 109 ++++++++ .../blueprint_assignment_resource.go | 263 +++++++++++++++++- .../blueprint_definition_datasource.go | 122 +++++++- .../services/blueprints/client/client.go | 5 + .../blueprints/parse/blueprint_assignment.go | 8 +- .../parse/blueprint_assignment_test.go | 8 +- .../blueprints/parse/blueprint_definition.go | 59 ++++ .../blueprints/parse/blueprint_version.go | 10 +- .../parse/blueprint_version_test.go | 12 +- .../services/blueprints/validate/blueprint.go | 21 ++ .../blueprints/validate/blueprint_version.go | 21 ++ .../services/blueprints/validate/identity.go | 21 ++ 13 files changed, 668 insertions(+), 25 deletions(-) create mode 100644 azurerm/helpers/azure/identity.go create mode 100644 azurerm/internal/services/blueprints/blueprint.go create mode 100644 azurerm/internal/services/blueprints/parse/blueprint_definition.go create mode 100644 azurerm/internal/services/blueprints/validate/blueprint.go create mode 100644 azurerm/internal/services/blueprints/validate/blueprint_version.go create mode 100644 azurerm/internal/services/blueprints/validate/identity.go diff --git a/azurerm/helpers/azure/identity.go b/azurerm/helpers/azure/identity.go new file mode 100644 index 000000000000..bc878ad61021 --- /dev/null +++ b/azurerm/helpers/azure/identity.go @@ -0,0 +1,34 @@ +package azure + +import "fmt" + +type UserAssignedIdentityId struct { + // "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/contoso-resource-group/providers/Microsoft.ManagedIdentity/userAssignedIdentities/contoso-identity" + Subscription string + ResourceGroup string + Name string +} + +func ParseUserAssignedIdentityID(input string) (*UserAssignedIdentityId, error) { + if len(input) == 0 { + return nil, fmt.Errorf("Bad: UserAssignedIdentityId cannot be an empty string") + } + + id, err := ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + userAssignedIdentityId := UserAssignedIdentityId{ + Subscription: id.SubscriptionID, + ResourceGroup: id.ResourceGroup, + } + + if name, err := id.PopSegment("userAssignedIdentities"); err != nil { + return nil, fmt.Errorf("Bad: missing userAssignedIdentities segment in ID (%q)", input) + } else { + userAssignedIdentityId.Name = name + } + + return &userAssignedIdentityId, nil +} diff --git a/azurerm/internal/services/blueprints/blueprint.go b/azurerm/internal/services/blueprints/blueprint.go new file mode 100644 index 000000000000..1eb4c12cbc43 --- /dev/null +++ b/azurerm/internal/services/blueprints/blueprint.go @@ -0,0 +1,109 @@ +package blueprints + +import ( + "context" + "encoding/json" + "fmt" + "github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/blueprints/validate" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func ManagedIdentitySchema() *schema.Schema { + return &schema.Schema{ + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "type": { + Type: schema.TypeString, + Required: true, + Default: string(blueprint.ManagedServiceIdentityTypeSystemAssigned), + ValidateFunc: validation.StringInSlice([]string{ + // ManagedServiceIdentityTypeNone is not valid; a valid and privileged Identity is required for the service to apply the changes. + string(blueprint.ManagedServiceIdentityTypeUserAssigned), + string(blueprint.ManagedServiceIdentityTypeSystemAssigned), + }, false), + }, + + "user_assigned_identities": { + // The API only seems to care about the "key" portion of this struct, which is the ResourceID of the Identity + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validate.UserAssignedIdentityId, + }, + }, + + "principal_id": { + Type: schema.TypeString, + Computed: true, + }, + + "tenant_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + } +} + +func blueprintAssignmentCreateStateRefreshFunc(ctx context.Context, client *blueprint.AssignmentsClient, scope, name string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + resp, err := client.Get(ctx, scope, name) + if err != nil { + return nil, "", fmt.Errorf("unable to retrieve Blueprint Assignment %q (Scope %q): %+v", name, scope, err) + } + + return resp, string(resp.ProvisioningState), nil + } +} + +func blueprintAssignmentDeleteStateRefreshFunc(ctx context.Context, client *blueprint.AssignmentsClient, scope, name string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + resp, err := client.Get(ctx, scope, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return resp, "NotFound", nil + } else { + return nil, "", fmt.Errorf("unable to retrieve Blueprint Assignment %q (Scope %q): %+v", name, scope, err) + } + } + + return resp, string(resp.ProvisioningState), nil + } +} + +func normalizeAssignmentParameterValuesJSON(jsonString interface{}) string { + if jsonString == nil || jsonString == "" { + return "" + } + + var values map[string]*blueprint.ParameterValue + if err := json.Unmarshal([]byte(jsonString.(string)), &values); err != nil { + return fmt.Sprintf("unable to parse JSON: %+v", err) + } + + b, _ := json.Marshal(values) + return string(b) +} + +func normalizeAssignmentResourceGroupValuesJSON(jsonString interface{}) string { + if jsonString == nil || jsonString == "" { + return "" + } + + var values map[string]*blueprint.ResourceGroupValue + if err := json.Unmarshal([]byte(jsonString.(string)), &values); err != nil { + return fmt.Sprintf("unable to parse JSON: %+v", err) + } + + b, _ := json.Marshal(values) + return string(b) +} diff --git a/azurerm/internal/services/blueprints/blueprint_assignment_resource.go b/azurerm/internal/services/blueprints/blueprint_assignment_resource.go index 4caeecf07d04..566adba11231 100644 --- a/azurerm/internal/services/blueprints/blueprint_assignment_resource.go +++ b/azurerm/internal/services/blueprints/blueprint_assignment_resource.go @@ -1,33 +1,288 @@ package blueprints -import "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +import ( + "fmt" + "time" + + "github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/structure" + "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/helpers/suppress" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/location" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/blueprints/parse" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/blueprints/validate" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) func resourceArmBlueprintAssignment() *schema.Resource { return &schema.Resource{ Create: resourceArmBlueprintAssignmentCreateUpdate, - Update: nil, + Update: resourceArmBlueprintAssignmentCreateUpdate, Read: resourceArmBlueprintAssignmentRead, Delete: resourceArmBlueprintAssignmentDelete, Importer: nil, - Timeouts: nil, + Timeouts: &schema.ResourceTimeout{ + Read: schema.DefaultTimeout(5 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "scope_type": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + "subscription", + "managementGroup", + }, true), + }, + + "scope": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "location": location.Schema(), + + "identity": ManagedIdentitySchema(), + + "blueprint_id": { + Type: schema.TypeString, + Optional: true, + ConflictsWith: []string{"version_id"}, + ValidateFunc: validate.BlueprintID, + }, + + "version_name": { + Type: schema.TypeString, + Optional: true, + ConflictsWith: []string{"version_id"}, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "version_id": { + Type: schema.TypeString, + Optional: true, + ConflictsWith: []string{"blueprint_id", "version_name"}, + ValidateFunc: validate.BlueprintVersionID, + }, + + "parameter_values": { + Type: schema.TypeString, + Optional: true, + // This state function is used to normalize the format of the input JSON string, + // and strip any extra field comparing to the allowed fields in the swagger + // to avoid unnecessary diff in the state and config + StateFunc: normalizeAssignmentParameterValuesJSON, + ValidateFunc: validation.StringIsJSON, + // Suppress the differences caused by JSON formatting or ordering + DiffSuppressFunc: structure.SuppressJsonDiff, + }, + + "resource_groups": { + Type: schema.TypeString, + Optional: true, + // This state function is used to normalize the format of the input JSON string, + // and strip any extra field comparing to the allowed fields in the swagger + // to avoid unnecessary diff in the state and config + StateFunc: normalizeAssignmentResourceGroupValuesJSON, + ValidateFunc: validation.StringIsJSON, + // Suppress the differences caused by JSON formatting or ordering + DiffSuppressFunc: structure.SuppressJsonDiff, + }, + + "lock_mode": { + Type: schema.TypeString, + Optional: true, + Default: string(blueprint.None), + ValidateFunc: validation.StringInSlice([]string{ + string(blueprint.None), + string(blueprint.AllResourcesReadOnly), + string(blueprint.AllResourcesDoNotDelete), + }, false), + // The first character of value returned by the service is always in lower case. + DiffSuppressFunc: suppress.CaseDifference, + }, - Schema: nil, + "lock_exclude_principals": { + Type: schema.TypeSet, + Optional: true, + MaxItems: 5, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Set: schema.HashString, + }, + + "description": { + Type: schema.TypeString, + Computed: true, + }, + + "display_name": { + Type: schema.TypeString, + Computed: true, + }, + + "blueprint_name": { + Type: schema.TypeString, + Computed: true, + }, + + "type": { + Type: schema.TypeString, + Computed: true, + }, + }, } } func resourceArmBlueprintAssignmentCreateUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Blueprints.AssignmentsClient + ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + var name, targetScope, definitionScope, blueprintId string + + if versionIdRaw, ok := d.GetOk("version_id"); ok { + versionID, _ := parse.VersionID(versionIdRaw.(string)) + definitionScope = versionID.Scope + blueprintId = fmt.Sprintf("/%s/providers/Microsoft.Blueprint/blueprints/%s", versionID.Scope, versionID.Blueprint) + } else { + if bpIDRaw, ok := d.GetOk("blueprint_id"); ok { + bpID, err := parse.DefinitionID(bpIDRaw.(string)) + if err != nil { + return err + } + + if versionName, ok := d.GetOk("version_name"); ok { + blueprintId = fmt.Sprintf("%s/versions/%s", bpIDRaw.(string), versionName.(string)) + definitionScope = bpID.Scope + } 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) + + assignment := blueprint.Assignment{ + Identity: nil, // TODO - Identity schema? + AssignmentProperties: &blueprint.AssignmentProperties{ + BlueprintID: utils.String(blueprintId), + Scope: utils.String(definitionScope), + }, + Location: utils.String(azure.NormalizeLocation(d.Get("location"))), + } + + resp, err := client.CreateOrUpdate(ctx, targetScope, name, assignment) + if err != nil { + return err + } + + stateConf := &resource.StateChangeConf{ + Pending: []string{ + string(blueprint.Waiting), + string(blueprint.Validating), + string(blueprint.Creating), + string(blueprint.Deploying), + string(blueprint.Locking), + }, + Target: []string{string(blueprint.Succeeded)}, + Refresh: blueprintAssignmentCreateStateRefreshFunc(ctx, client, targetScope, name), + Timeout: d.Timeout(schema.TimeoutCreate), + } + + if _, err := stateConf.WaitForState(); err != nil { + return fmt.Errorf("Failed waiting for Blueprint Assignment %q (Scope %q): %+v", name, targetScope, err) + } + + d.SetId(*resp.ID) return resourceArmBlueprintAssignmentRead(d, meta) } func resourceArmBlueprintAssignmentRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Blueprints.AssignmentsClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := parse.AssignmentID(d.Id()) + resourceScope := id.Scope + assignmentName := id.Name + + resp, err := client.Get(ctx, resourceScope, assignmentName) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Blueprint Assignment %q not found: %+v", assignmentName, err) + } + + return fmt.Errorf("Read failed for Blueprint Assignment (%q): %+v", assignmentName, err) + } + + if resp.Name != nil { + d.Set("name", resp.Name) + } + + if resp.Scope != nil { + d.Set("scope", resp.Scope) + } return nil } func resourceArmBlueprintAssignmentDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Blueprints.AssignmentsClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + assignmentID, err := parse.AssignmentID(d.Id()) + if err != nil { + return err + } + + name := assignmentID.Name + targetScope := assignmentID.Scope + + resp, err := client.Delete(ctx, targetScope, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return nil + } + return fmt.Errorf("failed to delete Blueprint Assignment %q from scope %q: %+v", name, targetScope, err) + } + + stateConf := &resource.StateChangeConf{ + Pending: []string{ + string(blueprint.Waiting), + string(blueprint.Validating), + string(blueprint.Locking), + string(blueprint.Deleting), + }, + Target: []string{"NotFound"}, + Refresh: blueprintAssignmentDeleteStateRefreshFunc(ctx, client, targetScope, name), + Timeout: d.Timeout(schema.TimeoutDelete), + } + + if _, err := stateConf.WaitForState(); err != nil { + return fmt.Errorf("Failed waiting for Blueprint Assignment %q (Scope %q): %+v", name, targetScope, err) + } return nil } diff --git a/azurerm/internal/services/blueprints/blueprint_definition_datasource.go b/azurerm/internal/services/blueprints/blueprint_definition_datasource.go index 2c5e9f077ad8..7b00f4681243 100644 --- a/azurerm/internal/services/blueprints/blueprint_definition_datasource.go +++ b/azurerm/internal/services/blueprints/blueprint_definition_datasource.go @@ -1,7 +1,125 @@ package blueprints -import "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +import ( + "fmt" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/terraform-providers/terraform-provider-azuread/azuread/helpers/validate" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" + "time" +) func dataSourceArmBlueprintDefinition() *schema.Resource { - return &schema.Resource{} + return &schema.Resource{ + Read: dataSourceArmBlueprintDefinitionRead, + + Timeouts: &schema.ResourceTimeout{ + Read: schema.DefaultTimeout(5 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "scope": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + "subscription", + "managementGroup", + }, false), + }, + + // Computed + "description": { + Type: schema.TypeString, + Computed: true, + }, + + "display_name": { + Type: schema.TypeString, + Computed: true, + }, + + "last_modified": { + Type: schema.TypeString, + Computed: true, + }, + + "target_scope": { + Type: schema.TypeString, + Computed: true, + }, + + "time_created": { + Type: schema.TypeString, + Computed: true, + }, + + "type": { + Type: schema.TypeString, + Computed: true, + }, + + "versions": { + Type: schema.TypeList, + Computed: true, + Elem: schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + }, + }, + } +} + +func dataSourceArmBlueprintDefinitionRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Blueprints.BlueprintsClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + scope := d.Get("scope").(string) + name := d.Get("name").(string) + + resp, err := client.Get(ctx, scope, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Blueprint Definition %q not found in Scope (%q): %+v", name, scope, err) + } + + return fmt.Errorf("Read failed for Blueprint Definition (%q) in Sccope (%q): %+v", name, scope, err) + } + + if resp.ID != nil { + d.SetId(*resp.ID) + } else { + return fmt.Errorf("Failed to retrieve ID for Blueprint %q", name) + } + + if resp.Description != nil { + d.Set("description", resp.Description) + } + + if resp.DisplayName != nil { + d.Set("display_name", resp.DisplayName) + } + + d.Set("last_modified", resp.Status.LastModified.String()) + + d.Set("time_created", resp.Status.TimeCreated.String()) + + if resp.Type != nil { + d.Set("type", resp.Type) + } + + if resp.Versions != nil { + d.Set("versions", resp.Versions) + } + + return nil } diff --git a/azurerm/internal/services/blueprints/client/client.go b/azurerm/internal/services/blueprints/client/client.go index 463bfe31bae1..3011d41145ab 100644 --- a/azurerm/internal/services/blueprints/client/client.go +++ b/azurerm/internal/services/blueprints/client/client.go @@ -7,6 +7,7 @@ import ( type Client struct { AssignmentsClient *blueprint.AssignmentsClient + BlueprintsClient *blueprint.BlueprintsClient PublishedBlueprintsClient *blueprint.PublishedBlueprintsClient } @@ -14,11 +15,15 @@ func NewClient(o *common.ClientOptions) *Client { assignmentsClient := blueprint.NewAssignmentsClientWithBaseURI(o.ResourceManagerEndpoint) o.ConfigureClient(&assignmentsClient.Client, o.ResourceManagerAuthorizer) + blueprintsClient := blueprint.NewBlueprintsClientWithBaseURI(o.ResourceManagerEndpoint) + o.ConfigureClient(&blueprintsClient.Client, o.ResourceManagerAuthorizer) + publishedBlueprintsClient := blueprint.NewPublishedBlueprintsClientWithBaseURI(o.ResourceManagerEndpoint) o.ConfigureClient(&publishedBlueprintsClient.Client, o.ResourceManagerAuthorizer) return &Client{ AssignmentsClient: &assignmentsClient, + BlueprintsClient: &blueprintsClient, PublishedBlueprintsClient: &publishedBlueprintsClient, } } diff --git a/azurerm/internal/services/blueprints/parse/blueprint_assignment.go b/azurerm/internal/services/blueprints/parse/blueprint_assignment.go index 593810563ebb..c3aa3bf3730d 100644 --- a/azurerm/internal/services/blueprints/parse/blueprint_assignment.go +++ b/azurerm/internal/services/blueprints/parse/blueprint_assignment.go @@ -6,7 +6,7 @@ import ( "strings" ) -type BlueprintAssignmentId struct { +type AssignmentId struct { // "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Blueprint/blueprintAssignments/assignSimpleBlueprint", // "/managementGroups/ContosoOnlineGroup/providers/Microsoft.Blueprint/blueprintAssignments/assignSimpleBlueprint", @@ -16,12 +16,12 @@ type BlueprintAssignmentId struct { Name string } -func BlueprintAssignmentID(input string) (*BlueprintAssignmentId, error) { +func AssignmentID(input string) (*AssignmentId, error) { if len(input) == 0 { return nil, fmt.Errorf("Bad: Assignment ID is empty string") } - assignmentID := BlueprintAssignmentId{} + assignmentID := AssignmentId{} idParts := strings.Split(strings.Trim(input, "/"), "/") if len(idParts) != 6 { @@ -39,7 +39,7 @@ func BlueprintAssignmentID(input string) (*BlueprintAssignmentId, error) { switch idParts[0] { case "managementGroups": - assignmentID = BlueprintAssignmentId{ + assignmentID = AssignmentId{ Scope: fmt.Sprintf("%s/%s", idParts[0], idParts[1]), ManagementGroup: idParts[1], } diff --git a/azurerm/internal/services/blueprints/parse/blueprint_assignment_test.go b/azurerm/internal/services/blueprints/parse/blueprint_assignment_test.go index c6d83a3560a4..2a7aa0b54be9 100644 --- a/azurerm/internal/services/blueprints/parse/blueprint_assignment_test.go +++ b/azurerm/internal/services/blueprints/parse/blueprint_assignment_test.go @@ -9,7 +9,7 @@ func TestBlueprintAssignmentID(t *testing.T) { Name string Input string Error bool - Expected *BlueprintAssignmentId + Expected *AssignmentId }{ { Name: "Empty", @@ -31,7 +31,7 @@ func TestBlueprintAssignmentID(t *testing.T) { Name: "Valid subscription scoped", Input: "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Blueprint/blueprintAssignments/assignSimpleBlueprint", Error: false, - Expected: &BlueprintAssignmentId{ + Expected: &AssignmentId{ Scope: "subscriptions/00000000-0000-0000-0000-000000000000", Subscription: "00000000-0000-0000-0000-000000000000", Name: "assignSimpleBlueprint", @@ -41,7 +41,7 @@ func TestBlueprintAssignmentID(t *testing.T) { Name: "Valid managementGroup scoped", Input: "/managementGroups/testAccManagementGroup/providers/Microsoft.Blueprint/blueprintAssignments/assignSimpleBlueprint", Error: false, - Expected: &BlueprintAssignmentId{ + Expected: &AssignmentId{ Scope: "managementGroups/testAccManagementGroup", ManagementGroup: "testAccManagementGroup", Name: "assignSimpleBlueprint", @@ -62,7 +62,7 @@ func TestBlueprintAssignmentID(t *testing.T) { for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Name) - actual, err := BlueprintAssignmentID(v.Input) + actual, err := AssignmentID(v.Input) if err != nil { if v.Error { continue diff --git a/azurerm/internal/services/blueprints/parse/blueprint_definition.go b/azurerm/internal/services/blueprints/parse/blueprint_definition.go new file mode 100644 index 000000000000..113a5b90312a --- /dev/null +++ b/azurerm/internal/services/blueprints/parse/blueprint_definition.go @@ -0,0 +1,59 @@ +package parse + +import ( + "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "strings" +) + +type DefinitionId struct { + // "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Blueprint/blueprints/simpleBlueprint" + // "/providers/Microsoft.Management/managementGroups/ContosoOnlineGroup/providers/Microsoft.Blueprint/blueprints/simpleBlueprint" + + Name string + Scope string +} + +func DefinitionID(input string) (*DefinitionId, error) { + if len(input) == 0 { + return nil, fmt.Errorf("Bad: Blueprint ID cannot be an empty string") + } + + definitionId := DefinitionId{} + + idParts := strings.Split(strings.Trim(input, "/"), "/") + if len(idParts) != 6 && len(idParts) != 8 { + return nil, fmt.Errorf("Bad: Blueprint Version ID invalid: %q", input) + } + + switch idParts[0] { + case "providers": + // check casing on segments + if idParts[1] != "Microsoft.Management" || idParts[2] != "managementGroups" { + return nil, fmt.Errorf("ID has invalid provider scope segment (should be `/providers/Microsoft.Management/managementGroups` case sensitive): %q", input) + } + if idParts[4] != "providers" || idParts[5] != "Microsoft.Blueprint" || idParts[6] != "blueprints" { + return nil, fmt.Errorf("Bad: ID has invalid resource provider segment(s), shoud be `/providers/Microsoft.Blueprint/blueprints/`, case sensitive: %q", input) + + } + + definitionId = DefinitionId{ + Scope: fmt.Sprintf("providers/Microsoft.Management/managementGroups/%s", idParts[3]), + Name: idParts[6], + } + + case "subscriptions": + id, err := azure.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("[ERROR] Unable to parse Image ID %q: %+v", input, err) + } + + definitionId.Scope = fmt.Sprintf("subscriptions/%s", id.SubscriptionID) + definitionId.Name = idParts[5] + + default: + return nil, fmt.Errorf("Bad: Invalid ID, should start with one of `/provider` or `/subscriptions`: %q", input) + } + + return &definitionId, nil +} diff --git a/azurerm/internal/services/blueprints/parse/blueprint_version.go b/azurerm/internal/services/blueprints/parse/blueprint_version.go index 81ec6c5a260d..c8b1604ec800 100644 --- a/azurerm/internal/services/blueprints/parse/blueprint_version.go +++ b/azurerm/internal/services/blueprints/parse/blueprint_version.go @@ -6,7 +6,7 @@ import ( "strings" ) -type BlueprintVersionId struct { +type VersionId struct { // "/{resourceScope}/providers/Microsoft.Blueprint/blueprints/{blueprintName}/versions/{versionId}" // "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Blueprint/blueprints/simpleBlueprint/versions/v1" // "/providers/Microsoft.Management/managementGroups/ContosoOnlineGroup/providers/Microsoft.Blueprint/blueprints/simpleBlueprint/versions/v1" @@ -16,12 +16,12 @@ type BlueprintVersionId struct { Name string } -func BlueprintVersionID(input string) (*BlueprintVersionId, error) { +func VersionID(input string) (*VersionId, error) { if len(input) == 0 { return nil, fmt.Errorf("Bad: Blueprint version ID cannot be an empty string") } - versionId := BlueprintVersionId{} + versionId := VersionId{} idParts := strings.Split(strings.Trim(input, "/"), "/") if len(idParts) != 8 && len(idParts) != 10 { @@ -34,12 +34,12 @@ func BlueprintVersionID(input string) (*BlueprintVersionId, error) { if idParts[1] != "Microsoft.Management" || idParts[2] != "managementGroups" { return nil, fmt.Errorf("ID has invalid provider scope segment (should be `/providers/Microsoft.Management/managementGroups` case sensitive): %q", input) } - if idParts[4] != "providers" || idParts[5] != "Microsoft.Blueprint" || idParts[6] != "blueprints" { + if idParts[4] != "providers" || idParts[5] != "Microsoft.Blueprint" || idParts[6] != "blueprints" { return nil, fmt.Errorf("Bad: ID has invalid resource provider segment(s), shoud be `/providers/Microsoft.Blueprint/blueprints/`, case sensitive: %q", input) } - versionId = BlueprintVersionId{ + versionId = VersionId{ Scope: fmt.Sprintf("providers/Microsoft.Management/managementGroups/%s", idParts[3]), Blueprint: idParts[6], Name: idParts[9], diff --git a/azurerm/internal/services/blueprints/parse/blueprint_version_test.go b/azurerm/internal/services/blueprints/parse/blueprint_version_test.go index cb4acce48bae..44d2de1683cd 100644 --- a/azurerm/internal/services/blueprints/parse/blueprint_version_test.go +++ b/azurerm/internal/services/blueprints/parse/blueprint_version_test.go @@ -7,7 +7,7 @@ func TestBlueprintVersionID(t *testing.T) { Name string Input string Error bool - Expected *BlueprintVersionId + Expected *VersionId }{ { Name: "Empty", @@ -26,18 +26,18 @@ func TestBlueprintVersionID(t *testing.T) { }, // We have two valid possibilities to check for { - Name: "Valid subscription scoped", + Name: "Valid subscription scoped", Input: "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Blueprint/blueprints/simpleBlueprint/versions/v1-test", - Expected: &BlueprintVersionId{ + Expected: &VersionId{ Scope: "subscriptions/00000000-0000-0000-0000-000000000000", Blueprint: "simpleBlueprint", Name: "v1-test", }, }, { - Name: "Valid management group scoped", + Name: "Valid management group scoped", Input: "/providers/Microsoft.Management/managementGroups/testAccManagementGroup/providers/Microsoft.Blueprint/blueprints/simpleBlueprint/versions/v1-test", - Expected: &BlueprintVersionId{ + Expected: &VersionId{ Scope: "providers/Microsoft.Management/managementGroups/testAccManagementGroup", Blueprint: "simpleBlueprint", Name: "v1-test", @@ -48,7 +48,7 @@ func TestBlueprintVersionID(t *testing.T) { for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Name) - actual, err := BlueprintVersionID(v.Input) + actual, err := VersionID(v.Input) if err != nil { if v.Error { continue diff --git a/azurerm/internal/services/blueprints/validate/blueprint.go b/azurerm/internal/services/blueprints/validate/blueprint.go new file mode 100644 index 000000000000..bb709fb7b7ba --- /dev/null +++ b/azurerm/internal/services/blueprints/validate/blueprint.go @@ -0,0 +1,21 @@ +package validate + +import ( + "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/blueprints/parse" +) + +func BlueprintID(i interface{}, k string) (warnings []string, errors []error) { + v, ok := i.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected type of %q to be string", k)) + return + } + + if _, err := parse.DefinitionID(v); err != nil { + errors = append(errors, fmt.Errorf("Can not parse %q as a resource id: %v", k, err)) + return + } + + return warnings, errors +} diff --git a/azurerm/internal/services/blueprints/validate/blueprint_version.go b/azurerm/internal/services/blueprints/validate/blueprint_version.go new file mode 100644 index 000000000000..be322b8bcdd3 --- /dev/null +++ b/azurerm/internal/services/blueprints/validate/blueprint_version.go @@ -0,0 +1,21 @@ +package validate + +import ( + "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/blueprints/parse" +) + +func BlueprintVersionID(i interface{}, k string) (warnings []string, errors []error) { + v, ok := i.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected type of %q to be string", k)) + return + } + + if _, err := parse.VersionID(v); err != nil { + errors = append(errors, fmt.Errorf("Can not parse %q as a Blueprint Version id: %v", k, err)) + return + } + + return warnings, errors +} diff --git a/azurerm/internal/services/blueprints/validate/identity.go b/azurerm/internal/services/blueprints/validate/identity.go new file mode 100644 index 000000000000..97c745e93b3e --- /dev/null +++ b/azurerm/internal/services/blueprints/validate/identity.go @@ -0,0 +1,21 @@ +package validate + +import ( + "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" +) + +func UserAssignedIdentityId(i interface{}, k string) (warnings []string, errors []error) { + v, ok := i.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected type of %q to be string", k)) + return + } + + if _, err := azure.ParseUserAssignedIdentityID(v); err != nil { + errors = append(errors, fmt.Errorf("Can not parse %q as a resource id: %v", k, err)) + return + } + + return warnings, errors +} From 30b0aaaa6af046c0d9ae81f0206357acd173bf26 Mon Sep 17 00:00:00 2001 From: jackofallops Date: Fri, 24 Apr 2020 16:06:14 +0100 Subject: [PATCH 03/26] updates --- .../internal/services/blueprints/blueprint.go | 113 +++++++++++- .../blueprint_assignment_resource.go | 161 ++++++++++++++---- .../blueprint_definition_datasource.go | 3 +- .../blueprint_published_version_datasource.go | 3 +- .../blueprints/parse/blueprint_assignment.go | 3 +- .../parse/blueprint_assignment_test.go | 1 - .../blueprints/parse/blueprint_definition.go | 4 +- .../blueprints/parse/blueprint_version.go | 5 +- .../services/blueprints/validate/blueprint.go | 1 + .../blueprints/validate/blueprint_version.go | 1 + .../services/blueprints/validate/identity.go | 1 + 11 files changed, 250 insertions(+), 46 deletions(-) diff --git a/azurerm/internal/services/blueprints/blueprint.go b/azurerm/internal/services/blueprints/blueprint.go index 1eb4c12cbc43..1dcf17de44b5 100644 --- a/azurerm/internal/services/blueprints/blueprint.go +++ b/azurerm/internal/services/blueprints/blueprint.go @@ -4,10 +4,12 @@ import ( "context" "encoding/json" "fmt" + "github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/blueprints/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/blueprints/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -25,15 +27,18 @@ func ManagedIdentitySchema() *schema.Schema { Default: string(blueprint.ManagedServiceIdentityTypeSystemAssigned), ValidateFunc: validation.StringInSlice([]string{ // ManagedServiceIdentityTypeNone is not valid; a valid and privileged Identity is required for the service to apply the changes. + // SystemAssigned type not currently supported - The Portal performs significant activity in temporary escalation of permissions to Owner on the target scope + // Such activity in the Provider would be brittle + // string(blueprint.ManagedServiceIdentityTypeSystemAssigned), string(blueprint.ManagedServiceIdentityTypeUserAssigned), - string(blueprint.ManagedServiceIdentityTypeSystemAssigned), }, false), }, "user_assigned_identities": { // The API only seems to care about the "key" portion of this struct, which is the ResourceID of the Identity Type: schema.TypeList, - Optional: true, + Required: true, + MinItems: 1, Elem: &schema.Schema{ Type: schema.TypeString, ValidateFunc: validate.UserAssignedIdentityId, @@ -107,3 +112,107 @@ func normalizeAssignmentResourceGroupValuesJSON(jsonString interface{}) string { b, _ := json.Marshal(values) return string(b) } + +func expandArmBlueprintAssignmentParameters(input string) map[string]*blueprint.ParameterValue { + var result map[string]*blueprint.ParameterValue + // the string has been validated by the schema, therefore the error is ignored here, since it will never happen. + _ = json.Unmarshal([]byte(input), &result) + return result +} + +func expandArmBlueprintAssignmentResourceGroups(input string) map[string]*blueprint.ResourceGroupValue { + var result map[string]*blueprint.ResourceGroupValue + // the string has been validated by the schema, therefore the error is ignored here, since it will never happen. + _ = json.Unmarshal([]byte(input), &result) + return result +} + +func expandArmBlueprintAssignmentIdentity(input []interface{}) (*blueprint.ManagedServiceIdentity, error) { + if len(input) == 0 { + return nil, fmt.Errorf("Managed Service Identity was empty") + } + + raw := input[0].(map[string]interface{}) + + identity := blueprint.ManagedServiceIdentity{ + Type: blueprint.ManagedServiceIdentityType(raw["type"].(string)), + } + + identityIdsRaw := raw["identity_ids"].(*schema.Set).List() + identityIds := make(map[string]*blueprint.UserAssignedIdentity) + for _, v := range identityIdsRaw { + identityIds[v.(string)] = &blueprint.UserAssignedIdentity{} + } + + return &identity, nil +} + +func flattenArmBlueprintAssignmentIdentity(input *blueprint.ManagedServiceIdentity) []interface{} { + if input == nil { + return []interface{}{} + } + + identityIds := make([]string, 0) + if input.UserAssignedIdentities != nil { + for k := range input.UserAssignedIdentities { + identityIds = append(identityIds, k) + } + } + + principalId := "" + if input.PrincipalID != nil { + principalId = *input.PrincipalID + } + + tenantId := "" + if input.TenantID != nil { + tenantId = *input.TenantID + } + + return []interface{}{ + map[string]interface{}{ + "type": string(input.Type), + "identity_ids": identityIds, + "principal_id": principalId, + "tenant_id": tenantId, + }, + } +} + +func flattenArmBlueprintAssignmentParameters(input map[string]*blueprint.ParameterValue) (string, error) { + if len(input) == 0 { + return "", nil + } + + b, err := json.Marshal(input) + if err != nil { + return "", err + } + + return string(b), nil +} + +func flattenArmBlueprintAssignmentResourceGroups(input map[string]*blueprint.ResourceGroupValue) (string, error) { + if len(input) == 0 { + return "", nil + } + + b, err := json.Marshal(input) + if err != nil { + return "", err + } + + return string(b), nil +} + +func splitPublishedVersionID(input string) (blueprintID, versionName string) { + versionID, err := parse.VersionID(input) + if err != nil { + return "", "" + } + + versionName = versionID.Name + blueprintID = fmt.Sprintf("/%s/providers/Microsoft.Blueprint/blueprints/%s", versionID.Scope, versionID.Blueprint) + + return +} diff --git a/azurerm/internal/services/blueprints/blueprint_assignment_resource.go b/azurerm/internal/services/blueprints/blueprint_assignment_resource.go index 566adba11231..15d6a236faa1 100644 --- a/azurerm/internal/services/blueprints/blueprint_assignment_resource.go +++ b/azurerm/internal/services/blueprints/blueprint_assignment_resource.go @@ -2,8 +2,12 @@ package blueprints import ( "fmt" + "log" + "strings" "time" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/set" + "github.com/Azure/azure-sdk-for-go/services/preview/blueprint/mgmt/2018-11-01-preview/blueprint" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -59,47 +63,39 @@ func resourceArmBlueprintAssignment() *schema.Resource { "identity": ManagedIdentitySchema(), "blueprint_id": { - Type: schema.TypeString, - Optional: true, - ConflictsWith: []string{"version_id"}, - ValidateFunc: validate.BlueprintID, + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validate.BlueprintID, }, "version_name": { - Type: schema.TypeString, - Optional: true, - ConflictsWith: []string{"version_id"}, - ValidateFunc: validation.StringIsNotEmpty, + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringIsNotEmpty, }, "version_id": { - Type: schema.TypeString, - Optional: true, - ConflictsWith: []string{"blueprint_id", "version_name"}, - ValidateFunc: validate.BlueprintVersionID, + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validate.BlueprintVersionID, }, "parameter_values": { - Type: schema.TypeString, - Optional: true, - // This state function is used to normalize the format of the input JSON string, - // and strip any extra field comparing to the allowed fields in the swagger - // to avoid unnecessary diff in the state and config - StateFunc: normalizeAssignmentParameterValuesJSON, - ValidateFunc: validation.StringIsJSON, - // Suppress the differences caused by JSON formatting or ordering + Type: schema.TypeString, + Optional: true, + StateFunc: normalizeAssignmentParameterValuesJSON, + ValidateFunc: validation.StringIsJSON, DiffSuppressFunc: structure.SuppressJsonDiff, }, "resource_groups": { - Type: schema.TypeString, - Optional: true, - // This state function is used to normalize the format of the input JSON string, - // and strip any extra field comparing to the allowed fields in the swagger - // to avoid unnecessary diff in the state and config - StateFunc: normalizeAssignmentResourceGroupValuesJSON, - ValidateFunc: validation.StringIsJSON, - // Suppress the differences caused by JSON formatting or ordering + Type: schema.TypeString, + Optional: true, + StateFunc: normalizeAssignmentResourceGroupValuesJSON, + ValidateFunc: validation.StringIsJSON, DiffSuppressFunc: structure.SuppressJsonDiff, }, @@ -121,7 +117,8 @@ func resourceArmBlueprintAssignment() *schema.Resource { Optional: true, MaxItems: 5, Elem: &schema.Schema{ - Type: schema.TypeString, + Type: schema.TypeString, + ValidateFunc: validation.IsUUID, }, Set: schema.HashString, }, @@ -157,9 +154,14 @@ func resourceArmBlueprintAssignmentCreateUpdate(d *schema.ResourceData, meta int var name, targetScope, definitionScope, blueprintId string if versionIdRaw, ok := d.GetOk("version_id"); ok { - versionID, _ := parse.VersionID(versionIdRaw.(string)) - definitionScope = versionID.Scope - blueprintId = fmt.Sprintf("/%s/providers/Microsoft.Blueprint/blueprints/%s", versionID.Scope, versionID.Blueprint) + blueprintId = versionIdRaw.(string) + 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") + } } else { if bpIDRaw, ok := d.GetOk("blueprint_id"); ok { bpID, err := parse.DefinitionID(bpIDRaw.(string)) @@ -173,7 +175,6 @@ func resourceArmBlueprintAssignmentCreateUpdate(d *schema.ResourceData, meta int } 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") } @@ -185,12 +186,39 @@ func resourceArmBlueprintAssignmentCreateUpdate(d *schema.ResourceData, meta int assignment := blueprint.Assignment{ Identity: nil, // TODO - Identity schema? AssignmentProperties: &blueprint.AssignmentProperties{ - BlueprintID: utils.String(blueprintId), + BlueprintID: utils.String(blueprintId), // This is mislabeled - The ID is that of the Published Version, not just the Blueprint Scope: utils.String(definitionScope), }, Location: utils.String(azure.NormalizeLocation(d.Get("location"))), } + if lockModeRaw, ok := d.GetOk("lock_mode"); ok { + assignmentLockSettings := &blueprint.AssignmentLockSettings{} + lockMode := lockModeRaw.(string) + assignmentLockSettings.Mode = blueprint.AssignmentLockMode(lockMode) + if lockMode != "None" { + excludedPrincipalsRaw := d.Get("lock_exclude_principals").(*schema.Set).List() + if len(excludedPrincipalsRaw) != 0 { + assignmentLockSettings.ExcludedPrincipals = utils.ExpandStringSlice(excludedPrincipalsRaw) + } + } + assignment.AssignmentProperties.Locks = assignmentLockSettings + } + + identity, err := expandArmBlueprintAssignmentIdentity(d.Get("identity").([]interface{})) + if err != nil { + return err + } + assignment.Identity = identity + + if paramValuesRaw, ok := d.GetOk("parameter_values"); ok { + assignment.Parameters = expandArmBlueprintAssignmentParameters(paramValuesRaw.(string)) + } + + if resourceGroupsRaw, ok := d.GetOk("resource_groups"); ok { + assignment.ResourceGroups = expandArmBlueprintAssignmentResourceGroups(resourceGroupsRaw.(string)) + } + resp, err := client.CreateOrUpdate(ctx, targetScope, name, assignment) if err != nil { return err @@ -224,13 +252,19 @@ func resourceArmBlueprintAssignmentRead(d *schema.ResourceData, meta interface{} defer cancel() id, err := parse.AssignmentID(d.Id()) + if err != nil { + return err + } + resourceScope := id.Scope assignmentName := id.Name resp, err := client.Get(ctx, resourceScope, assignmentName) if err != nil { if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Blueprint Assignment %q not found: %+v", assignmentName, err) + log.Printf("[INFO] the Blueprint Assignment %q does not exist - removing from state", assignmentName) + d.SetId("") + return nil } return fmt.Errorf("Read failed for Blueprint Assignment (%q): %+v", assignmentName, err) @@ -241,7 +275,62 @@ func resourceArmBlueprintAssignmentRead(d *schema.ResourceData, meta interface{} } if resp.Scope != nil { - d.Set("scope", resp.Scope) + scopeParts := strings.Split(*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) + } + } + + if resp.Location != nil { + d.Set("location", azure.NormalizeLocation(resp.Location)) + } + + if resp.Identity != nil { + d.Set("identity", flattenArmBlueprintAssignmentIdentity(resp.Identity)) + } + + 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 { + params, err := flattenArmBlueprintAssignmentParameters(resp.Parameters) + if err != nil { + return err + } + d.Set("parameter_values", params) + } + + if resp.ResourceGroups != nil { + resourceGroups, err := flattenArmBlueprintAssignmentResourceGroups(resp.ResourceGroups) + if err != nil { + return err + } + d.Set("resource_groups", resourceGroups) + } + + // Locks + if locks := resp.Locks; locks != nil { + d.Set("lock_mode", locks.Mode) + if locks.ExcludedPrincipals != nil { + d.Set("lock_excluded_principals", set.FromStringSlice(*locks.ExcludedPrincipals)) + } + } + } + + if resp.DisplayName != nil { + d.Set("display_name", resp.DisplayName) + } + + if resp.Description != nil { + d.Set("description", resp.Description) } return nil diff --git a/azurerm/internal/services/blueprints/blueprint_definition_datasource.go b/azurerm/internal/services/blueprints/blueprint_definition_datasource.go index 7b00f4681243..79d782908c57 100644 --- a/azurerm/internal/services/blueprints/blueprint_definition_datasource.go +++ b/azurerm/internal/services/blueprints/blueprint_definition_datasource.go @@ -2,13 +2,14 @@ package blueprints import ( "fmt" + "time" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azuread/azuread/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" - "time" ) func dataSourceArmBlueprintDefinition() *schema.Resource { diff --git a/azurerm/internal/services/blueprints/blueprint_published_version_datasource.go b/azurerm/internal/services/blueprints/blueprint_published_version_datasource.go index 8e677e4588ed..e547f7ef4d82 100644 --- a/azurerm/internal/services/blueprints/blueprint_published_version_datasource.go +++ b/azurerm/internal/services/blueprints/blueprint_published_version_datasource.go @@ -2,12 +2,13 @@ package blueprints import ( "fmt" + "time" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/terraform-providers/terraform-provider-azuread/azuread/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" - "time" ) func dataSourceArmBlueprintPublishedVersion() *schema.Resource { diff --git a/azurerm/internal/services/blueprints/parse/blueprint_assignment.go b/azurerm/internal/services/blueprints/parse/blueprint_assignment.go index c3aa3bf3730d..0c5e930f69b1 100644 --- a/azurerm/internal/services/blueprints/parse/blueprint_assignment.go +++ b/azurerm/internal/services/blueprints/parse/blueprint_assignment.go @@ -2,8 +2,9 @@ package parse import ( "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "strings" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" ) type AssignmentId struct { diff --git a/azurerm/internal/services/blueprints/parse/blueprint_assignment_test.go b/azurerm/internal/services/blueprints/parse/blueprint_assignment_test.go index 2a7aa0b54be9..09ea4c756484 100644 --- a/azurerm/internal/services/blueprints/parse/blueprint_assignment_test.go +++ b/azurerm/internal/services/blueprints/parse/blueprint_assignment_test.go @@ -86,6 +86,5 @@ func TestBlueprintAssignmentID(t *testing.T) { if actual.Subscription == "" && actual.ManagementGroup != v.Expected.ManagementGroup { t.Fatalf("Expected %q but got %q for ManagementGroup", v.Expected.ManagementGroup, actual.ManagementGroup) } - } } diff --git a/azurerm/internal/services/blueprints/parse/blueprint_definition.go b/azurerm/internal/services/blueprints/parse/blueprint_definition.go index 113a5b90312a..684272a70adf 100644 --- a/azurerm/internal/services/blueprints/parse/blueprint_definition.go +++ b/azurerm/internal/services/blueprints/parse/blueprint_definition.go @@ -2,8 +2,9 @@ package parse import ( "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "strings" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" ) type DefinitionId struct { @@ -34,7 +35,6 @@ func DefinitionID(input string) (*DefinitionId, error) { } if idParts[4] != "providers" || idParts[5] != "Microsoft.Blueprint" || idParts[6] != "blueprints" { return nil, fmt.Errorf("Bad: ID has invalid resource provider segment(s), shoud be `/providers/Microsoft.Blueprint/blueprints/`, case sensitive: %q", input) - } definitionId = DefinitionId{ diff --git a/azurerm/internal/services/blueprints/parse/blueprint_version.go b/azurerm/internal/services/blueprints/parse/blueprint_version.go index c8b1604ec800..409307f9fb41 100644 --- a/azurerm/internal/services/blueprints/parse/blueprint_version.go +++ b/azurerm/internal/services/blueprints/parse/blueprint_version.go @@ -2,8 +2,9 @@ package parse import ( "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "strings" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" ) type VersionId struct { @@ -34,9 +35,9 @@ func VersionID(input string) (*VersionId, error) { if idParts[1] != "Microsoft.Management" || idParts[2] != "managementGroups" { return nil, fmt.Errorf("ID has invalid provider scope segment (should be `/providers/Microsoft.Management/managementGroups` case sensitive): %q", input) } + if idParts[4] != "providers" || idParts[5] != "Microsoft.Blueprint" || idParts[6] != "blueprints" { return nil, fmt.Errorf("Bad: ID has invalid resource provider segment(s), shoud be `/providers/Microsoft.Blueprint/blueprints/`, case sensitive: %q", input) - } versionId = VersionId{ diff --git a/azurerm/internal/services/blueprints/validate/blueprint.go b/azurerm/internal/services/blueprints/validate/blueprint.go index bb709fb7b7ba..49d3b4345669 100644 --- a/azurerm/internal/services/blueprints/validate/blueprint.go +++ b/azurerm/internal/services/blueprints/validate/blueprint.go @@ -2,6 +2,7 @@ package validate import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/blueprints/parse" ) diff --git a/azurerm/internal/services/blueprints/validate/blueprint_version.go b/azurerm/internal/services/blueprints/validate/blueprint_version.go index be322b8bcdd3..c22fc6abc5b7 100644 --- a/azurerm/internal/services/blueprints/validate/blueprint_version.go +++ b/azurerm/internal/services/blueprints/validate/blueprint_version.go @@ -2,6 +2,7 @@ package validate import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/blueprints/parse" ) diff --git a/azurerm/internal/services/blueprints/validate/identity.go b/azurerm/internal/services/blueprints/validate/identity.go index 97c745e93b3e..36bf30b54de4 100644 --- a/azurerm/internal/services/blueprints/validate/identity.go +++ b/azurerm/internal/services/blueprints/validate/identity.go @@ -2,6 +2,7 @@ package validate import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" ) From f003e6dfc081a355c0a1a8fe38c0b88adbcdd016 Mon Sep 17 00:00:00 2001 From: jackofallops Date: Mon, 27 Apr 2020 16:45:30 +0100 Subject: [PATCH 04/26] Added tests and docs --- .../internal/services/blueprints/blueprint.go | 1 - .../blueprint_definition_datasource.go | 36 +++--- .../blueprint_assignment_resource_test.go | 117 ++++++++++++++++++ .../blueprint_definition_data_source_test.go | 88 +++++++++++++ ...int_published_version_data_source_test.go} | 1 + .../services/blueprints/validate/blueprint.go | 14 +++ website/azurerm.erb | 18 +++ .../docs/d/blueprint_definition.html.markdown | 51 ++++++++ .../blueprint_published_version.html.markdown | 57 +++++++++ .../docs/r/blueprint_assignment.html.markdown | 64 ++++++++++ 10 files changed, 431 insertions(+), 16 deletions(-) create mode 100644 azurerm/internal/services/blueprints/tests/blueprint_assignment_resource_test.go create mode 100644 azurerm/internal/services/blueprints/tests/blueprint_definition_data_source_test.go rename azurerm/internal/services/blueprints/tests/{blueprint_published_version_datasource_test.go => blueprint_published_version_data_source_test.go} (98%) create mode 100644 website/docs/d/blueprint_definition.html.markdown create mode 100644 website/docs/d/blueprint_published_version.html.markdown create mode 100644 website/docs/r/blueprint_assignment.html.markdown diff --git a/azurerm/internal/services/blueprints/blueprint.go b/azurerm/internal/services/blueprints/blueprint.go index 1dcf17de44b5..017890297950 100644 --- a/azurerm/internal/services/blueprints/blueprint.go +++ b/azurerm/internal/services/blueprints/blueprint.go @@ -24,7 +24,6 @@ func ManagedIdentitySchema() *schema.Schema { "type": { Type: schema.TypeString, Required: true, - Default: string(blueprint.ManagedServiceIdentityTypeSystemAssigned), ValidateFunc: validation.StringInSlice([]string{ // ManagedServiceIdentityTypeNone is not valid; a valid and privileged Identity is required for the service to apply the changes. // SystemAssigned type not currently supported - The Portal performs significant activity in temporary escalation of permissions to Owner on the target scope diff --git a/azurerm/internal/services/blueprints/blueprint_definition_datasource.go b/azurerm/internal/services/blueprints/blueprint_definition_datasource.go index 79d782908c57..a38142e09951 100644 --- a/azurerm/internal/services/blueprints/blueprint_definition_datasource.go +++ b/azurerm/internal/services/blueprints/blueprint_definition_datasource.go @@ -6,8 +6,8 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - "github.com/terraform-providers/terraform-provider-azuread/azuread/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/blueprints/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -24,10 +24,10 @@ func dataSourceArmBlueprintDefinition() *schema.Resource { "name": { Type: schema.TypeString, Required: true, - ValidateFunc: validate.NoEmptyStrings, + ValidateFunc: validate.BlueprintName, }, - "scope": { + "scope_type": { Type: schema.TypeString, Required: true, ValidateFunc: validation.StringInSlice([]string{ @@ -36,6 +36,12 @@ func dataSourceArmBlueprintDefinition() *schema.Resource { }, false), }, + "scope_name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + // Computed "description": { Type: schema.TypeString, @@ -62,17 +68,11 @@ func dataSourceArmBlueprintDefinition() *schema.Resource { Computed: true, }, - "type": { - Type: schema.TypeString, - Computed: true, - }, - "versions": { Type: schema.TypeList, Computed: true, - Elem: schema.Schema{ - Type: schema.TypeString, - Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, }, }, }, @@ -84,8 +84,16 @@ func dataSourceArmBlueprintDefinitionRead(d *schema.ResourceData, meta interface ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - scope := d.Get("scope").(string) name := d.Get("name").(string) + var scope string + scopeName := d.Get("scope_name").(string) + scopeType := d.Get("scope_type").(string) + switch scopeType { + case "subscription": + scope = fmt.Sprintf("subscriptions/%s", scopeName) + case "managementGroup": + scope = fmt.Sprintf("providers/Microsoft.Management/managementGroups/%s", scopeName) + } resp, err := client.Get(ctx, scope, name) if err != nil { @@ -114,9 +122,7 @@ func dataSourceArmBlueprintDefinitionRead(d *schema.ResourceData, meta interface d.Set("time_created", resp.Status.TimeCreated.String()) - if resp.Type != nil { - d.Set("type", resp.Type) - } + d.Set("target_scope", resp.TargetScope) if resp.Versions != nil { d.Set("versions", resp.Versions) diff --git a/azurerm/internal/services/blueprints/tests/blueprint_assignment_resource_test.go b/azurerm/internal/services/blueprints/tests/blueprint_assignment_resource_test.go new file mode 100644 index 000000000000..c44f9b419f46 --- /dev/null +++ b/azurerm/internal/services/blueprints/tests/blueprint_assignment_resource_test.go @@ -0,0 +1,117 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/blueprints/parse" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccBlueprintAssignment_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_blueprint_assignment", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMBlueprintAssignmentDestroy, + Steps: []resource.TestStep{ + { + Config: testAccBlueprintAssignment_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckBlueprintAssignmentExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, ""), + ), + }, + }, + }) +} + +func testCheckBlueprintAssignmentExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Blueprint Assignment not found: %s", resourceName) + } + id, err := parse.AssignmentID(rs.Primary.ID) + if err != nil { + return err + } + + client := acceptance.AzureProvider.Meta().(*clients.Client).Blueprints.AssignmentsClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + if resp, err := client.Get(ctx, id.Scope, id.Name); err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Blueprint Assignment %q (scope %q) was not found", id.Name, id.Scope) + } + return fmt.Errorf("Bad: Get on Blueprint Assignment %q (scope %q): %+v", id.Name, id.Scope, err) + } + return nil + } +} + +func testCheckAzureRMBlueprintAssignmentDestroy(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).Blueprints.AssignmentsClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_blueprint_assignment" { + continue + } + + id, err := parse.AssignmentID(rs.Primary.ID) + if err != nil { + return err + } + + if resp, err := client.Get(ctx, id.Scope, id.Name); err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Get on Blueprint.AssignmentClient: %+v", err) + } + } + + return nil + } + + return nil +} + +// This test is intentionally broken as the AccTest environment is not currently capable of supporting this test +func testAccBlueprintAssignment_basic(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" {} + +data "azurerm_blueprint_definition" "test" { + name = "testAcc_basicSubscription" + scope_type = "subscription" + scope_name = data.azurerm_client_config.current.subscription_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 = "testAcc" +} + +resource "azurerm_blueprint_assignment" "test" { + # name = "testAccBPAssignment" + scope_type = "subscription" + scope = data.azurerm_client_config.current.subscription_id + location = "%s" + identity { + type = "UserAssigned" + user_assigned_identities = ["00000000-0000-0000-0000-000000000000"] + } + version_id = data.azurerm_blueprint_published_version.test.id +} +`, 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 new file mode 100644 index 000000000000..f8df37ea4387 --- /dev/null +++ b/azurerm/internal/services/blueprints/tests/blueprint_definition_data_source_test.go @@ -0,0 +1,88 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +// lintignore:AT001 +func TestAccDataSourceBlueprintDefinition_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_blueprint_definition", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceBlueprintDefinition_basic(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "description", "Acceptance Test stub for Blueprints at Subscription"), + resource.TestCheckResourceAttr(data.ResourceName, "name", "testAcc_basicSubscription"), + resource.TestCheckResourceAttrSet(data.ResourceName, "last_modified"), + resource.TestCheckResourceAttr(data.ResourceName, "target_scope", "subscription"), + resource.TestCheckResourceAttrSet(data.ResourceName, "time_created"), + ), + }, + }, + }) +} + +// lintignore:AT001 +func TestAccDataSourceBlueprintDefinition_basicAtManagementGroup(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_blueprint_definition", "test") + + // TODO - Update when the AccTest environment is capable of supporting MG level testing. For now this will fail. + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceBlueprintDefinition_basicAtManagementGroup("SomeGroup"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(data.ResourceName, "time_created"), + resource.TestCheckResourceAttrSet(data.ResourceName, "last_modified"), + resource.TestCheckResourceAttrSet(data.ResourceName, "target_scope"), + resource.TestCheckResourceAttrSet(data.ResourceName, "type"), + ), + }, + }, + }) +} + +func testAccDataSourceBlueprintDefinition_basic() string { + return ` +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" {} + +data "azurerm_blueprint_definition" "test" { + name = "testAcc_basicSubscription" + scope_type = "subscription" + scope_name = data.azurerm_client_config.current.subscription_id +} + +` +} + +func testAccDataSourceBlueprintDefinition_basicAtManagementGroup(managementGroup string) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" {} + +data "azurerm_blueprint_definition" "test" { + name = "simpleBlueprint" + scope_type = "managementGroup" + scope_name = %s +} + +`, managementGroup) +} diff --git a/azurerm/internal/services/blueprints/tests/blueprint_published_version_datasource_test.go b/azurerm/internal/services/blueprints/tests/blueprint_published_version_data_source_test.go similarity index 98% rename from azurerm/internal/services/blueprints/tests/blueprint_published_version_datasource_test.go rename to azurerm/internal/services/blueprints/tests/blueprint_published_version_data_source_test.go index dacac9242ee8..a9d74356aeff 100644 --- a/azurerm/internal/services/blueprints/tests/blueprint_published_version_datasource_test.go +++ b/azurerm/internal/services/blueprints/tests/blueprint_published_version_data_source_test.go @@ -8,6 +8,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) +// lintignore:AT001 func TestAccDataSourceBlueprintPublishedVersion_basicSubscription(t *testing.T) { data := acceptance.BuildTestData(t, "data.azurerm_blueprint_published_version", "test") diff --git a/azurerm/internal/services/blueprints/validate/blueprint.go b/azurerm/internal/services/blueprints/validate/blueprint.go index 49d3b4345669..16bb84203515 100644 --- a/azurerm/internal/services/blueprints/validate/blueprint.go +++ b/azurerm/internal/services/blueprints/validate/blueprint.go @@ -2,6 +2,7 @@ package validate import ( "fmt" + "regexp" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/blueprints/parse" ) @@ -20,3 +21,16 @@ func BlueprintID(i interface{}, k string) (warnings []string, errors []error) { return warnings, errors } + +func BlueprintName(i interface{}, k string) (warnings []string, errors []error) { + v, ok := i.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected type of %q to be string", k)) + return + } + + 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 +} diff --git a/website/azurerm.erb b/website/azurerm.erb index 6258968f384a..e0339a2a2b92 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -153,6 +153,14 @@ azurerm_batch_pool +
  • + azurerm_blueprint_definition +
  • + +
  • + azurerm_blueprint_published_version +
  • +
  • azurerm_cdn_profile
  • @@ -971,6 +979,16 @@ +
  • + Blueprints Resources + +
  • +
  • Bot Resources