From 5b3a1bf3d36e8d63974c67a83685056867c5797a Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Thu, 17 Nov 2022 14:54:45 +0800 Subject: [PATCH 01/27] initial commit with typed resource `azurerm_automanage_configuration_profile` --- internal/clients/client.go | 3 + internal/provider/services.go | 2 + ...tomanage_configuration_profile_resource.go | 229 ++++++ ...age_configuration_profile_resource_test.go | 214 ++++++ internal/services/automanage/client/client.go | 29 + .../parse/automanage_configuration_profile.go | 69 ++ .../automanage_configuration_profile_test.go | 112 +++ internal/services/automanage/registration.go | 51 ++ internal/services/automanage/resourceid.go | 4 + .../automanage_configuration_profile_id.go | 23 + ...utomanage_configuration_profile_id_test.go | 76 ++ .../2022-05-04/automanage/bestpractices.go | 172 +++++ .../automanage/bestpracticesversions.go | 181 +++++ .../2022-05-04/automanage/client.go | 41 + .../configurationprofileassignments.go | 715 ++++++++++++++++++ .../configurationprofilehciassignments.go | 301 ++++++++ .../configurationprofilehcrpassignments.go | 301 ++++++++ .../automanage/configurationprofiles.go | 540 +++++++++++++ .../configurationprofilesversions.go | 383 ++++++++++ .../automanage/2022-05-04/automanage/enums.go | 56 ++ .../2022-05-04/automanage/hcireports.go | 209 +++++ .../2022-05-04/automanage/hcrpreports.go | 209 +++++ .../2022-05-04/automanage/models.go | 687 +++++++++++++++++ .../2022-05-04/automanage/operations.go | 99 +++ .../2022-05-04/automanage/reports.go | 209 +++++ .../automanage/serviceprincipals.go | 188 +++++ .../2022-05-04/automanage/version.go | 19 + vendor/modules.txt | 1 + ...anage_configuration_profiles.html.markdown | 78 ++ 29 files changed, 5201 insertions(+) create mode 100644 internal/services/automanage/automanage_configuration_profile_resource.go create mode 100644 internal/services/automanage/automanage_configuration_profile_resource_test.go create mode 100644 internal/services/automanage/client/client.go create mode 100644 internal/services/automanage/parse/automanage_configuration_profile.go create mode 100644 internal/services/automanage/parse/automanage_configuration_profile_test.go create mode 100644 internal/services/automanage/registration.go create mode 100644 internal/services/automanage/resourceid.go create mode 100644 internal/services/automanage/validate/automanage_configuration_profile_id.go create mode 100644 internal/services/automanage/validate/automanage_configuration_profile_id_test.go create mode 100644 vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/bestpractices.go create mode 100644 vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/bestpracticesversions.go create mode 100644 vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/client.go create mode 100644 vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/configurationprofileassignments.go create mode 100644 vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/configurationprofilehciassignments.go create mode 100644 vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/configurationprofilehcrpassignments.go create mode 100644 vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/configurationprofiles.go create mode 100644 vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/configurationprofilesversions.go create mode 100644 vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/enums.go create mode 100644 vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/hcireports.go create mode 100644 vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/hcrpreports.go create mode 100644 vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/models.go create mode 100644 vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/operations.go create mode 100644 vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/reports.go create mode 100644 vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/serviceprincipals.go create mode 100644 vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/version.go create mode 100644 website/docs/r/automanage_configuration_profiles.html.markdown diff --git a/internal/clients/client.go b/internal/clients/client.go index 16a104039f9d..2713795ca084 100644 --- a/internal/clients/client.go +++ b/internal/clients/client.go @@ -21,6 +21,7 @@ import ( appService "github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/client" attestation "github.com/hashicorp/terraform-provider-azurerm/internal/services/attestation/client" authorization "github.com/hashicorp/terraform-provider-azurerm/internal/services/authorization/client" + automanage "github.com/hashicorp/terraform-provider-azurerm/internal/services/automanage/client" automation "github.com/hashicorp/terraform-provider-azurerm/internal/services/automation/client" azureStackHCI "github.com/hashicorp/terraform-provider-azurerm/internal/services/azurestackhci/client" batch "github.com/hashicorp/terraform-provider-azurerm/internal/services/batch/client" @@ -139,6 +140,7 @@ type Client struct { AppService *appService.Client Attestation *attestation.Client Authorization *authorization.Client + AutoManage *automanage.Client Automation *automation.Client AzureStackHCI *azureStackHCI.Client Batch *batch.Client @@ -261,6 +263,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error client.AppService = appService.NewClient(o) client.Attestation = attestation.NewClient(o) client.Authorization = authorization.NewClient(o) + client.AutoManage = automanage.NewClient(o) client.Automation = automation.NewClient(o) client.AzureStackHCI = azureStackHCI.NewClient(o) client.Batch = batch.NewClient(o) diff --git a/internal/provider/services.go b/internal/provider/services.go index 3f04cdd0e438..3be6c77d0c4c 100644 --- a/internal/provider/services.go +++ b/internal/provider/services.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice" "github.com/hashicorp/terraform-provider-azurerm/internal/services/attestation" "github.com/hashicorp/terraform-provider-azurerm/internal/services/authorization" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/automanage" "github.com/hashicorp/terraform-provider-azurerm/internal/services/automation" "github.com/hashicorp/terraform-provider-azurerm/internal/services/azurestackhci" "github.com/hashicorp/terraform-provider-azurerm/internal/services/batch" @@ -121,6 +122,7 @@ func SupportedTypedServices() []sdk.TypedServiceRegistration { appconfiguration.Registration{}, applicationinsights.Registration{}, appservice.Registration{}, + automanage.Registration{}, automation.Registration{}, batch.Registration{}, bot.Registration{}, diff --git a/internal/services/automanage/automanage_configuration_profile_resource.go b/internal/services/automanage/automanage_configuration_profile_resource.go new file mode 100644 index 000000000000..4b0278740298 --- /dev/null +++ b/internal/services/automanage/automanage_configuration_profile_resource.go @@ -0,0 +1,229 @@ +package automanage + +import ( + "context" + "encoding/json" + "fmt" + "time" + + "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/location" + "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/automanage/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/automanage/validate" + "github.com/hashicorp/terraform-provider-azurerm/internal/tags" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" + "github.com/hashicorp/terraform-provider-azurerm/utils" + "github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage" +) + +type AutoManageConfigurationProfileModel struct { + Name string `tfschema:"name"` + ResourceGroupName string `tfschema:"resource_group_name"` + Configuration string `tfschema:"configuration_json"` + Location string `tfschema:"location"` + Tags map[string]string `tfschema:"tags"` +} + +type AutoManageConfigurationProfileResource struct{} + +var _ sdk.ResourceWithUpdate = AutoManageConfigurationProfileResource{} + +func (r AutoManageConfigurationProfileResource) ResourceType() string { + return "azurerm_automanage_configuration_profile" +} + +func (r AutoManageConfigurationProfileResource) ModelObject() interface{} { + return &AutoManageConfigurationProfileModel{} +} + +func (r AutoManageConfigurationProfileResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { + return validate.AutomanageConfigurationProfileID +} + +func (r AutoManageConfigurationProfileResource) Arguments() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "resource_group_name": commonschema.ResourceGroupName(), + + "location": commonschema.Location(), + + "configuration_json": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringIsJSON, + DiffSuppressFunc: pluginsdk.SuppressJsonDiff, + }, + + "tags": commonschema.Tags(), + } +} + +func (r AutoManageConfigurationProfileResource) Attributes() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{} +} + +func (r AutoManageConfigurationProfileResource) Create() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + var model AutoManageConfigurationProfileModel + if err := metadata.Decode(&model); err != nil { + return fmt.Errorf("decoding: %+v", err) + } + + client := metadata.Client.AutoManage.ConfigurationProfileClient + subscriptionId := metadata.Client.Account.SubscriptionId + id := parse.NewAutomanageConfigurationProfileID(subscriptionId, model.ResourceGroupName, model.Name) + existing, err := client.Get(ctx, id.ConfigurationProfileName, id.ResourceGroup) + if err != nil && !response.WasNotFound(existing.Response.Response) { + return fmt.Errorf("checking for existing %s: %+v", id, err) + } + + if !response.WasNotFound(existing.Response.Response) { + return metadata.ResourceRequiresImport(r.ResourceType(), id) + } + + properties := automanage.ConfigurationProfile{ + Location: utils.String(location.Normalize(model.Location)), + Properties: &automanage.ConfigurationProfileProperties{}, + Tags: tags.FromTypedObject(model.Tags), + } + + if model.Configuration != "" { + var configurationValue interface{} + err = json.Unmarshal([]byte(model.Configuration), &configurationValue) + if err != nil { + return err + } + properties.Properties.Configuration = &configurationValue + } + + if _, err := client.CreateOrUpdate(ctx, id.ConfigurationProfileName, id.ResourceGroup, properties); err != nil { + return fmt.Errorf("creating %s: %+v", id, err) + } + + metadata.SetID(id) + return nil + }, + } +} + +func (r AutoManageConfigurationProfileResource) Update() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.AutoManage.ConfigurationProfileClient + + id, err := parse.AutomanageConfigurationProfileID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + var model AutoManageConfigurationProfileModel + if err := metadata.Decode(&model); err != nil { + return fmt.Errorf("decoding: %+v", err) + } + + resp, err := client.Get(ctx, id.ConfigurationProfileName, id.ResourceGroup) + if err != nil { + return fmt.Errorf("retrieving %s: %+v", *id, err) + } + + if metadata.ResourceData.HasChange("configuration_json") { + var configurationValue interface{} + err := json.Unmarshal([]byte(model.Configuration), &configurationValue) + if err != nil { + return err + } + + resp.Properties.Configuration = &configurationValue + } + + resp.SystemData = nil + + if metadata.ResourceData.HasChange("tags") { + resp.Tags = tags.FromTypedObject(model.Tags) + } + + if _, err := client.CreateOrUpdate(ctx, id.ConfigurationProfileName, id.ResourceGroup, resp); err != nil { + return fmt.Errorf("updating %s: %+v", *id, err) + } + + return nil + }, + } +} + +func (r AutoManageConfigurationProfileResource) Read() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 5 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.AutoManage.ConfigurationProfileClient + + id, err := parse.AutomanageConfigurationProfileID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + resp, err := client.Get(ctx, id.ConfigurationProfileName, id.ResourceGroup) + if err != nil { + if response.WasNotFound(resp.Response.Response) { + return metadata.MarkAsGone(id) + } + + return fmt.Errorf("retrieving %s: %+v", *id, err) + } + + state := AutoManageConfigurationProfileModel{ + Name: id.ConfigurationProfileName, + ResourceGroupName: id.ResourceGroup, + Location: location.NormalizeNilable(resp.Location), + } + + if properties := resp.Properties; properties != nil { + if properties.Configuration != nil { + configurationValue, err := json.Marshal(properties.Configuration) + if err != nil { + return err + } + + state.Configuration = string(configurationValue) + } + } + if resp.Tags != nil { + state.Tags = tags.ToTypedObject(resp.Tags) + } + + return metadata.Encode(&state) + }, + } +} + +func (r AutoManageConfigurationProfileResource) Delete() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.AutoManage.ConfigurationProfileClient + + id, err := parse.AutomanageConfigurationProfileID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + if _, err := client.Delete(ctx, id.ResourceGroup, id.ConfigurationProfileName); err != nil { + return fmt.Errorf("deleting %s: %+v", id, err) + } + + return nil + }, + } +} diff --git a/internal/services/automanage/automanage_configuration_profile_resource_test.go b/internal/services/automanage/automanage_configuration_profile_resource_test.go new file mode 100644 index 000000000000..751be03c822a --- /dev/null +++ b/internal/services/automanage/automanage_configuration_profile_resource_test.go @@ -0,0 +1,214 @@ +package automanage_test + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" + "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/automanage/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +type AutoManageConfigurationProfileResource struct{} + +func TestAccAutoManageConfigurationProfile_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_automanage_configuration_profile", "test") + r := AutoManageConfigurationProfileResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccAutoManageConfigurationProfile_requiresImport(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_automanage_configuration_profile", "test") + r := AutoManageConfigurationProfileResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.RequiresImportErrorStep(r.requiresImport), + }) +} + +func TestAccAutoManageConfigurationProfile_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_automanage_configuration_profile", "test") + r := AutoManageConfigurationProfileResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccAutoManageConfigurationProfile_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_automanage_configuration_profile", "test") + r := AutoManageConfigurationProfileResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.update(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func (r AutoManageConfigurationProfileResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + id, err := parse.AutomanageConfigurationProfileID(state.ID) + if err != nil { + return nil, err + } + + client := clients.AutoManage.ConfigurationProfileClient + resp, err := client.Get(ctx, id.ConfigurationProfileName, id.ResourceGroup) + if err != nil { + if response.WasNotFound(resp.Response.Response) { + return utils.Bool(false), nil + } + return nil, fmt.Errorf("retrieving %s: %+v", id, err) + } + return utils.Bool(resp.Response.Response != nil), nil +} + +func (r AutoManageConfigurationProfileResource) template(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctest-rg-%d" + location = "%s" +} +`, data.RandomInteger, data.Locations.Primary) +} + +func (r AutoManageConfigurationProfileResource) basic(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` + %s + +resource "azurerm_automanage_configuration_profile" "test" { + name = "acctest-amcp-%d" + resource_group_name = azurerm_resource_group.test.name + location = "%s" + configuration_json = jsonencode({ + "Antimalware/Enable":false, + "AzureSecurityCenter/Enable":true, + "Backup/Enable":false, + "BootDiagnostics/Enable":true, + "ChangeTrackingAndInventory/Enable":true, + "GuestConfiguration/Enable":true, + "LogAnalytics/Enable":true, + "UpdateManagement/Enable":true, + "VMInsights/Enable":true + }) +} +`, template, data.RandomInteger, data.Locations.Primary) +} + +func (r AutoManageConfigurationProfileResource) requiresImport(data acceptance.TestData) string { + config := r.basic(data) + return fmt.Sprintf(` + %s + +resource "azurerm_automanage_configuration_profile" "import" { + name = azurerm_automanage_configuration_profile.test.name + resource_group_name = azurerm_resource_group.test.name + location = "%s" + configuration_json = jsonencode({ + "Antimalware/Enable":false, + "AzureSecurityCenter/Enable":true, + "Backup/Enable":false, + "BootDiagnostics/Enable":true, + "ChangeTrackingAndInventory/Enable":true, + "GuestConfiguration/Enable":true, + "LogAnalytics/Enable":true, + "UpdateManagement/Enable":true, + "VMInsights/Enable":true + }) +} +`, config, data.Locations.Primary) +} + +func (r AutoManageConfigurationProfileResource) complete(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` + %s + +resource "azurerm_automanage_configuration_profile" "test" { + name = "acctest-amcp-%d" + resource_group_name = azurerm_resource_group.test.name + location = "%s" + configuration_json = jsonencode({ + "Antimalware/Enable":false, + "AzureSecurityCenter/Enable":true, + "Backup/Enable":false, + "BootDiagnostics/Enable":true, + "ChangeTrackingAndInventory/Enable":true, + "GuestConfiguration/Enable":true, + "LogAnalytics/Enable":true, + "UpdateManagement/Enable":true, + "VMInsights/Enable":true + }) + tags = { + key = "value" + } + +} +`, template, data.RandomInteger, data.Locations.Primary) +} + +func (r AutoManageConfigurationProfileResource) update(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` + %s + +resource "azurerm_automanage_configuration_profile" "test" { + name = "acctest-amcp-%d" + resource_group_name = azurerm_resource_group.test.name + location = "%s" + configuration_json = jsonencode({ + "Antimalware/Enable":false, + "AzureSecurityCenter/Enable":true, + "Backup/Enable":true, + "BootDiagnostics/Enable":true, + "ChangeTrackingAndInventory/Enable":true, + "GuestConfiguration/Enable":true, + "LogAnalytics/Enable":true, + "UpdateManagement/Enable":true, + "VMInsights/Enable":true + }) + tags = { + key2 = "value2" + } + +} +`, template, data.RandomInteger, data.Locations.Primary) +} diff --git a/internal/services/automanage/client/client.go b/internal/services/automanage/client/client.go new file mode 100644 index 000000000000..8d93bf7d38a0 --- /dev/null +++ b/internal/services/automanage/client/client.go @@ -0,0 +1,29 @@ +package client + +import ( + "github.com/hashicorp/terraform-provider-azurerm/internal/common" + "github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage" +) + +type Client struct { + ConfigurationProfileClient *automanage.ConfigurationProfilesClient + ConfigurationProfileAssignmentClient *automanage.ConfigurationProfileAssignmentsClient + ConfigurationProfileHCIAssignmentClient *automanage.ConfigurationProfileHCIAssignmentsClient +} + +func NewClient(o *common.ClientOptions) *Client { + configurationProfileClient := automanage.NewConfigurationProfilesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) + o.ConfigureClient(&configurationProfileClient.Client, o.ResourceManagerAuthorizer) + + configurationProfileAssignmentClient := automanage.NewConfigurationProfileAssignmentsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) + o.ConfigureClient(&configurationProfileAssignmentClient.Client, o.ResourceManagerAuthorizer) + + configurationProfileHCIAssignmentClient := automanage.NewConfigurationProfileHCIAssignmentsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) + o.ConfigureClient(&configurationProfileHCIAssignmentClient.Client, o.ResourceManagerAuthorizer) + + return &Client{ + ConfigurationProfileClient: &configurationProfileClient, + ConfigurationProfileAssignmentClient: &configurationProfileAssignmentClient, + ConfigurationProfileHCIAssignmentClient: &configurationProfileHCIAssignmentClient, + } +} diff --git a/internal/services/automanage/parse/automanage_configuration_profile.go b/internal/services/automanage/parse/automanage_configuration_profile.go new file mode 100644 index 000000000000..865a2089eb37 --- /dev/null +++ b/internal/services/automanage/parse/automanage_configuration_profile.go @@ -0,0 +1,69 @@ +package parse + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +type AutomanageConfigurationProfileId struct { + SubscriptionId string + ResourceGroup string + ConfigurationProfileName string +} + +func NewAutomanageConfigurationProfileID(subscriptionId, resourceGroup, configurationProfileName string) AutomanageConfigurationProfileId { + return AutomanageConfigurationProfileId{ + SubscriptionId: subscriptionId, + ResourceGroup: resourceGroup, + ConfigurationProfileName: configurationProfileName, + } +} + +func (id AutomanageConfigurationProfileId) String() string { + segments := []string{ + fmt.Sprintf("Configuration Profile Name %q", id.ConfigurationProfileName), + fmt.Sprintf("Resource Group %q", id.ResourceGroup), + } + segmentsStr := strings.Join(segments, " / ") + return fmt.Sprintf("%s: (%s)", "Automanage Configuration Profile", segmentsStr) +} + +func (id AutomanageConfigurationProfileId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Automanage/configurationProfiles/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.ConfigurationProfileName) +} + +// AutomanageConfigurationProfileID parses a AutomanageConfigurationProfile ID into an AutomanageConfigurationProfileId struct +func AutomanageConfigurationProfileID(input string) (*AutomanageConfigurationProfileId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + resourceId := AutomanageConfigurationProfileId{ + SubscriptionId: id.SubscriptionID, + ResourceGroup: id.ResourceGroup, + } + + if resourceId.SubscriptionId == "" { + return nil, fmt.Errorf("ID was missing the 'subscriptions' element") + } + + if resourceId.ResourceGroup == "" { + return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") + } + + if resourceId.ConfigurationProfileName, err = id.PopSegment("configurationProfiles"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} diff --git a/internal/services/automanage/parse/automanage_configuration_profile_test.go b/internal/services/automanage/parse/automanage_configuration_profile_test.go new file mode 100644 index 000000000000..471a334a93e1 --- /dev/null +++ b/internal/services/automanage/parse/automanage_configuration_profile_test.go @@ -0,0 +1,112 @@ +package parse + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.Id = AutomanageConfigurationProfileId{} + +func TestAutomanageConfigurationProfileIDFormatter(t *testing.T) { + actual := NewAutomanageConfigurationProfileID("12345678-1234-9876-4563-123456789012", "resourceGroup1", "configurationProfile1").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.Automanage/configurationProfiles/configurationProfile1" + if actual != expected { + t.Fatalf("Expected %q but got %q", expected, actual) + } +} + +func TestAutomanageConfigurationProfileID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AutomanageConfigurationProfileId + }{ + + { + // empty + Input: "", + Error: true, + }, + + { + // missing SubscriptionId + Input: "/", + Error: true, + }, + + { + // missing value for SubscriptionId + Input: "/subscriptions/", + Error: true, + }, + + { + // missing ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", + Error: true, + }, + + { + // missing value for ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", + Error: true, + }, + + { + // missing ConfigurationProfileName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.Automanage/", + Error: true, + }, + + { + // missing value for ConfigurationProfileName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.Automanage/configurationProfiles/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.Automanage/configurationProfiles/configurationProfile1", + Expected: &AutomanageConfigurationProfileId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resourceGroup1", + ConfigurationProfileName: "configurationProfile1", + }, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESOURCEGROUP1/PROVIDERS/MICROSOFT.AUTOMANAGE/CONFIGURATIONPROFILES/CONFIGURATIONPROFILE1", + Error: true, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := AutomanageConfigurationProfileID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %s", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) + } + if actual.ConfigurationProfileName != v.Expected.ConfigurationProfileName { + t.Fatalf("Expected %q but got %q for ConfigurationProfileName", v.Expected.ConfigurationProfileName, actual.ConfigurationProfileName) + } + } +} diff --git a/internal/services/automanage/registration.go b/internal/services/automanage/registration.go new file mode 100644 index 000000000000..acccb86713b6 --- /dev/null +++ b/internal/services/automanage/registration.go @@ -0,0 +1,51 @@ +package automanage + +import ( + "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +type Registration struct{} + +var ( + _ sdk.TypedServiceRegistrationWithAGitHubLabel = Registration{} + _ sdk.UntypedServiceRegistrationWithAGitHubLabel = Registration{} +) + +func (r Registration) AssociatedGitHubLabel() string { + return "service/automanage" +} + +// Name is the name of this Service +func (r Registration) Name() string { + return "Automanage" +} + +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Automanage", + } +} + +// SupportedDataSources returns the supported Data Sources supported by this Service +func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{} +} + +// SupportedResources returns the supported Resources supported by this Service +func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{} +} + +// DataSources returns a list of Data Sources supported by this Service +func (r Registration) DataSources() []sdk.DataSource { + return []sdk.DataSource{} +} + +// Resources returns a list of Resources supported by this Service +func (r Registration) Resources() []sdk.Resource { + return []sdk.Resource{ + AutoManageConfigurationProfileResource{}, + } +} diff --git a/internal/services/automanage/resourceid.go b/internal/services/automanage/resourceid.go new file mode 100644 index 000000000000..016ba9f2009d --- /dev/null +++ b/internal/services/automanage/resourceid.go @@ -0,0 +1,4 @@ +package automanage + +// leaving the Automanage prefix here to avoid stuttering the property name for now +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=AutomanageConfigurationProfile -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.Automanage/configurationProfiles/configurationProfile1 diff --git a/internal/services/automanage/validate/automanage_configuration_profile_id.go b/internal/services/automanage/validate/automanage_configuration_profile_id.go new file mode 100644 index 000000000000..bebe6e519a10 --- /dev/null +++ b/internal/services/automanage/validate/automanage_configuration_profile_id.go @@ -0,0 +1,23 @@ +package validate + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import ( + "fmt" + + "github.com/hashicorp/terraform-provider-azurerm/internal/services/automanage/parse" +) + +func AutomanageConfigurationProfileID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := parse.AutomanageConfigurationProfileID(v); err != nil { + errors = append(errors, err) + } + + return +} diff --git a/internal/services/automanage/validate/automanage_configuration_profile_id_test.go b/internal/services/automanage/validate/automanage_configuration_profile_id_test.go new file mode 100644 index 000000000000..44cfb320d04f --- /dev/null +++ b/internal/services/automanage/validate/automanage_configuration_profile_id_test.go @@ -0,0 +1,76 @@ +package validate + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import "testing" + +func TestAutomanageConfigurationProfileID(t *testing.T) { + cases := []struct { + Input string + Valid bool + }{ + + { + // empty + Input: "", + Valid: false, + }, + + { + // missing SubscriptionId + Input: "/", + Valid: false, + }, + + { + // missing value for SubscriptionId + Input: "/subscriptions/", + Valid: false, + }, + + { + // missing ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", + Valid: false, + }, + + { + // missing value for ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", + Valid: false, + }, + + { + // missing ConfigurationProfileName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.Automanage/", + Valid: false, + }, + + { + // missing value for ConfigurationProfileName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.Automanage/configurationProfiles/", + Valid: false, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.Automanage/configurationProfiles/configurationProfile1", + Valid: true, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESOURCEGROUP1/PROVIDERS/MICROSOFT.AUTOMANAGE/CONFIGURATIONPROFILES/CONFIGURATIONPROFILE1", + Valid: false, + }, + } + for _, tc := range cases { + t.Logf("[DEBUG] Testing Value %s", tc.Input) + _, errors := AutomanageConfigurationProfileID(tc.Input, "test") + valid := len(errors) == 0 + + if tc.Valid != valid { + t.Fatalf("Expected %t but got %t", tc.Valid, valid) + } + } +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/bestpractices.go b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/bestpractices.go new file mode 100644 index 000000000000..30091eb1fff6 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/bestpractices.go @@ -0,0 +1,172 @@ +package automanage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/tracing" +) + +// BestPracticesClient is the automanage Client +type BestPracticesClient struct { + BaseClient +} + +// NewBestPracticesClient creates an instance of the BestPracticesClient client. +func NewBestPracticesClient(subscriptionID string) BestPracticesClient { + return NewBestPracticesClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewBestPracticesClientWithBaseURI creates an instance of the BestPracticesClient 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 NewBestPracticesClientWithBaseURI(baseURI string, subscriptionID string) BestPracticesClient { + return BestPracticesClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// Get get information about a Automanage best practice +// Parameters: +// bestPracticeName - the Automanage best practice name. +func (client BestPracticesClient) Get(ctx context.Context, bestPracticeName string) (result BestPractice, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/BestPracticesClient.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, bestPracticeName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.BestPracticesClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.BestPracticesClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.BestPracticesClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client BestPracticesClient) GetPreparer(ctx context.Context, bestPracticeName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "bestPracticeName": autorest.Encode("path", bestPracticeName), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Automanage/bestPractices/{bestPracticeName}", 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 BestPracticesClient) 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 BestPracticesClient) GetResponder(resp *http.Response) (result BestPractice, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListByTenant retrieve a list of Automanage best practices +func (client BestPracticesClient) ListByTenant(ctx context.Context) (result BestPracticeList, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/BestPracticesClient.ListByTenant") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.ListByTenantPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.BestPracticesClient", "ListByTenant", nil, "Failure preparing request") + return + } + + resp, err := client.ListByTenantSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.BestPracticesClient", "ListByTenant", resp, "Failure sending request") + return + } + + result, err = client.ListByTenantResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.BestPracticesClient", "ListByTenant", resp, "Failure responding to request") + return + } + + return +} + +// ListByTenantPreparer prepares the ListByTenant request. +func (client BestPracticesClient) ListByTenantPreparer(ctx context.Context) (*http.Request, error) { + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPath("/providers/Microsoft.Automanage/bestPractices"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListByTenantSender sends the ListByTenant request. The method will close the +// http.Response Body if it receives an error. +func (client BestPracticesClient) ListByTenantSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListByTenantResponder handles the response to the ListByTenant request. The method always +// closes the http.Response Body. +func (client BestPracticesClient) ListByTenantResponder(resp *http.Response) (result BestPracticeList, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/bestpracticesversions.go b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/bestpracticesversions.go new file mode 100644 index 000000000000..a664fdde5a2a --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/bestpracticesversions.go @@ -0,0 +1,181 @@ +package automanage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/tracing" +) + +// BestPracticesVersionsClient is the automanage Client +type BestPracticesVersionsClient struct { + BaseClient +} + +// NewBestPracticesVersionsClient creates an instance of the BestPracticesVersionsClient client. +func NewBestPracticesVersionsClient(subscriptionID string) BestPracticesVersionsClient { + return NewBestPracticesVersionsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewBestPracticesVersionsClientWithBaseURI creates an instance of the BestPracticesVersionsClient 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 NewBestPracticesVersionsClientWithBaseURI(baseURI string, subscriptionID string) BestPracticesVersionsClient { + return BestPracticesVersionsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// Get get information about a Automanage best practice version +// Parameters: +// bestPracticeName - the Automanage best practice name. +// versionName - the Automanage best practice version name. +func (client BestPracticesVersionsClient) Get(ctx context.Context, bestPracticeName string, versionName string) (result BestPractice, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/BestPracticesVersionsClient.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, bestPracticeName, versionName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.BestPracticesVersionsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.BestPracticesVersionsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.BestPracticesVersionsClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client BestPracticesVersionsClient) GetPreparer(ctx context.Context, bestPracticeName string, versionName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "bestPracticeName": autorest.Encode("path", bestPracticeName), + "versionName": autorest.Encode("path", versionName), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Automanage/bestPractices/{bestPracticeName}/versions/{versionName}", 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 BestPracticesVersionsClient) 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 BestPracticesVersionsClient) GetResponder(resp *http.Response) (result BestPractice, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListByTenant retrieve a list of Automanage best practices versions +// Parameters: +// bestPracticeName - the Automanage best practice name. +func (client BestPracticesVersionsClient) ListByTenant(ctx context.Context, bestPracticeName string) (result BestPracticeList, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/BestPracticesVersionsClient.ListByTenant") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.ListByTenantPreparer(ctx, bestPracticeName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.BestPracticesVersionsClient", "ListByTenant", nil, "Failure preparing request") + return + } + + resp, err := client.ListByTenantSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.BestPracticesVersionsClient", "ListByTenant", resp, "Failure sending request") + return + } + + result, err = client.ListByTenantResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.BestPracticesVersionsClient", "ListByTenant", resp, "Failure responding to request") + return + } + + return +} + +// ListByTenantPreparer prepares the ListByTenant request. +func (client BestPracticesVersionsClient) ListByTenantPreparer(ctx context.Context, bestPracticeName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "bestPracticeName": autorest.Encode("path", bestPracticeName), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Automanage/bestPractices/{bestPracticeName}/versions", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListByTenantSender sends the ListByTenant request. The method will close the +// http.Response Body if it receives an error. +func (client BestPracticesVersionsClient) ListByTenantSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListByTenantResponder handles the response to the ListByTenant request. The method always +// closes the http.Response Body. +func (client BestPracticesVersionsClient) ListByTenantResponder(resp *http.Response) (result BestPracticeList, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/client.go b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/client.go new file mode 100644 index 000000000000..6f3c1e593838 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/client.go @@ -0,0 +1,41 @@ +// Package automanage implements the Azure ARM Automanage service API version 2022-05-04. +// +// Automanage Client +package automanage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// 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 Automanage + DefaultBaseURI = "https://management.azure.com" +) + +// BaseClient is the base client for Automanage. +type BaseClient struct { + autorest.Client + BaseURI string + SubscriptionID string +} + +// New creates an instance of the BaseClient client. +func New(subscriptionID string) BaseClient { + return NewWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// 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, subscriptionID string) BaseClient { + return BaseClient{ + Client: autorest.NewClientWithUserAgent(UserAgent()), + BaseURI: baseURI, + SubscriptionID: subscriptionID, + } +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/configurationprofileassignments.go b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/configurationprofileassignments.go new file mode 100644 index 000000000000..47a16dc052d4 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/configurationprofileassignments.go @@ -0,0 +1,715 @@ +package automanage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "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" +) + +// ConfigurationProfileAssignmentsClient is the automanage Client +type ConfigurationProfileAssignmentsClient struct { + BaseClient +} + +// NewConfigurationProfileAssignmentsClient creates an instance of the ConfigurationProfileAssignmentsClient client. +func NewConfigurationProfileAssignmentsClient(subscriptionID string) ConfigurationProfileAssignmentsClient { + return NewConfigurationProfileAssignmentsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewConfigurationProfileAssignmentsClientWithBaseURI creates an instance of the ConfigurationProfileAssignmentsClient +// 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 NewConfigurationProfileAssignmentsClientWithBaseURI(baseURI string, subscriptionID string) ConfigurationProfileAssignmentsClient { + return ConfigurationProfileAssignmentsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// CreateOrUpdate creates an association between a VM and Automanage configuration profile +// Parameters: +// configurationProfileAssignmentName - name of the configuration profile assignment. Only default is +// supported. +// parameters - parameters supplied to the create or update configuration profile assignment. +// resourceGroupName - the name of the resource group. The name is case insensitive. +// VMName - the name of the virtual machine. +func (client ConfigurationProfileAssignmentsClient) CreateOrUpdate(ctx context.Context, configurationProfileAssignmentName string, parameters ConfigurationProfileAssignment, resourceGroupName string, VMName string) (result ConfigurationProfileAssignment, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationProfileAssignmentsClient.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: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ConfigurationProfileAssignmentsClient", "CreateOrUpdate", err.Error()) + } + + req, err := client.CreateOrUpdatePreparer(ctx, configurationProfileAssignmentName, parameters, resourceGroupName, VMName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileAssignmentsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileAssignmentsClient", "CreateOrUpdate", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileAssignmentsClient", "CreateOrUpdate", resp, "Failure responding to request") + return + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client ConfigurationProfileAssignmentsClient) CreateOrUpdatePreparer(ctx context.Context, configurationProfileAssignmentName string, parameters ConfigurationProfileAssignment, resourceGroupName string, VMName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "configurationProfileAssignmentName": autorest.Encode("path", configurationProfileAssignmentName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + "vmName": autorest.Encode("path", VMName), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + parameters.ManagedBy = nil + parameters.SystemData = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/providers/Microsoft.Automanage/configurationProfileAssignments/{configurationProfileAssignmentName}", pathParameters), + autorest.WithJSON(parameters), + 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 ConfigurationProfileAssignmentsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client ConfigurationProfileAssignmentsClient) CreateOrUpdateResponder(resp *http.Response) (result ConfigurationProfileAssignment, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete delete a configuration profile assignment +// Parameters: +// resourceGroupName - the name of the resource group. The name is case insensitive. +// configurationProfileAssignmentName - name of the configuration profile assignment +// VMName - the name of the virtual machine. +func (client ConfigurationProfileAssignmentsClient) Delete(ctx context.Context, resourceGroupName string, configurationProfileAssignmentName string, VMName string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationProfileAssignmentsClient.Delete") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ConfigurationProfileAssignmentsClient", "Delete", err.Error()) + } + + req, err := client.DeletePreparer(ctx, resourceGroupName, configurationProfileAssignmentName, VMName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileAssignmentsClient", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileAssignmentsClient", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileAssignmentsClient", "Delete", resp, "Failure responding to request") + return + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client ConfigurationProfileAssignmentsClient) DeletePreparer(ctx context.Context, resourceGroupName string, configurationProfileAssignmentName string, VMName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "configurationProfileAssignmentName": autorest.Encode("path", configurationProfileAssignmentName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + "vmName": autorest.Encode("path", VMName), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/providers/Microsoft.Automanage/configurationProfileAssignments/{configurationProfileAssignmentName}", 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 ConfigurationProfileAssignmentsClient) DeleteSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client ConfigurationProfileAssignmentsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Get get information about a configuration profile assignment +// Parameters: +// resourceGroupName - the name of the resource group. The name is case insensitive. +// configurationProfileAssignmentName - the configuration profile assignment name. +// VMName - the name of the virtual machine. +func (client ConfigurationProfileAssignmentsClient) Get(ctx context.Context, resourceGroupName string, configurationProfileAssignmentName string, VMName string) (result ConfigurationProfileAssignment, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationProfileAssignmentsClient.Get") + 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: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ConfigurationProfileAssignmentsClient", "Get", err.Error()) + } + + req, err := client.GetPreparer(ctx, resourceGroupName, configurationProfileAssignmentName, VMName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileAssignmentsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileAssignmentsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileAssignmentsClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client ConfigurationProfileAssignmentsClient) GetPreparer(ctx context.Context, resourceGroupName string, configurationProfileAssignmentName string, VMName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "configurationProfileAssignmentName": autorest.Encode("path", configurationProfileAssignmentName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + "vmName": autorest.Encode("path", VMName), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/providers/Microsoft.Automanage/configurationProfileAssignments/{configurationProfileAssignmentName}", 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 ConfigurationProfileAssignmentsClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client ConfigurationProfileAssignmentsClient) GetResponder(resp *http.Response) (result ConfigurationProfileAssignment, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List get list of configuration profile assignments +// Parameters: +// resourceGroupName - the name of the resource group. The name is case insensitive. +func (client ConfigurationProfileAssignmentsClient) List(ctx context.Context, resourceGroupName string) (result ConfigurationProfileAssignmentList, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationProfileAssignmentsClient.List") + 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: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ConfigurationProfileAssignmentsClient", "List", err.Error()) + } + + req, err := client.ListPreparer(ctx, resourceGroupName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileAssignmentsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileAssignmentsClient", "List", resp, "Failure sending request") + return + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileAssignmentsClient", "List", resp, "Failure responding to request") + return + } + + return +} + +// ListPreparer prepares the List request. +func (client ConfigurationProfileAssignmentsClient) ListPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automanage/configurationProfileAssignments", 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 ConfigurationProfileAssignmentsClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client ConfigurationProfileAssignmentsClient) ListResponder(resp *http.Response) (result ConfigurationProfileAssignmentList, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListByClusterName get list of configuration profile assignments +// Parameters: +// resourceGroupName - the name of the resource group. The name is case insensitive. +// clusterName - the name of the Arc machine. +func (client ConfigurationProfileAssignmentsClient) ListByClusterName(ctx context.Context, resourceGroupName string, clusterName string) (result ConfigurationProfileAssignmentList, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationProfileAssignmentsClient.ListByClusterName") + 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: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ConfigurationProfileAssignmentsClient", "ListByClusterName", err.Error()) + } + + req, err := client.ListByClusterNamePreparer(ctx, resourceGroupName, clusterName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileAssignmentsClient", "ListByClusterName", nil, "Failure preparing request") + return + } + + resp, err := client.ListByClusterNameSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileAssignmentsClient", "ListByClusterName", resp, "Failure sending request") + return + } + + result, err = client.ListByClusterNameResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileAssignmentsClient", "ListByClusterName", resp, "Failure responding to request") + return + } + + return +} + +// ListByClusterNamePreparer prepares the ListByClusterName request. +func (client ConfigurationProfileAssignmentsClient) ListByClusterNamePreparer(ctx context.Context, resourceGroupName string, clusterName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "clusterName": autorest.Encode("path", clusterName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AzureStackHci/clusters/{clusterName}/providers/Microsoft.Automanage/configurationProfileAssignments", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListByClusterNameSender sends the ListByClusterName request. The method will close the +// http.Response Body if it receives an error. +func (client ConfigurationProfileAssignmentsClient) ListByClusterNameSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListByClusterNameResponder handles the response to the ListByClusterName request. The method always +// closes the http.Response Body. +func (client ConfigurationProfileAssignmentsClient) ListByClusterNameResponder(resp *http.Response) (result ConfigurationProfileAssignmentList, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListByMachineName get list of configuration profile assignments +// Parameters: +// resourceGroupName - the name of the resource group. The name is case insensitive. +// machineName - the name of the Arc machine. +func (client ConfigurationProfileAssignmentsClient) ListByMachineName(ctx context.Context, resourceGroupName string, machineName string) (result ConfigurationProfileAssignmentList, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationProfileAssignmentsClient.ListByMachineName") + 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: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ConfigurationProfileAssignmentsClient", "ListByMachineName", err.Error()) + } + + req, err := client.ListByMachineNamePreparer(ctx, resourceGroupName, machineName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileAssignmentsClient", "ListByMachineName", nil, "Failure preparing request") + return + } + + resp, err := client.ListByMachineNameSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileAssignmentsClient", "ListByMachineName", resp, "Failure sending request") + return + } + + result, err = client.ListByMachineNameResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileAssignmentsClient", "ListByMachineName", resp, "Failure responding to request") + return + } + + return +} + +// ListByMachineNamePreparer prepares the ListByMachineName request. +func (client ConfigurationProfileAssignmentsClient) ListByMachineNamePreparer(ctx context.Context, resourceGroupName string, machineName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "machineName": autorest.Encode("path", machineName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridCompute/machines/{machineName}/providers/Microsoft.Automanage/configurationProfileAssignments", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListByMachineNameSender sends the ListByMachineName request. The method will close the +// http.Response Body if it receives an error. +func (client ConfigurationProfileAssignmentsClient) ListByMachineNameSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListByMachineNameResponder handles the response to the ListByMachineName request. The method always +// closes the http.Response Body. +func (client ConfigurationProfileAssignmentsClient) ListByMachineNameResponder(resp *http.Response) (result ConfigurationProfileAssignmentList, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListBySubscription get list of configuration profile assignments under a given subscription +func (client ConfigurationProfileAssignmentsClient) ListBySubscription(ctx context.Context) (result ConfigurationProfileAssignmentList, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationProfileAssignmentsClient.ListBySubscription") + 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: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ConfigurationProfileAssignmentsClient", "ListBySubscription", err.Error()) + } + + req, err := client.ListBySubscriptionPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileAssignmentsClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + resp, err := client.ListBySubscriptionSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileAssignmentsClient", "ListBySubscription", resp, "Failure sending request") + return + } + + result, err = client.ListBySubscriptionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileAssignmentsClient", "ListBySubscription", resp, "Failure responding to request") + return + } + + return +} + +// ListBySubscriptionPreparer prepares the ListBySubscription request. +func (client ConfigurationProfileAssignmentsClient) ListBySubscriptionPreparer(ctx context.Context) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Automanage/configurationProfileAssignments", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListBySubscriptionSender sends the ListBySubscription request. The method will close the +// http.Response Body if it receives an error. +func (client ConfigurationProfileAssignmentsClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListBySubscriptionResponder handles the response to the ListBySubscription request. The method always +// closes the http.Response Body. +func (client ConfigurationProfileAssignmentsClient) ListBySubscriptionResponder(resp *http.Response) (result ConfigurationProfileAssignmentList, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListByVirtualMachines get list of configuration profile assignments +// Parameters: +// resourceGroupName - the name of the resource group. The name is case insensitive. +// VMName - the name of the virtual machine. +func (client ConfigurationProfileAssignmentsClient) ListByVirtualMachines(ctx context.Context, resourceGroupName string, VMName string) (result ConfigurationProfileAssignmentList, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationProfileAssignmentsClient.ListByVirtualMachines") + 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: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ConfigurationProfileAssignmentsClient", "ListByVirtualMachines", err.Error()) + } + + req, err := client.ListByVirtualMachinesPreparer(ctx, resourceGroupName, VMName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileAssignmentsClient", "ListByVirtualMachines", nil, "Failure preparing request") + return + } + + resp, err := client.ListByVirtualMachinesSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileAssignmentsClient", "ListByVirtualMachines", resp, "Failure sending request") + return + } + + result, err = client.ListByVirtualMachinesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileAssignmentsClient", "ListByVirtualMachines", resp, "Failure responding to request") + return + } + + return +} + +// ListByVirtualMachinesPreparer prepares the ListByVirtualMachines request. +func (client ConfigurationProfileAssignmentsClient) ListByVirtualMachinesPreparer(ctx context.Context, resourceGroupName string, VMName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + "vmName": autorest.Encode("path", VMName), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/providers/Microsoft.Automanage/configurationProfileAssignments", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListByVirtualMachinesSender sends the ListByVirtualMachines request. The method will close the +// http.Response Body if it receives an error. +func (client ConfigurationProfileAssignmentsClient) ListByVirtualMachinesSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListByVirtualMachinesResponder handles the response to the ListByVirtualMachines request. The method always +// closes the http.Response Body. +func (client ConfigurationProfileAssignmentsClient) ListByVirtualMachinesResponder(resp *http.Response) (result ConfigurationProfileAssignmentList, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/configurationprofilehciassignments.go b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/configurationprofilehciassignments.go new file mode 100644 index 000000000000..7ef8c7a85fe3 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/configurationprofilehciassignments.go @@ -0,0 +1,301 @@ +package automanage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "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" +) + +// ConfigurationProfileHCIAssignmentsClient is the automanage Client +type ConfigurationProfileHCIAssignmentsClient struct { + BaseClient +} + +// NewConfigurationProfileHCIAssignmentsClient creates an instance of the ConfigurationProfileHCIAssignmentsClient +// client. +func NewConfigurationProfileHCIAssignmentsClient(subscriptionID string) ConfigurationProfileHCIAssignmentsClient { + return NewConfigurationProfileHCIAssignmentsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewConfigurationProfileHCIAssignmentsClientWithBaseURI creates an instance of the +// ConfigurationProfileHCIAssignmentsClient 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 NewConfigurationProfileHCIAssignmentsClientWithBaseURI(baseURI string, subscriptionID string) ConfigurationProfileHCIAssignmentsClient { + return ConfigurationProfileHCIAssignmentsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// CreateOrUpdate creates an association between a AzureStackHCI cluster and Automanage configuration profile +// Parameters: +// parameters - parameters supplied to the create or update configuration profile assignment. +// resourceGroupName - the name of the resource group. The name is case insensitive. +// clusterName - the name of the Arc machine. +// configurationProfileAssignmentName - name of the configuration profile assignment. Only default is +// supported. +func (client ConfigurationProfileHCIAssignmentsClient) CreateOrUpdate(ctx context.Context, parameters ConfigurationProfileAssignment, resourceGroupName string, clusterName string, configurationProfileAssignmentName string) (result ConfigurationProfileAssignment, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationProfileHCIAssignmentsClient.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: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ConfigurationProfileHCIAssignmentsClient", "CreateOrUpdate", err.Error()) + } + + req, err := client.CreateOrUpdatePreparer(ctx, parameters, resourceGroupName, clusterName, configurationProfileAssignmentName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileHCIAssignmentsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileHCIAssignmentsClient", "CreateOrUpdate", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileHCIAssignmentsClient", "CreateOrUpdate", resp, "Failure responding to request") + return + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client ConfigurationProfileHCIAssignmentsClient) CreateOrUpdatePreparer(ctx context.Context, parameters ConfigurationProfileAssignment, resourceGroupName string, clusterName string, configurationProfileAssignmentName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "clusterName": autorest.Encode("path", clusterName), + "configurationProfileAssignmentName": autorest.Encode("path", configurationProfileAssignmentName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + parameters.ManagedBy = nil + parameters.SystemData = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AzureStackHci/clusters/{clusterName}/providers/Microsoft.Automanage/configurationProfileAssignments/{configurationProfileAssignmentName}", pathParameters), + autorest.WithJSON(parameters), + 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 ConfigurationProfileHCIAssignmentsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client ConfigurationProfileHCIAssignmentsClient) CreateOrUpdateResponder(resp *http.Response) (result ConfigurationProfileAssignment, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete delete a configuration profile assignment +// Parameters: +// resourceGroupName - the name of the resource group. The name is case insensitive. +// clusterName - the name of the Arc machine. +// configurationProfileAssignmentName - name of the configuration profile assignment +func (client ConfigurationProfileHCIAssignmentsClient) Delete(ctx context.Context, resourceGroupName string, clusterName string, configurationProfileAssignmentName string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationProfileHCIAssignmentsClient.Delete") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ConfigurationProfileHCIAssignmentsClient", "Delete", err.Error()) + } + + req, err := client.DeletePreparer(ctx, resourceGroupName, clusterName, configurationProfileAssignmentName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileHCIAssignmentsClient", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileHCIAssignmentsClient", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileHCIAssignmentsClient", "Delete", resp, "Failure responding to request") + return + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client ConfigurationProfileHCIAssignmentsClient) DeletePreparer(ctx context.Context, resourceGroupName string, clusterName string, configurationProfileAssignmentName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "clusterName": autorest.Encode("path", clusterName), + "configurationProfileAssignmentName": autorest.Encode("path", configurationProfileAssignmentName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AzureStackHci/clusters/{clusterName}/providers/Microsoft.Automanage/configurationProfileAssignments/{configurationProfileAssignmentName}", 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 ConfigurationProfileHCIAssignmentsClient) DeleteSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client ConfigurationProfileHCIAssignmentsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Get get information about a configuration profile assignment +// Parameters: +// resourceGroupName - the name of the resource group. The name is case insensitive. +// clusterName - the name of the Arc machine. +// configurationProfileAssignmentName - the configuration profile assignment name. +func (client ConfigurationProfileHCIAssignmentsClient) Get(ctx context.Context, resourceGroupName string, clusterName string, configurationProfileAssignmentName string) (result ConfigurationProfileAssignment, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationProfileHCIAssignmentsClient.Get") + 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: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ConfigurationProfileHCIAssignmentsClient", "Get", err.Error()) + } + + req, err := client.GetPreparer(ctx, resourceGroupName, clusterName, configurationProfileAssignmentName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileHCIAssignmentsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileHCIAssignmentsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileHCIAssignmentsClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client ConfigurationProfileHCIAssignmentsClient) GetPreparer(ctx context.Context, resourceGroupName string, clusterName string, configurationProfileAssignmentName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "clusterName": autorest.Encode("path", clusterName), + "configurationProfileAssignmentName": autorest.Encode("path", configurationProfileAssignmentName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AzureStackHci/clusters/{clusterName}/providers/Microsoft.Automanage/configurationProfileAssignments/{configurationProfileAssignmentName}", 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 ConfigurationProfileHCIAssignmentsClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client ConfigurationProfileHCIAssignmentsClient) GetResponder(resp *http.Response) (result ConfigurationProfileAssignment, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/configurationprofilehcrpassignments.go b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/configurationprofilehcrpassignments.go new file mode 100644 index 000000000000..e44b59f9e384 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/configurationprofilehcrpassignments.go @@ -0,0 +1,301 @@ +package automanage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "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" +) + +// ConfigurationProfileHCRPAssignmentsClient is the automanage Client +type ConfigurationProfileHCRPAssignmentsClient struct { + BaseClient +} + +// NewConfigurationProfileHCRPAssignmentsClient creates an instance of the ConfigurationProfileHCRPAssignmentsClient +// client. +func NewConfigurationProfileHCRPAssignmentsClient(subscriptionID string) ConfigurationProfileHCRPAssignmentsClient { + return NewConfigurationProfileHCRPAssignmentsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewConfigurationProfileHCRPAssignmentsClientWithBaseURI creates an instance of the +// ConfigurationProfileHCRPAssignmentsClient 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 NewConfigurationProfileHCRPAssignmentsClientWithBaseURI(baseURI string, subscriptionID string) ConfigurationProfileHCRPAssignmentsClient { + return ConfigurationProfileHCRPAssignmentsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// CreateOrUpdate creates an association between a ARC machine and Automanage configuration profile +// Parameters: +// parameters - parameters supplied to the create or update configuration profile assignment. +// resourceGroupName - the name of the resource group. The name is case insensitive. +// machineName - the name of the Arc machine. +// configurationProfileAssignmentName - name of the configuration profile assignment. Only default is +// supported. +func (client ConfigurationProfileHCRPAssignmentsClient) CreateOrUpdate(ctx context.Context, parameters ConfigurationProfileAssignment, resourceGroupName string, machineName string, configurationProfileAssignmentName string) (result ConfigurationProfileAssignment, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationProfileHCRPAssignmentsClient.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: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ConfigurationProfileHCRPAssignmentsClient", "CreateOrUpdate", err.Error()) + } + + req, err := client.CreateOrUpdatePreparer(ctx, parameters, resourceGroupName, machineName, configurationProfileAssignmentName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileHCRPAssignmentsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileHCRPAssignmentsClient", "CreateOrUpdate", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileHCRPAssignmentsClient", "CreateOrUpdate", resp, "Failure responding to request") + return + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client ConfigurationProfileHCRPAssignmentsClient) CreateOrUpdatePreparer(ctx context.Context, parameters ConfigurationProfileAssignment, resourceGroupName string, machineName string, configurationProfileAssignmentName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "configurationProfileAssignmentName": autorest.Encode("path", configurationProfileAssignmentName), + "machineName": autorest.Encode("path", machineName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + parameters.ManagedBy = nil + parameters.SystemData = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridCompute/machines/{machineName}/providers/Microsoft.Automanage/configurationProfileAssignments/{configurationProfileAssignmentName}", pathParameters), + autorest.WithJSON(parameters), + 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 ConfigurationProfileHCRPAssignmentsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client ConfigurationProfileHCRPAssignmentsClient) CreateOrUpdateResponder(resp *http.Response) (result ConfigurationProfileAssignment, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete delete a configuration profile assignment +// Parameters: +// resourceGroupName - the name of the resource group. The name is case insensitive. +// machineName - the name of the Arc machine. +// configurationProfileAssignmentName - name of the configuration profile assignment +func (client ConfigurationProfileHCRPAssignmentsClient) Delete(ctx context.Context, resourceGroupName string, machineName string, configurationProfileAssignmentName string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationProfileHCRPAssignmentsClient.Delete") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ConfigurationProfileHCRPAssignmentsClient", "Delete", err.Error()) + } + + req, err := client.DeletePreparer(ctx, resourceGroupName, machineName, configurationProfileAssignmentName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileHCRPAssignmentsClient", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileHCRPAssignmentsClient", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileHCRPAssignmentsClient", "Delete", resp, "Failure responding to request") + return + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client ConfigurationProfileHCRPAssignmentsClient) DeletePreparer(ctx context.Context, resourceGroupName string, machineName string, configurationProfileAssignmentName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "configurationProfileAssignmentName": autorest.Encode("path", configurationProfileAssignmentName), + "machineName": autorest.Encode("path", machineName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridCompute/machines/{machineName}/providers/Microsoft.Automanage/configurationProfileAssignments/{configurationProfileAssignmentName}", 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 ConfigurationProfileHCRPAssignmentsClient) DeleteSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client ConfigurationProfileHCRPAssignmentsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Get get information about a configuration profile assignment +// Parameters: +// resourceGroupName - the name of the resource group. The name is case insensitive. +// machineName - the name of the Arc machine. +// configurationProfileAssignmentName - the configuration profile assignment name. +func (client ConfigurationProfileHCRPAssignmentsClient) Get(ctx context.Context, resourceGroupName string, machineName string, configurationProfileAssignmentName string) (result ConfigurationProfileAssignment, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationProfileHCRPAssignmentsClient.Get") + 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: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ConfigurationProfileHCRPAssignmentsClient", "Get", err.Error()) + } + + req, err := client.GetPreparer(ctx, resourceGroupName, machineName, configurationProfileAssignmentName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileHCRPAssignmentsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileHCRPAssignmentsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfileHCRPAssignmentsClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client ConfigurationProfileHCRPAssignmentsClient) GetPreparer(ctx context.Context, resourceGroupName string, machineName string, configurationProfileAssignmentName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "configurationProfileAssignmentName": autorest.Encode("path", configurationProfileAssignmentName), + "machineName": autorest.Encode("path", machineName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridCompute/machines/{machineName}/providers/Microsoft.Automanage/configurationProfileAssignments/{configurationProfileAssignmentName}", 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 ConfigurationProfileHCRPAssignmentsClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client ConfigurationProfileHCRPAssignmentsClient) GetResponder(resp *http.Response) (result ConfigurationProfileAssignment, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/configurationprofiles.go b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/configurationprofiles.go new file mode 100644 index 000000000000..d26336dae0dc --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/configurationprofiles.go @@ -0,0 +1,540 @@ +package automanage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "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" +) + +// ConfigurationProfilesClient is the automanage Client +type ConfigurationProfilesClient struct { + BaseClient +} + +// NewConfigurationProfilesClient creates an instance of the ConfigurationProfilesClient client. +func NewConfigurationProfilesClient(subscriptionID string) ConfigurationProfilesClient { + return NewConfigurationProfilesClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewConfigurationProfilesClientWithBaseURI creates an instance of the ConfigurationProfilesClient 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 NewConfigurationProfilesClientWithBaseURI(baseURI string, subscriptionID string) ConfigurationProfilesClient { + return ConfigurationProfilesClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// CreateOrUpdate creates a configuration profile +// Parameters: +// configurationProfileName - name of the configuration profile. +// resourceGroupName - the name of the resource group. The name is case insensitive. +// parameters - parameters supplied to create or update configuration profile. +func (client ConfigurationProfilesClient) CreateOrUpdate(ctx context.Context, configurationProfileName string, resourceGroupName string, parameters ConfigurationProfile) (result ConfigurationProfile, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationProfilesClient.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: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ConfigurationProfilesClient", "CreateOrUpdate", err.Error()) + } + + req, err := client.CreateOrUpdatePreparer(ctx, configurationProfileName, resourceGroupName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesClient", "CreateOrUpdate", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesClient", "CreateOrUpdate", resp, "Failure responding to request") + return + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client ConfigurationProfilesClient) CreateOrUpdatePreparer(ctx context.Context, configurationProfileName string, resourceGroupName string, parameters ConfigurationProfile) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "configurationProfileName": autorest.Encode("path", configurationProfileName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + parameters.SystemData = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automanage/configurationProfiles/{configurationProfileName}", pathParameters), + autorest.WithJSON(parameters), + 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 ConfigurationProfilesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client ConfigurationProfilesClient) CreateOrUpdateResponder(resp *http.Response) (result ConfigurationProfile, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete delete a configuration profile +// Parameters: +// resourceGroupName - the name of the resource group. The name is case insensitive. +// configurationProfileName - name of the configuration profile +func (client ConfigurationProfilesClient) Delete(ctx context.Context, resourceGroupName string, configurationProfileName string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationProfilesClient.Delete") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ConfigurationProfilesClient", "Delete", err.Error()) + } + + req, err := client.DeletePreparer(ctx, resourceGroupName, configurationProfileName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesClient", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesClient", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesClient", "Delete", resp, "Failure responding to request") + return + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client ConfigurationProfilesClient) DeletePreparer(ctx context.Context, resourceGroupName string, configurationProfileName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "configurationProfileName": autorest.Encode("path", configurationProfileName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automanage/configurationProfiles/{configurationProfileName}", 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 ConfigurationProfilesClient) DeleteSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client ConfigurationProfilesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Get get information about a configuration profile +// Parameters: +// configurationProfileName - the configuration profile name. +// resourceGroupName - the name of the resource group. The name is case insensitive. +func (client ConfigurationProfilesClient) Get(ctx context.Context, configurationProfileName string, resourceGroupName string) (result ConfigurationProfile, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationProfilesClient.Get") + 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: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ConfigurationProfilesClient", "Get", err.Error()) + } + + req, err := client.GetPreparer(ctx, configurationProfileName, resourceGroupName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client ConfigurationProfilesClient) GetPreparer(ctx context.Context, configurationProfileName string, resourceGroupName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "configurationProfileName": autorest.Encode("path", configurationProfileName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automanage/configurationProfiles/{configurationProfileName}", 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 ConfigurationProfilesClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client ConfigurationProfilesClient) GetResponder(resp *http.Response) (result ConfigurationProfile, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListByResourceGroup retrieve a list of configuration profile within a given resource group +// Parameters: +// resourceGroupName - the name of the resource group. The name is case insensitive. +func (client ConfigurationProfilesClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result ConfigurationProfileList, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationProfilesClient.ListByResourceGroup") + 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: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ConfigurationProfilesClient", "ListByResourceGroup", err.Error()) + } + + req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + resp, err := client.ListByResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesClient", "ListByResourceGroup", resp, "Failure sending request") + return + } + + result, err = client.ListByResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesClient", "ListByResourceGroup", resp, "Failure responding to request") + return + } + + return +} + +// ListByResourceGroupPreparer prepares the ListByResourceGroup request. +func (client ConfigurationProfilesClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automanage/configurationProfiles", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the +// http.Response Body if it receives an error. +func (client ConfigurationProfilesClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always +// closes the http.Response Body. +func (client ConfigurationProfilesClient) ListByResourceGroupResponder(resp *http.Response) (result ConfigurationProfileList, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListBySubscription retrieve a list of configuration profile within a subscription +func (client ConfigurationProfilesClient) ListBySubscription(ctx context.Context) (result ConfigurationProfileList, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationProfilesClient.ListBySubscription") + 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: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ConfigurationProfilesClient", "ListBySubscription", err.Error()) + } + + req, err := client.ListBySubscriptionPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + resp, err := client.ListBySubscriptionSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesClient", "ListBySubscription", resp, "Failure sending request") + return + } + + result, err = client.ListBySubscriptionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesClient", "ListBySubscription", resp, "Failure responding to request") + return + } + + return +} + +// ListBySubscriptionPreparer prepares the ListBySubscription request. +func (client ConfigurationProfilesClient) ListBySubscriptionPreparer(ctx context.Context) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Automanage/configurationProfiles", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListBySubscriptionSender sends the ListBySubscription request. The method will close the +// http.Response Body if it receives an error. +func (client ConfigurationProfilesClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListBySubscriptionResponder handles the response to the ListBySubscription request. The method always +// closes the http.Response Body. +func (client ConfigurationProfilesClient) ListBySubscriptionResponder(resp *http.Response) (result ConfigurationProfileList, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Update updates a configuration profile +// Parameters: +// configurationProfileName - name of the configuration profile. +// resourceGroupName - the name of the resource group. The name is case insensitive. +// parameters - parameters supplied to update configuration profile. +func (client ConfigurationProfilesClient) Update(ctx context.Context, configurationProfileName string, resourceGroupName string, parameters ConfigurationProfileUpdate) (result ConfigurationProfile, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationProfilesClient.Update") + 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: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ConfigurationProfilesClient", "Update", err.Error()) + } + + req, err := client.UpdatePreparer(ctx, configurationProfileName, resourceGroupName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesClient", "Update", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesClient", "Update", resp, "Failure sending request") + return + } + + result, err = client.UpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesClient", "Update", resp, "Failure responding to request") + return + } + + return +} + +// UpdatePreparer prepares the Update request. +func (client ConfigurationProfilesClient) UpdatePreparer(ctx context.Context, configurationProfileName string, resourceGroupName string, parameters ConfigurationProfileUpdate) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "configurationProfileName": autorest.Encode("path", configurationProfileName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automanage/configurationProfiles/{configurationProfileName}", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdateSender sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (client ConfigurationProfilesClient) UpdateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// UpdateResponder handles the response to the Update request. The method always +// closes the http.Response Body. +func (client ConfigurationProfilesClient) UpdateResponder(resp *http.Response) (result ConfigurationProfile, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/configurationprofilesversions.go b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/configurationprofilesversions.go new file mode 100644 index 000000000000..0e9b7e209119 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/configurationprofilesversions.go @@ -0,0 +1,383 @@ +package automanage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "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" +) + +// ConfigurationProfilesVersionsClient is the automanage Client +type ConfigurationProfilesVersionsClient struct { + BaseClient +} + +// NewConfigurationProfilesVersionsClient creates an instance of the ConfigurationProfilesVersionsClient client. +func NewConfigurationProfilesVersionsClient(subscriptionID string) ConfigurationProfilesVersionsClient { + return NewConfigurationProfilesVersionsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewConfigurationProfilesVersionsClientWithBaseURI creates an instance of the ConfigurationProfilesVersionsClient +// 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 NewConfigurationProfilesVersionsClientWithBaseURI(baseURI string, subscriptionID string) ConfigurationProfilesVersionsClient { + return ConfigurationProfilesVersionsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// CreateOrUpdate creates a configuration profile version +// Parameters: +// configurationProfileName - name of the configuration profile. +// versionName - the configuration profile version name. +// resourceGroupName - the name of the resource group. The name is case insensitive. +// parameters - parameters supplied to create or update configuration profile. +func (client ConfigurationProfilesVersionsClient) CreateOrUpdate(ctx context.Context, configurationProfileName string, versionName string, resourceGroupName string, parameters ConfigurationProfile) (result ConfigurationProfile, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationProfilesVersionsClient.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: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ConfigurationProfilesVersionsClient", "CreateOrUpdate", err.Error()) + } + + req, err := client.CreateOrUpdatePreparer(ctx, configurationProfileName, versionName, resourceGroupName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesVersionsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesVersionsClient", "CreateOrUpdate", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesVersionsClient", "CreateOrUpdate", resp, "Failure responding to request") + return + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client ConfigurationProfilesVersionsClient) CreateOrUpdatePreparer(ctx context.Context, configurationProfileName string, versionName string, resourceGroupName string, parameters ConfigurationProfile) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "configurationProfileName": autorest.Encode("path", configurationProfileName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + "versionName": autorest.Encode("path", versionName), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + parameters.SystemData = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automanage/configurationProfiles/{configurationProfileName}/versions/{versionName}", pathParameters), + autorest.WithJSON(parameters), + 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 ConfigurationProfilesVersionsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client ConfigurationProfilesVersionsClient) CreateOrUpdateResponder(resp *http.Response) (result ConfigurationProfile, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete delete a configuration profile version +// Parameters: +// resourceGroupName - the name of the resource group. The name is case insensitive. +// configurationProfileName - name of the configuration profile +// versionName - the configuration profile version name. +func (client ConfigurationProfilesVersionsClient) Delete(ctx context.Context, resourceGroupName string, configurationProfileName string, versionName string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationProfilesVersionsClient.Delete") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ConfigurationProfilesVersionsClient", "Delete", err.Error()) + } + + req, err := client.DeletePreparer(ctx, resourceGroupName, configurationProfileName, versionName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesVersionsClient", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesVersionsClient", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesVersionsClient", "Delete", resp, "Failure responding to request") + return + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client ConfigurationProfilesVersionsClient) DeletePreparer(ctx context.Context, resourceGroupName string, configurationProfileName string, versionName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "configurationProfileName": autorest.Encode("path", configurationProfileName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + "versionName": autorest.Encode("path", versionName), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automanage/configurationProfiles/{configurationProfileName}/versions/{versionName}", 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 ConfigurationProfilesVersionsClient) DeleteSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client ConfigurationProfilesVersionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Get get information about a configuration profile version +// Parameters: +// configurationProfileName - the configuration profile name. +// versionName - the configuration profile version name. +// resourceGroupName - the name of the resource group. The name is case insensitive. +func (client ConfigurationProfilesVersionsClient) Get(ctx context.Context, configurationProfileName string, versionName string, resourceGroupName string) (result ConfigurationProfile, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationProfilesVersionsClient.Get") + 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: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ConfigurationProfilesVersionsClient", "Get", err.Error()) + } + + req, err := client.GetPreparer(ctx, configurationProfileName, versionName, resourceGroupName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesVersionsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesVersionsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesVersionsClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client ConfigurationProfilesVersionsClient) GetPreparer(ctx context.Context, configurationProfileName string, versionName string, resourceGroupName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "configurationProfileName": autorest.Encode("path", configurationProfileName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + "versionName": autorest.Encode("path", versionName), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automanage/configurationProfiles/{configurationProfileName}/versions/{versionName}", 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 ConfigurationProfilesVersionsClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client ConfigurationProfilesVersionsClient) GetResponder(resp *http.Response) (result ConfigurationProfile, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListChildResources retrieve a list of configuration profile version for a configuration profile +// Parameters: +// configurationProfileName - name of the configuration profile. +// resourceGroupName - the name of the resource group. The name is case insensitive. +func (client ConfigurationProfilesVersionsClient) ListChildResources(ctx context.Context, configurationProfileName string, resourceGroupName string) (result ConfigurationProfileList, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ConfigurationProfilesVersionsClient.ListChildResources") + 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: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ConfigurationProfilesVersionsClient", "ListChildResources", err.Error()) + } + + req, err := client.ListChildResourcesPreparer(ctx, configurationProfileName, resourceGroupName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesVersionsClient", "ListChildResources", nil, "Failure preparing request") + return + } + + resp, err := client.ListChildResourcesSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesVersionsClient", "ListChildResources", resp, "Failure sending request") + return + } + + result, err = client.ListChildResourcesResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ConfigurationProfilesVersionsClient", "ListChildResources", resp, "Failure responding to request") + return + } + + return +} + +// ListChildResourcesPreparer prepares the ListChildResources request. +func (client ConfigurationProfilesVersionsClient) ListChildResourcesPreparer(ctx context.Context, configurationProfileName string, resourceGroupName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "configurationProfileName": autorest.Encode("path", configurationProfileName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automanage/configurationProfiles/{configurationProfileName}/versions", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListChildResourcesSender sends the ListChildResources request. The method will close the +// http.Response Body if it receives an error. +func (client ConfigurationProfilesVersionsClient) ListChildResourcesSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListChildResourcesResponder handles the response to the ListChildResources request. The method always +// closes the http.Response Body. +func (client ConfigurationProfilesVersionsClient) ListChildResourcesResponder(resp *http.Response) (result ConfigurationProfileList, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/enums.go b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/enums.go new file mode 100644 index 000000000000..05c95d21aa3e --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/enums.go @@ -0,0 +1,56 @@ +package automanage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +// ActionType enumerates the values for action type. +type ActionType string + +const ( + // ActionTypeInternal ... + ActionTypeInternal ActionType = "Internal" +) + +// PossibleActionTypeValues returns an array of possible values for the ActionType const type. +func PossibleActionTypeValues() []ActionType { + return []ActionType{ActionTypeInternal} +} + +// CreatedByType enumerates the values for created by type. +type CreatedByType string + +const ( + // CreatedByTypeApplication ... + CreatedByTypeApplication CreatedByType = "Application" + // CreatedByTypeKey ... + CreatedByTypeKey CreatedByType = "Key" + // CreatedByTypeManagedIdentity ... + CreatedByTypeManagedIdentity CreatedByType = "ManagedIdentity" + // CreatedByTypeUser ... + CreatedByTypeUser CreatedByType = "User" +) + +// PossibleCreatedByTypeValues returns an array of possible values for the CreatedByType const type. +func PossibleCreatedByTypeValues() []CreatedByType { + return []CreatedByType{CreatedByTypeApplication, CreatedByTypeKey, CreatedByTypeManagedIdentity, CreatedByTypeUser} +} + +// Origin enumerates the values for origin. +type Origin string + +const ( + // OriginSystem ... + OriginSystem Origin = "system" + // OriginUser ... + OriginUser Origin = "user" + // OriginUsersystem ... + OriginUsersystem Origin = "user,system" +) + +// PossibleOriginValues returns an array of possible values for the Origin const type. +func PossibleOriginValues() []Origin { + return []Origin{OriginSystem, OriginUser, OriginUsersystem} +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/hcireports.go b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/hcireports.go new file mode 100644 index 000000000000..46045c12af53 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/hcireports.go @@ -0,0 +1,209 @@ +package automanage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "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" +) + +// HCIReportsClient is the automanage Client +type HCIReportsClient struct { + BaseClient +} + +// NewHCIReportsClient creates an instance of the HCIReportsClient client. +func NewHCIReportsClient(subscriptionID string) HCIReportsClient { + return NewHCIReportsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewHCIReportsClientWithBaseURI creates an instance of the HCIReportsClient 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 NewHCIReportsClientWithBaseURI(baseURI string, subscriptionID string) HCIReportsClient { + return HCIReportsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// Get get information about a report associated with a configuration profile assignment run +// Parameters: +// resourceGroupName - the name of the resource group. The name is case insensitive. +// clusterName - the name of the Arc machine. +// configurationProfileAssignmentName - the configuration profile assignment name. +// reportName - the report name. +func (client HCIReportsClient) Get(ctx context.Context, resourceGroupName string, clusterName string, configurationProfileAssignmentName string, reportName string) (result Report, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/HCIReportsClient.Get") + 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: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.HCIReportsClient", "Get", err.Error()) + } + + req, err := client.GetPreparer(ctx, resourceGroupName, clusterName, configurationProfileAssignmentName, reportName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.HCIReportsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.HCIReportsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.HCIReportsClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client HCIReportsClient) GetPreparer(ctx context.Context, resourceGroupName string, clusterName string, configurationProfileAssignmentName string, reportName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "clusterName": autorest.Encode("path", clusterName), + "configurationProfileAssignmentName": autorest.Encode("path", configurationProfileAssignmentName), + "reportName": autorest.Encode("path", reportName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AzureStackHci/clusters/{clusterName}/providers/Microsoft.Automanage/configurationProfileAssignments/{configurationProfileAssignmentName}/reports/{reportName}", 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 HCIReportsClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client HCIReportsClient) GetResponder(resp *http.Response) (result Report, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListByConfigurationProfileAssignments retrieve a list of reports within a given configuration profile assignment +// Parameters: +// resourceGroupName - the name of the resource group. The name is case insensitive. +// clusterName - the name of the Arc machine. +// configurationProfileAssignmentName - the configuration profile assignment name. +func (client HCIReportsClient) ListByConfigurationProfileAssignments(ctx context.Context, resourceGroupName string, clusterName string, configurationProfileAssignmentName string) (result ReportList, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/HCIReportsClient.ListByConfigurationProfileAssignments") + 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: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.HCIReportsClient", "ListByConfigurationProfileAssignments", err.Error()) + } + + req, err := client.ListByConfigurationProfileAssignmentsPreparer(ctx, resourceGroupName, clusterName, configurationProfileAssignmentName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.HCIReportsClient", "ListByConfigurationProfileAssignments", nil, "Failure preparing request") + return + } + + resp, err := client.ListByConfigurationProfileAssignmentsSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.HCIReportsClient", "ListByConfigurationProfileAssignments", resp, "Failure sending request") + return + } + + result, err = client.ListByConfigurationProfileAssignmentsResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.HCIReportsClient", "ListByConfigurationProfileAssignments", resp, "Failure responding to request") + return + } + + return +} + +// ListByConfigurationProfileAssignmentsPreparer prepares the ListByConfigurationProfileAssignments request. +func (client HCIReportsClient) ListByConfigurationProfileAssignmentsPreparer(ctx context.Context, resourceGroupName string, clusterName string, configurationProfileAssignmentName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "clusterName": autorest.Encode("path", clusterName), + "configurationProfileAssignmentName": autorest.Encode("path", configurationProfileAssignmentName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AzureStackHci/clusters/{clusterName}/providers/Microsoft.Automanage/configurationProfileAssignments/{configurationProfileAssignmentName}/reports", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListByConfigurationProfileAssignmentsSender sends the ListByConfigurationProfileAssignments request. The method will close the +// http.Response Body if it receives an error. +func (client HCIReportsClient) ListByConfigurationProfileAssignmentsSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListByConfigurationProfileAssignmentsResponder handles the response to the ListByConfigurationProfileAssignments request. The method always +// closes the http.Response Body. +func (client HCIReportsClient) ListByConfigurationProfileAssignmentsResponder(resp *http.Response) (result ReportList, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/hcrpreports.go b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/hcrpreports.go new file mode 100644 index 000000000000..c9e7db65e02b --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/hcrpreports.go @@ -0,0 +1,209 @@ +package automanage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "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" +) + +// HCRPReportsClient is the automanage Client +type HCRPReportsClient struct { + BaseClient +} + +// NewHCRPReportsClient creates an instance of the HCRPReportsClient client. +func NewHCRPReportsClient(subscriptionID string) HCRPReportsClient { + return NewHCRPReportsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewHCRPReportsClientWithBaseURI creates an instance of the HCRPReportsClient 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 NewHCRPReportsClientWithBaseURI(baseURI string, subscriptionID string) HCRPReportsClient { + return HCRPReportsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// Get get information about a report associated with a configuration profile assignment run +// Parameters: +// resourceGroupName - the name of the resource group. The name is case insensitive. +// machineName - the name of the Arc machine. +// configurationProfileAssignmentName - the configuration profile assignment name. +// reportName - the report name. +func (client HCRPReportsClient) Get(ctx context.Context, resourceGroupName string, machineName string, configurationProfileAssignmentName string, reportName string) (result Report, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/HCRPReportsClient.Get") + 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: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.HCRPReportsClient", "Get", err.Error()) + } + + req, err := client.GetPreparer(ctx, resourceGroupName, machineName, configurationProfileAssignmentName, reportName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.HCRPReportsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.HCRPReportsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.HCRPReportsClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client HCRPReportsClient) GetPreparer(ctx context.Context, resourceGroupName string, machineName string, configurationProfileAssignmentName string, reportName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "configurationProfileAssignmentName": autorest.Encode("path", configurationProfileAssignmentName), + "machineName": autorest.Encode("path", machineName), + "reportName": autorest.Encode("path", reportName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridCompute/machines/{machineName}/providers/Microsoft.Automanage/configurationProfileAssignments/{configurationProfileAssignmentName}/reports/{reportName}", 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 HCRPReportsClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client HCRPReportsClient) GetResponder(resp *http.Response) (result Report, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListByConfigurationProfileAssignments retrieve a list of reports within a given configuration profile assignment +// Parameters: +// resourceGroupName - the name of the resource group. The name is case insensitive. +// machineName - the name of the Arc machine. +// configurationProfileAssignmentName - the configuration profile assignment name. +func (client HCRPReportsClient) ListByConfigurationProfileAssignments(ctx context.Context, resourceGroupName string, machineName string, configurationProfileAssignmentName string) (result ReportList, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/HCRPReportsClient.ListByConfigurationProfileAssignments") + 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: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.HCRPReportsClient", "ListByConfigurationProfileAssignments", err.Error()) + } + + req, err := client.ListByConfigurationProfileAssignmentsPreparer(ctx, resourceGroupName, machineName, configurationProfileAssignmentName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.HCRPReportsClient", "ListByConfigurationProfileAssignments", nil, "Failure preparing request") + return + } + + resp, err := client.ListByConfigurationProfileAssignmentsSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.HCRPReportsClient", "ListByConfigurationProfileAssignments", resp, "Failure sending request") + return + } + + result, err = client.ListByConfigurationProfileAssignmentsResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.HCRPReportsClient", "ListByConfigurationProfileAssignments", resp, "Failure responding to request") + return + } + + return +} + +// ListByConfigurationProfileAssignmentsPreparer prepares the ListByConfigurationProfileAssignments request. +func (client HCRPReportsClient) ListByConfigurationProfileAssignmentsPreparer(ctx context.Context, resourceGroupName string, machineName string, configurationProfileAssignmentName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "configurationProfileAssignmentName": autorest.Encode("path", configurationProfileAssignmentName), + "machineName": autorest.Encode("path", machineName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridCompute/machines/{machineName}/providers/Microsoft.Automanage/configurationProfileAssignments/{configurationProfileAssignmentName}/reports", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListByConfigurationProfileAssignmentsSender sends the ListByConfigurationProfileAssignments request. The method will close the +// http.Response Body if it receives an error. +func (client HCRPReportsClient) ListByConfigurationProfileAssignmentsSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListByConfigurationProfileAssignmentsResponder handles the response to the ListByConfigurationProfileAssignments request. The method always +// closes the http.Response Body. +func (client HCRPReportsClient) ListByConfigurationProfileAssignmentsResponder(resp *http.Response) (result ReportList, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/models.go b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/models.go new file mode 100644 index 000000000000..6e9c0c024907 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/models.go @@ -0,0 +1,687 @@ +package automanage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "encoding/json" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/date" +) + +// The package's fully qualified name. +const fqdn = "home/runner/work/kermit/kermit/sdk/automanage/2022-05-04/automanage" + +// AssignmentReportProperties data related to the report detail. +type AssignmentReportProperties struct { + // StartTime - Start time of the configuration profile assignment processing. + StartTime *string `json:"startTime,omitempty"` + // EndTime - End time of the configuration profile assignment processing. + EndTime *string `json:"endTime,omitempty"` + // LastModifiedTime - READ-ONLY; Last modified time of the configuration profile assignment processing. + LastModifiedTime *string `json:"lastModifiedTime,omitempty"` + // Duration - READ-ONLY; Duration of the configuration profile assignment processing. + Duration *string `json:"duration,omitempty"` + // Type - READ-ONLY; Type of the configuration profile assignment processing (Initial/Consistency). + Type *string `json:"type,omitempty"` + // Status - READ-ONLY; The status of the configuration profile assignment. + Status *string `json:"status,omitempty"` + // ConfigurationProfile - READ-ONLY; The configurationProfile linked to the assignment. + ConfigurationProfile *string `json:"configurationProfile,omitempty"` + // Resources - READ-ONLY; List of resources processed by the configuration profile assignment. + Resources *[]ReportResource `json:"resources,omitempty"` + // Error - READ-ONLY; Error message, if any, returned by the configuration profile assignment processing. + Error *ErrorDetail `json:"error,omitempty"` + // ReportFormatVersion - READ-ONLY; Version of the report format + ReportFormatVersion *string `json:"reportFormatVersion,omitempty"` +} + +// MarshalJSON is the custom marshaler for AssignmentReportProperties. +func (arp AssignmentReportProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if arp.StartTime != nil { + objectMap["startTime"] = arp.StartTime + } + if arp.EndTime != nil { + objectMap["endTime"] = arp.EndTime + } + return json.Marshal(objectMap) +} + +// AzureEntityResource the resource model definition for an Azure Resource Manager resource with an etag. +type AzureEntityResource struct { + // Etag - READ-ONLY; Resource Etag. + Etag *string `json:"etag,omitempty"` + // ID - READ-ONLY; Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; The name of the resource + Name *string `json:"name,omitempty"` + // Type - READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for AzureEntityResource. +func (aer AzureEntityResource) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + return json.Marshal(objectMap) +} + +// BestPractice definition of the Automanage best practice. +type BestPractice struct { + autorest.Response `json:"-"` + // ID - READ-ONLY; The fully qualified ID for the best practice. For example, /providers/Microsoft.Automanage/bestPractices/azureBestPracticesProduction + ID *string `json:"id,omitempty"` + // Type - READ-ONLY; The type of the resource. For example, Microsoft.Automanage/bestPractices + Type *string `json:"type,omitempty"` + // Name - READ-ONLY; The name of the best practice. For example, azureBestPracticesProduction + Name *string `json:"name,omitempty"` + // ConfigurationProfileProperties - Properties of the best practice. + *ConfigurationProfileProperties `json:"properties,omitempty"` + // SystemData - READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information. + SystemData *SystemData `json:"systemData,omitempty"` +} + +// MarshalJSON is the custom marshaler for BestPractice. +func (bp BestPractice) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if bp.ConfigurationProfileProperties != nil { + objectMap["properties"] = bp.ConfigurationProfileProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for BestPractice struct. +func (bp *BestPractice) 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 "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + bp.ID = &ID + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + bp.Type = &typeVar + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + bp.Name = &name + } + case "properties": + if v != nil { + var configurationProfileProperties ConfigurationProfileProperties + err = json.Unmarshal(*v, &configurationProfileProperties) + if err != nil { + return err + } + bp.ConfigurationProfileProperties = &configurationProfileProperties + } + case "systemData": + if v != nil { + var systemData SystemData + err = json.Unmarshal(*v, &systemData) + if err != nil { + return err + } + bp.SystemData = &systemData + } + } + } + + return nil +} + +// BestPracticeList the response of the list best practice operation. +type BestPracticeList struct { + autorest.Response `json:"-"` + // Value - Result of the list best practice operation. + Value *[]BestPractice `json:"value,omitempty"` +} + +// ConfigurationProfile definition of the configuration profile. +type ConfigurationProfile struct { + autorest.Response `json:"-"` + // Properties - Properties of the configuration profile. + Properties *ConfigurationProfileProperties `json:"properties,omitempty"` + // SystemData - READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information. + SystemData *SystemData `json:"systemData,omitempty"` + // Tags - Resource tags. + Tags map[string]*string `json:"tags"` + // Location - The geo-location where the resource lives + Location *string `json:"location,omitempty"` + // ID - READ-ONLY; Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; The name of the resource + Name *string `json:"name,omitempty"` + // Type - READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for ConfigurationProfile. +func (cp ConfigurationProfile) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if cp.Properties != nil { + objectMap["properties"] = cp.Properties + } + if cp.Tags != nil { + objectMap["tags"] = cp.Tags + } + if cp.Location != nil { + objectMap["location"] = cp.Location + } + return json.Marshal(objectMap) +} + +// ConfigurationProfileAssignment configuration profile assignment is an association between a VM and +// automanage profile configuration. +type ConfigurationProfileAssignment struct { + autorest.Response `json:"-"` + // Properties - Properties of the configuration profile assignment. + Properties *ConfigurationProfileAssignmentProperties `json:"properties,omitempty"` + // ManagedBy - READ-ONLY; Azure resource id. Indicates if this resource is managed by another Azure resource. + ManagedBy *string `json:"managedBy,omitempty"` + // SystemData - READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information. + SystemData *SystemData `json:"systemData,omitempty"` + // ID - READ-ONLY; Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; The name of the resource + Name *string `json:"name,omitempty"` + // Type - READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for ConfigurationProfileAssignment. +func (cpa ConfigurationProfileAssignment) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if cpa.Properties != nil { + objectMap["properties"] = cpa.Properties + } + return json.Marshal(objectMap) +} + +// ConfigurationProfileAssignmentList the response of the list configuration profile assignment operation. +type ConfigurationProfileAssignmentList struct { + autorest.Response `json:"-"` + // Value - Result of the list configuration profile assignment operation. + Value *[]ConfigurationProfileAssignment `json:"value,omitempty"` +} + +// ConfigurationProfileAssignmentProperties automanage configuration profile assignment properties. +type ConfigurationProfileAssignmentProperties struct { + // ConfigurationProfile - The Automanage configurationProfile ARM Resource URI. + ConfigurationProfile *string `json:"configurationProfile,omitempty"` + // TargetID - READ-ONLY; The target VM resource URI + TargetID *string `json:"targetId,omitempty"` + // Status - READ-ONLY; The status of onboarding, which only appears in the response. + Status *string `json:"status,omitempty"` +} + +// MarshalJSON is the custom marshaler for ConfigurationProfileAssignmentProperties. +func (cpap ConfigurationProfileAssignmentProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if cpap.ConfigurationProfile != nil { + objectMap["configurationProfile"] = cpap.ConfigurationProfile + } + return json.Marshal(objectMap) +} + +// ConfigurationProfileList the response of the list configuration profile operation. +type ConfigurationProfileList struct { + autorest.Response `json:"-"` + // Value - Result of the list ConfigurationProfile operation. + Value *[]ConfigurationProfile `json:"value,omitempty"` +} + +// ConfigurationProfileProperties automanage configuration profile properties. +type ConfigurationProfileProperties struct { + // Configuration - configuration dictionary of the configuration profile. + Configuration interface{} `json:"configuration,omitempty"` +} + +// ConfigurationProfileUpdate definition of the configuration profile. +type ConfigurationProfileUpdate struct { + // Properties - Properties of the configuration profile. + Properties *ConfigurationProfileProperties `json:"properties,omitempty"` + // Tags - The tags of the resource. + Tags map[string]*string `json:"tags"` +} + +// MarshalJSON is the custom marshaler for ConfigurationProfileUpdate. +func (CPU ConfigurationProfileUpdate) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if CPU.Properties != nil { + objectMap["properties"] = CPU.Properties + } + if CPU.Tags != nil { + objectMap["tags"] = CPU.Tags + } + return json.Marshal(objectMap) +} + +// ErrorAdditionalInfo the resource management error additional info. +type ErrorAdditionalInfo struct { + // Type - READ-ONLY; The additional info type. + Type *string `json:"type,omitempty"` + // Info - READ-ONLY; The additional info. + Info interface{} `json:"info,omitempty"` +} + +// MarshalJSON is the custom marshaler for ErrorAdditionalInfo. +func (eai ErrorAdditionalInfo) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + return json.Marshal(objectMap) +} + +// ErrorDetail the error detail. +type ErrorDetail struct { + // Code - READ-ONLY; The error code. + Code *string `json:"code,omitempty"` + // Message - READ-ONLY; The error message. + Message *string `json:"message,omitempty"` + // Target - READ-ONLY; The error target. + Target *string `json:"target,omitempty"` + // Details - READ-ONLY; The error details. + Details *[]ErrorDetail `json:"details,omitempty"` + // AdditionalInfo - READ-ONLY; The error additional info. + AdditionalInfo *[]ErrorAdditionalInfo `json:"additionalInfo,omitempty"` +} + +// MarshalJSON is the custom marshaler for ErrorDetail. +func (ed ErrorDetail) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + return json.Marshal(objectMap) +} + +// ErrorResponse common error response for all Azure Resource Manager APIs to return error details for +// failed operations. (This also follows the OData error response format.). +type ErrorResponse struct { + // Error - The error object. + Error *ErrorDetail `json:"error,omitempty"` +} + +// Operation details of a REST API operation, returned from the Resource Provider Operations API +type Operation struct { + // Name - READ-ONLY; The name of the operation, as per Resource-Based Access Control (RBAC). Examples: "Microsoft.Compute/virtualMachines/write", "Microsoft.Compute/virtualMachines/capture/action" + Name *string `json:"name,omitempty"` + // IsDataAction - READ-ONLY; Whether the operation applies to data-plane. This is "true" for data-plane operations and "false" for ARM/control-plane operations. + IsDataAction *bool `json:"isDataAction,omitempty"` + // Display - Localized display information for this particular operation. + Display *OperationDisplay `json:"display,omitempty"` + // Origin - READ-ONLY; The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default value is "user,system". Possible values include: 'OriginUser', 'OriginSystem', 'OriginUsersystem' + Origin Origin `json:"origin,omitempty"` + // ActionType - READ-ONLY; Enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. Possible values include: 'ActionTypeInternal' + ActionType ActionType `json:"actionType,omitempty"` +} + +// MarshalJSON is the custom marshaler for Operation. +func (o Operation) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if o.Display != nil { + objectMap["display"] = o.Display + } + return json.Marshal(objectMap) +} + +// OperationDisplay localized display information for this particular operation. +type OperationDisplay struct { + // Provider - READ-ONLY; The localized friendly form of the resource provider name, e.g. "Microsoft Monitoring Insights" or "Microsoft Compute". + Provider *string `json:"provider,omitempty"` + // Resource - READ-ONLY; The localized friendly name of the resource type related to this operation. E.g. "Virtual Machines" or "Job Schedule Collections". + Resource *string `json:"resource,omitempty"` + // Operation - READ-ONLY; The concise, localized friendly name for the operation; suitable for dropdowns. E.g. "Create or Update Virtual Machine", "Restart Virtual Machine". + Operation *string `json:"operation,omitempty"` + // Description - READ-ONLY; The short, localized friendly description of the operation; suitable for tool tips and detailed views. + Description *string `json:"description,omitempty"` +} + +// MarshalJSON is the custom marshaler for OperationDisplay. +func (o OperationDisplay) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + return json.Marshal(objectMap) +} + +// OperationListResult a list of REST API operations supported by an Azure Resource Provider. It contains +// an URL link to get the next set of results. +type OperationListResult struct { + autorest.Response `json:"-"` + // Value - READ-ONLY; List of operations supported by the resource provider + Value *[]Operation `json:"value,omitempty"` + // NextLink - READ-ONLY; URL to get the next set of operation list results (if there are any). + NextLink *string `json:"nextLink,omitempty"` +} + +// MarshalJSON is the custom marshaler for OperationListResult. +func (olr OperationListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + return json.Marshal(objectMap) +} + +// ProxyResource the resource model definition for a Azure Resource Manager proxy resource. It will not +// have tags and a location +type ProxyResource struct { + // ID - READ-ONLY; Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; The name of the resource + Name *string `json:"name,omitempty"` + // Type - READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for ProxyResource. +func (pr ProxyResource) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + return json.Marshal(objectMap) +} + +// Report definition of the report. +type Report struct { + autorest.Response `json:"-"` + // AssignmentReportProperties - The properties for the report. + *AssignmentReportProperties `json:"properties,omitempty"` + // SystemData - READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information. + SystemData *SystemData `json:"systemData,omitempty"` + // ID - READ-ONLY; Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; The name of the resource + Name *string `json:"name,omitempty"` + // Type - READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for Report. +func (r Report) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if r.AssignmentReportProperties != nil { + objectMap["properties"] = r.AssignmentReportProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for Report struct. +func (r *Report) 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 assignmentReportProperties AssignmentReportProperties + err = json.Unmarshal(*v, &assignmentReportProperties) + if err != nil { + return err + } + r.AssignmentReportProperties = &assignmentReportProperties + } + case "systemData": + if v != nil { + var systemData SystemData + err = json.Unmarshal(*v, &systemData) + if err != nil { + return err + } + r.SystemData = &systemData + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + r.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + r.Name = &name + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + r.Type = &typeVar + } + } + } + + return nil +} + +// ReportList the response of the list report operation. +type ReportList struct { + autorest.Response `json:"-"` + // Value - Result of the list report operation. + Value *[]Report `json:"value,omitempty"` +} + +// ReportResource details about the resource processed by the configuration profile assignment +type ReportResource struct { + // Name - READ-ONLY; Name of the resource. + Name *string `json:"name,omitempty"` + // ID - READ-ONLY; ARM id of the resource. + ID *string `json:"id,omitempty"` + // Type - READ-ONLY; Type of the resource. + Type *string `json:"type,omitempty"` + // Status - READ-ONLY; Status of the resource. + Status *string `json:"status,omitempty"` + // Error - READ-ONLY; Error message, if any, returned when deploying the resource. + Error *ErrorDetail `json:"error,omitempty"` +} + +// MarshalJSON is the custom marshaler for ReportResource. +func (rr ReportResource) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + return json.Marshal(objectMap) +} + +// Resource common fields that are returned in the response for all Azure Resource Manager resources +type Resource struct { + // ID - READ-ONLY; Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; The name of the resource + Name *string `json:"name,omitempty"` + // Type - READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for Resource. +func (r Resource) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + return json.Marshal(objectMap) +} + +// ServicePrincipal the Service Principal Id for the subscription. +type ServicePrincipal struct { + autorest.Response `json:"-"` + // ServicePrincipalProperties - The Service Principal properties for the subscription + *ServicePrincipalProperties `json:"properties,omitempty"` + // SystemData - READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information. + SystemData *SystemData `json:"systemData,omitempty"` + // ID - READ-ONLY; Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; The name of the resource + Name *string `json:"name,omitempty"` + // Type - READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for ServicePrincipal. +func (sp ServicePrincipal) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if sp.ServicePrincipalProperties != nil { + objectMap["properties"] = sp.ServicePrincipalProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for ServicePrincipal struct. +func (sp *ServicePrincipal) 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 servicePrincipalProperties ServicePrincipalProperties + err = json.Unmarshal(*v, &servicePrincipalProperties) + if err != nil { + return err + } + sp.ServicePrincipalProperties = &servicePrincipalProperties + } + case "systemData": + if v != nil { + var systemData SystemData + err = json.Unmarshal(*v, &systemData) + if err != nil { + return err + } + sp.SystemData = &systemData + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + sp.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + sp.Name = &name + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + sp.Type = &typeVar + } + } + } + + return nil +} + +// ServicePrincipalListResult the list of ServicePrincipals. +type ServicePrincipalListResult struct { + autorest.Response `json:"-"` + // Value - The list of servicePrincipals. + Value *[]ServicePrincipal `json:"value,omitempty"` +} + +// ServicePrincipalProperties the Service Principal properties for the subscription. +type ServicePrincipalProperties struct { + // ServicePrincipalID - READ-ONLY; The Service Principal Id for the subscription. + ServicePrincipalID *string `json:"servicePrincipalId,omitempty"` + // AuthorizationSet - READ-ONLY; Returns the contributor RBAC Role exist or not for the Service Principal Id. + AuthorizationSet *bool `json:"authorizationSet,omitempty"` +} + +// MarshalJSON is the custom marshaler for ServicePrincipalProperties. +func (spp ServicePrincipalProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + return json.Marshal(objectMap) +} + +// SystemData metadata pertaining to creation and last modification of the resource. +type SystemData struct { + // CreatedBy - The identity that created the resource. + CreatedBy *string `json:"createdBy,omitempty"` + // CreatedByType - The type of identity that created the resource. Possible values include: 'CreatedByTypeUser', 'CreatedByTypeApplication', 'CreatedByTypeManagedIdentity', 'CreatedByTypeKey' + CreatedByType CreatedByType `json:"createdByType,omitempty"` + // CreatedAt - The timestamp of resource creation (UTC). + CreatedAt *date.Time `json:"createdAt,omitempty"` + // LastModifiedBy - The identity that last modified the resource. + LastModifiedBy *string `json:"lastModifiedBy,omitempty"` + // LastModifiedByType - The type of identity that last modified the resource. Possible values include: 'CreatedByTypeUser', 'CreatedByTypeApplication', 'CreatedByTypeManagedIdentity', 'CreatedByTypeKey' + LastModifiedByType CreatedByType `json:"lastModifiedByType,omitempty"` + // LastModifiedAt - The timestamp of resource last modification (UTC) + LastModifiedAt *date.Time `json:"lastModifiedAt,omitempty"` +} + +// TrackedResource the resource model definition for an Azure Resource Manager tracked top level resource +// which has 'tags' and a 'location' +type TrackedResource struct { + // Tags - Resource tags. + Tags map[string]*string `json:"tags"` + // Location - The geo-location where the resource lives + Location *string `json:"location,omitempty"` + // ID - READ-ONLY; Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; The name of the resource + Name *string `json:"name,omitempty"` + // Type - READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for TrackedResource. +func (tr TrackedResource) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if tr.Tags != nil { + objectMap["tags"] = tr.Tags + } + if tr.Location != nil { + objectMap["location"] = tr.Location + } + return json.Marshal(objectMap) +} + +// UpdateResource represents an update resource +type UpdateResource struct { + // Tags - The tags of the resource. + Tags map[string]*string `json:"tags"` +} + +// MarshalJSON is the custom marshaler for UpdateResource. +func (ur UpdateResource) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if ur.Tags != nil { + objectMap["tags"] = ur.Tags + } + return json.Marshal(objectMap) +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/operations.go b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/operations.go new file mode 100644 index 000000000000..072c953b57aa --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/operations.go @@ -0,0 +1,99 @@ +package automanage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/tracing" +) + +// OperationsClient is the automanage Client +type OperationsClient struct { + BaseClient +} + +// NewOperationsClient creates an instance of the OperationsClient client. +func NewOperationsClient(subscriptionID string) OperationsClient { + return NewOperationsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewOperationsClientWithBaseURI creates an instance of the OperationsClient 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 NewOperationsClientWithBaseURI(baseURI string, subscriptionID string) OperationsClient { + return OperationsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// List lists all of the available Automanage REST API operations. +func (client OperationsClient) List(ctx context.Context) (result OperationListResult, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.List") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.ListPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.OperationsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.OperationsClient", "List", resp, "Failure sending request") + return + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.OperationsClient", "List", resp, "Failure responding to request") + return + } + + return +} + +// ListPreparer prepares the List request. +func (client OperationsClient) ListPreparer(ctx context.Context) (*http.Request, error) { + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPath("/providers/Microsoft.Automanage/operations"), + 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 OperationsClient) 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 OperationsClient) ListResponder(resp *http.Response) (result OperationListResult, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/reports.go b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/reports.go new file mode 100644 index 000000000000..c84277c676d1 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/reports.go @@ -0,0 +1,209 @@ +package automanage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "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" +) + +// ReportsClient is the automanage Client +type ReportsClient struct { + BaseClient +} + +// NewReportsClient creates an instance of the ReportsClient client. +func NewReportsClient(subscriptionID string) ReportsClient { + return NewReportsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewReportsClientWithBaseURI creates an instance of the ReportsClient 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 NewReportsClientWithBaseURI(baseURI string, subscriptionID string) ReportsClient { + return ReportsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// Get get information about a report associated with a configuration profile assignment run +// Parameters: +// resourceGroupName - the name of the resource group. The name is case insensitive. +// configurationProfileAssignmentName - the configuration profile assignment name. +// reportName - the report name. +// VMName - the name of the virtual machine. +func (client ReportsClient) Get(ctx context.Context, resourceGroupName string, configurationProfileAssignmentName string, reportName string, VMName string) (result Report, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ReportsClient.Get") + 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: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ReportsClient", "Get", err.Error()) + } + + req, err := client.GetPreparer(ctx, resourceGroupName, configurationProfileAssignmentName, reportName, VMName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ReportsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.ReportsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ReportsClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client ReportsClient) GetPreparer(ctx context.Context, resourceGroupName string, configurationProfileAssignmentName string, reportName string, VMName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "configurationProfileAssignmentName": autorest.Encode("path", configurationProfileAssignmentName), + "reportName": autorest.Encode("path", reportName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + "vmName": autorest.Encode("path", VMName), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/providers/Microsoft.Automanage/configurationProfileAssignments/{configurationProfileAssignmentName}/reports/{reportName}", 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 ReportsClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client ReportsClient) GetResponder(resp *http.Response) (result Report, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListByConfigurationProfileAssignments retrieve a list of reports within a given configuration profile assignment +// Parameters: +// resourceGroupName - the name of the resource group. The name is case insensitive. +// configurationProfileAssignmentName - the configuration profile assignment name. +// VMName - the name of the virtual machine. +func (client ReportsClient) ListByConfigurationProfileAssignments(ctx context.Context, resourceGroupName string, configurationProfileAssignmentName string, VMName string) (result ReportList, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ReportsClient.ListByConfigurationProfileAssignments") + 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: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ReportsClient", "ListByConfigurationProfileAssignments", err.Error()) + } + + req, err := client.ListByConfigurationProfileAssignmentsPreparer(ctx, resourceGroupName, configurationProfileAssignmentName, VMName) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ReportsClient", "ListByConfigurationProfileAssignments", nil, "Failure preparing request") + return + } + + resp, err := client.ListByConfigurationProfileAssignmentsSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.ReportsClient", "ListByConfigurationProfileAssignments", resp, "Failure sending request") + return + } + + result, err = client.ListByConfigurationProfileAssignmentsResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ReportsClient", "ListByConfigurationProfileAssignments", resp, "Failure responding to request") + return + } + + return +} + +// ListByConfigurationProfileAssignmentsPreparer prepares the ListByConfigurationProfileAssignments request. +func (client ReportsClient) ListByConfigurationProfileAssignmentsPreparer(ctx context.Context, resourceGroupName string, configurationProfileAssignmentName string, VMName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "configurationProfileAssignmentName": autorest.Encode("path", configurationProfileAssignmentName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + "vmName": autorest.Encode("path", VMName), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/providers/Microsoft.Automanage/configurationProfileAssignments/{configurationProfileAssignmentName}/reports", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListByConfigurationProfileAssignmentsSender sends the ListByConfigurationProfileAssignments request. The method will close the +// http.Response Body if it receives an error. +func (client ReportsClient) ListByConfigurationProfileAssignmentsSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListByConfigurationProfileAssignmentsResponder handles the response to the ListByConfigurationProfileAssignments request. The method always +// closes the http.Response Body. +func (client ReportsClient) ListByConfigurationProfileAssignmentsResponder(resp *http.Response) (result ReportList, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/serviceprincipals.go b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/serviceprincipals.go new file mode 100644 index 000000000000..d72001b77795 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/serviceprincipals.go @@ -0,0 +1,188 @@ +package automanage + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "net/http" + + "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" +) + +// ServicePrincipalsClient is the automanage Client +type ServicePrincipalsClient struct { + BaseClient +} + +// NewServicePrincipalsClient creates an instance of the ServicePrincipalsClient client. +func NewServicePrincipalsClient(subscriptionID string) ServicePrincipalsClient { + return NewServicePrincipalsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewServicePrincipalsClientWithBaseURI creates an instance of the ServicePrincipalsClient 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 NewServicePrincipalsClientWithBaseURI(baseURI string, subscriptionID string) ServicePrincipalsClient { + return ServicePrincipalsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// Get get the Automanage AAD first party Application Service Principal details for the subscription id. +func (client ServicePrincipalsClient) Get(ctx context.Context) (result ServicePrincipal, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ServicePrincipalsClient.Get") + 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: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ServicePrincipalsClient", "Get", err.Error()) + } + + req, err := client.GetPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ServicePrincipalsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.ServicePrincipalsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ServicePrincipalsClient", "Get", resp, "Failure responding to request") + return + } + + return +} + +// GetPreparer prepares the Get request. +func (client ServicePrincipalsClient) GetPreparer(ctx context.Context) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Automanage/servicePrincipals/default", 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 ServicePrincipalsClient) GetSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client ServicePrincipalsClient) GetResponder(resp *http.Response) (result ServicePrincipal, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListBySubscription get the Automanage AAD first party Application Service Principal details for the subscription id. +func (client ServicePrincipalsClient) ListBySubscription(ctx context.Context) (result ServicePrincipalListResult, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ServicePrincipalsClient.ListBySubscription") + 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: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("automanage.ServicePrincipalsClient", "ListBySubscription", err.Error()) + } + + req, err := client.ListBySubscriptionPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ServicePrincipalsClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + resp, err := client.ListBySubscriptionSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automanage.ServicePrincipalsClient", "ListBySubscription", resp, "Failure sending request") + return + } + + result, err = client.ListBySubscriptionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automanage.ServicePrincipalsClient", "ListBySubscription", resp, "Failure responding to request") + return + } + + return +} + +// ListBySubscriptionPreparer prepares the ListBySubscription request. +func (client ServicePrincipalsClient) ListBySubscriptionPreparer(ctx context.Context) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2022-05-04" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Automanage/servicePrincipals", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListBySubscriptionSender sends the ListBySubscription request. The method will close the +// http.Response Body if it receives an error. +func (client ServicePrincipalsClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListBySubscriptionResponder handles the response to the ListBySubscription request. The method always +// closes the http.Response Body. +func (client ServicePrincipalsClient) ListBySubscriptionResponder(resp *http.Response) (result ServicePrincipalListResult, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/version.go b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/version.go new file mode 100644 index 000000000000..34adf4eb2f11 --- /dev/null +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/version.go @@ -0,0 +1,19 @@ +package automanage + +import "github.com/Azure/azure-sdk-for-go/version" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// +// 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() + " automanage/2022-05-04" +} + +// 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 02c76c616995..44cf8a998365 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -600,6 +600,7 @@ github.com/tombuildsstuff/giovanni/storage/internal/metadata github.com/tombuildsstuff/giovanni/version # github.com/tombuildsstuff/kermit v0.20221104.1101437 ## explicit; go 1.18 +github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage github.com/tombuildsstuff/kermit/sdk/compute/2022-08-01/compute github.com/tombuildsstuff/kermit/sdk/iothub/2022-04-30-preview/iothub github.com/tombuildsstuff/kermit/sdk/network/2022-05-01/network diff --git a/website/docs/r/automanage_configuration_profiles.html.markdown b/website/docs/r/automanage_configuration_profiles.html.markdown new file mode 100644 index 000000000000..3d856f815168 --- /dev/null +++ b/website/docs/r/automanage_configuration_profiles.html.markdown @@ -0,0 +1,78 @@ +--- +subcategory: "Automanage" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_automanage_configuration_profile" +description: |- +Manages a automanage ConfigurationProfile. +--- + +# azurerm_automanage_configuration_profile + +Manages a automanage ConfigurationProfile. + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "example-automanage" + location = "West Europe" +} + +resource "azurerm_automanage_configuration_profile" "example" { + name = "example-configurationprofile" + resource_group_name = azurerm_resource_group.example.name + location = azurerm_resource_group.example.location + configuration_json = jsonencode({ + "Antimalware/Enable":false, + "AzureSecurityCenter/Enable":true, + "Backup/Enable":false, + "BootDiagnostics/Enable":true, + "ChangeTrackingAndInventory/Enable":true, + "GuestConfiguration/Enable":true, + "LogAnalytics/Enable":true, + "UpdateManagement/Enable":true, + "VMInsights/Enable":true + }) +} +``` + +## Arguments Reference + +The following arguments are supported: + +* `name` - (Required) The name which should be used for this automanage ConfigurationProfile. Changing this forces a new automanage ConfigurationProfile to be created. + +* `resource_group_name` - (Required) The name of the Resource Group where the automanage ConfigurationProfile should exist. Changing this forces a new automanage ConfigurationProfile to be created. + +* `location` - (Required) The Azure Region where the automanage ConfigurationProfile should exist. Changing this forces a new automanage ConfigurationProfile to be created. + +* `configuration_json` - (Required) configuration dictionary of the configuration profile. Changing this forces a new automanage ConfigurationProfile to be created. + +--- + +* `tags` - (Optional) A mapping of tags which should be assigned to the automanage ConfigurationProfile. + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `id` - The ID of the automanage ConfigurationProfile. + +* `type` - The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts". + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: + +* `create` - (Defaults to 30 minutes) Used when creating the automanage ConfigurationProfile. +* `read` - (Defaults to 5 minutes) Used when retrieving the automanage ConfigurationProfile. +* `update` - (Defaults to 30 minutes) Used when updating the automanage ConfigurationProfile. +* `delete` - (Defaults to 30 minutes) Used when deleting the automanage ConfigurationProfile. + +## Import + +automanage ConfigurationProfiles can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_automanage_configuration_profile.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Automanage/configurationProfiles/configurationProfile1 +``` \ No newline at end of file From 48a5795154a132c595ec4a1b3e6c33ea5e4f6c0a Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Fri, 18 Nov 2022 11:28:57 +0800 Subject: [PATCH 02/27] remove unnecessary code piece --- .../automanage_configuration_profile_resource.go | 7 +++---- internal/services/automanage/client/client.go | 14 ++------------ 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/internal/services/automanage/automanage_configuration_profile_resource.go b/internal/services/automanage/automanage_configuration_profile_resource.go index 4b0278740298..95deddbadbb5 100644 --- a/internal/services/automanage/automanage_configuration_profile_resource.go +++ b/internal/services/automanage/automanage_configuration_profile_resource.go @@ -6,7 +6,6 @@ import ( "fmt" "time" - "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" @@ -84,11 +83,11 @@ func (r AutoManageConfigurationProfileResource) Create() sdk.ResourceFunc { subscriptionId := metadata.Client.Account.SubscriptionId id := parse.NewAutomanageConfigurationProfileID(subscriptionId, model.ResourceGroupName, model.Name) existing, err := client.Get(ctx, id.ConfigurationProfileName, id.ResourceGroup) - if err != nil && !response.WasNotFound(existing.Response.Response) { + if err != nil && !utils.ResponseWasNotFound(existing.Response) { return fmt.Errorf("checking for existing %s: %+v", id, err) } - if !response.WasNotFound(existing.Response.Response) { + if !utils.ResponseWasNotFound(existing.Response) { return metadata.ResourceRequiresImport(r.ResourceType(), id) } @@ -176,7 +175,7 @@ func (r AutoManageConfigurationProfileResource) Read() sdk.ResourceFunc { resp, err := client.Get(ctx, id.ConfigurationProfileName, id.ResourceGroup) if err != nil { - if response.WasNotFound(resp.Response.Response) { + if utils.ResponseWasNotFound(resp.Response) { return metadata.MarkAsGone(id) } diff --git a/internal/services/automanage/client/client.go b/internal/services/automanage/client/client.go index 8d93bf7d38a0..7c0734a4241b 100644 --- a/internal/services/automanage/client/client.go +++ b/internal/services/automanage/client/client.go @@ -6,24 +6,14 @@ import ( ) type Client struct { - ConfigurationProfileClient *automanage.ConfigurationProfilesClient - ConfigurationProfileAssignmentClient *automanage.ConfigurationProfileAssignmentsClient - ConfigurationProfileHCIAssignmentClient *automanage.ConfigurationProfileHCIAssignmentsClient + ConfigurationProfileClient *automanage.ConfigurationProfilesClient } func NewClient(o *common.ClientOptions) *Client { configurationProfileClient := automanage.NewConfigurationProfilesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&configurationProfileClient.Client, o.ResourceManagerAuthorizer) - configurationProfileAssignmentClient := automanage.NewConfigurationProfileAssignmentsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) - o.ConfigureClient(&configurationProfileAssignmentClient.Client, o.ResourceManagerAuthorizer) - - configurationProfileHCIAssignmentClient := automanage.NewConfigurationProfileHCIAssignmentsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) - o.ConfigureClient(&configurationProfileHCIAssignmentClient.Client, o.ResourceManagerAuthorizer) - return &Client{ - ConfigurationProfileClient: &configurationProfileClient, - ConfigurationProfileAssignmentClient: &configurationProfileAssignmentClient, - ConfigurationProfileHCIAssignmentClient: &configurationProfileHCIAssignmentClient, + ConfigurationProfileClient: &configurationProfileClient, } } From 16f22455093f8ba4a062f715287f7b66add7b1f6 Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Fri, 18 Nov 2022 15:58:36 +0800 Subject: [PATCH 03/27] change name to align with RP --- internal/clients/client.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/clients/client.go b/internal/clients/client.go index 2713795ca084..69522609f823 100644 --- a/internal/clients/client.go +++ b/internal/clients/client.go @@ -140,7 +140,7 @@ type Client struct { AppService *appService.Client Attestation *attestation.Client Authorization *authorization.Client - AutoManage *automanage.Client + Automanage *automanage.Client Automation *automation.Client AzureStackHCI *azureStackHCI.Client Batch *batch.Client @@ -263,7 +263,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error client.AppService = appService.NewClient(o) client.Attestation = attestation.NewClient(o) client.Authorization = authorization.NewClient(o) - client.AutoManage = automanage.NewClient(o) + client.Automanage = automanage.NewClient(o) client.Automation = automation.NewClient(o) client.AzureStackHCI = azureStackHCI.NewClient(o) client.Batch = batch.NewClient(o) From ffdf97d955d9ebc7b50f1e6df0d21ebcbe434470 Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Fri, 18 Nov 2022 16:19:32 +0800 Subject: [PATCH 04/27] change name to align with RP --- .../automanage_configuration_profile_resource.go | 8 ++++---- .../automanage_configuration_profile_resource_test.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/services/automanage/automanage_configuration_profile_resource.go b/internal/services/automanage/automanage_configuration_profile_resource.go index 95deddbadbb5..633f33d5db7a 100644 --- a/internal/services/automanage/automanage_configuration_profile_resource.go +++ b/internal/services/automanage/automanage_configuration_profile_resource.go @@ -79,7 +79,7 @@ func (r AutoManageConfigurationProfileResource) Create() sdk.ResourceFunc { return fmt.Errorf("decoding: %+v", err) } - client := metadata.Client.AutoManage.ConfigurationProfileClient + client := metadata.Client.Automanage.ConfigurationProfileClient subscriptionId := metadata.Client.Account.SubscriptionId id := parse.NewAutomanageConfigurationProfileID(subscriptionId, model.ResourceGroupName, model.Name) existing, err := client.Get(ctx, id.ConfigurationProfileName, id.ResourceGroup) @@ -120,7 +120,7 @@ func (r AutoManageConfigurationProfileResource) Update() sdk.ResourceFunc { return sdk.ResourceFunc{ Timeout: 30 * time.Minute, Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { - client := metadata.Client.AutoManage.ConfigurationProfileClient + client := metadata.Client.Automanage.ConfigurationProfileClient id, err := parse.AutomanageConfigurationProfileID(metadata.ResourceData.Id()) if err != nil { @@ -166,7 +166,7 @@ func (r AutoManageConfigurationProfileResource) Read() sdk.ResourceFunc { return sdk.ResourceFunc{ Timeout: 5 * time.Minute, Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { - client := metadata.Client.AutoManage.ConfigurationProfileClient + client := metadata.Client.Automanage.ConfigurationProfileClient id, err := parse.AutomanageConfigurationProfileID(metadata.ResourceData.Id()) if err != nil { @@ -211,7 +211,7 @@ func (r AutoManageConfigurationProfileResource) Delete() sdk.ResourceFunc { return sdk.ResourceFunc{ Timeout: 30 * time.Minute, Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { - client := metadata.Client.AutoManage.ConfigurationProfileClient + client := metadata.Client.Automanage.ConfigurationProfileClient id, err := parse.AutomanageConfigurationProfileID(metadata.ResourceData.Id()) if err != nil { diff --git a/internal/services/automanage/automanage_configuration_profile_resource_test.go b/internal/services/automanage/automanage_configuration_profile_resource_test.go index 751be03c822a..635239917232 100644 --- a/internal/services/automanage/automanage_configuration_profile_resource_test.go +++ b/internal/services/automanage/automanage_configuration_profile_resource_test.go @@ -85,7 +85,7 @@ func (r AutoManageConfigurationProfileResource) Exists(ctx context.Context, clie return nil, err } - client := clients.AutoManage.ConfigurationProfileClient + client := clients.Automanage.ConfigurationProfileClient resp, err := client.Get(ctx, id.ConfigurationProfileName, id.ResourceGroup) if err != nil { if response.WasNotFound(resp.Response.Response) { From e61a47b889f12d056f0130de50090c7a397b6a4f Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Fri, 18 Nov 2022 17:05:21 +0800 Subject: [PATCH 05/27] change test case format using terrafmt tool --- ...age_configuration_profile_resource_test.go | 80 +++++++++---------- ...anage_configuration_profiles.html.markdown | 22 ++--- 2 files changed, 51 insertions(+), 51 deletions(-) diff --git a/internal/services/automanage/automanage_configuration_profile_resource_test.go b/internal/services/automanage/automanage_configuration_profile_resource_test.go index 635239917232..7532842f61e6 100644 --- a/internal/services/automanage/automanage_configuration_profile_resource_test.go +++ b/internal/services/automanage/automanage_configuration_profile_resource_test.go @@ -118,16 +118,16 @@ resource "azurerm_automanage_configuration_profile" "test" { name = "acctest-amcp-%d" resource_group_name = azurerm_resource_group.test.name location = "%s" - configuration_json = jsonencode({ - "Antimalware/Enable":false, - "AzureSecurityCenter/Enable":true, - "Backup/Enable":false, - "BootDiagnostics/Enable":true, - "ChangeTrackingAndInventory/Enable":true, - "GuestConfiguration/Enable":true, - "LogAnalytics/Enable":true, - "UpdateManagement/Enable":true, - "VMInsights/Enable":true + configuration_json = jsonencode({ + "Antimalware/Enable" : false, + "AzureSecurityCenter/Enable" : true, + "Backup/Enable" : false, + "BootDiagnostics/Enable" : true, + "ChangeTrackingAndInventory/Enable" : true, + "GuestConfiguration/Enable" : true, + "LogAnalytics/Enable" : true, + "UpdateManagement/Enable" : true, + "VMInsights/Enable" : true }) } `, template, data.RandomInteger, data.Locations.Primary) @@ -142,16 +142,16 @@ resource "azurerm_automanage_configuration_profile" "import" { name = azurerm_automanage_configuration_profile.test.name resource_group_name = azurerm_resource_group.test.name location = "%s" - configuration_json = jsonencode({ - "Antimalware/Enable":false, - "AzureSecurityCenter/Enable":true, - "Backup/Enable":false, - "BootDiagnostics/Enable":true, - "ChangeTrackingAndInventory/Enable":true, - "GuestConfiguration/Enable":true, - "LogAnalytics/Enable":true, - "UpdateManagement/Enable":true, - "VMInsights/Enable":true + configuration_json = jsonencode({ + "Antimalware/Enable" : false, + "AzureSecurityCenter/Enable" : true, + "Backup/Enable" : false, + "BootDiagnostics/Enable" : true, + "ChangeTrackingAndInventory/Enable" : true, + "GuestConfiguration/Enable" : true, + "LogAnalytics/Enable" : true, + "UpdateManagement/Enable" : true, + "VMInsights/Enable" : true }) } `, config, data.Locations.Primary) @@ -166,16 +166,16 @@ resource "azurerm_automanage_configuration_profile" "test" { name = "acctest-amcp-%d" resource_group_name = azurerm_resource_group.test.name location = "%s" - configuration_json = jsonencode({ - "Antimalware/Enable":false, - "AzureSecurityCenter/Enable":true, - "Backup/Enable":false, - "BootDiagnostics/Enable":true, - "ChangeTrackingAndInventory/Enable":true, - "GuestConfiguration/Enable":true, - "LogAnalytics/Enable":true, - "UpdateManagement/Enable":true, - "VMInsights/Enable":true + configuration_json = jsonencode({ + "Antimalware/Enable" : false, + "AzureSecurityCenter/Enable" : true, + "Backup/Enable" : false, + "BootDiagnostics/Enable" : true, + "ChangeTrackingAndInventory/Enable" : true, + "GuestConfiguration/Enable" : true, + "LogAnalytics/Enable" : true, + "UpdateManagement/Enable" : true, + "VMInsights/Enable" : true }) tags = { key = "value" @@ -194,16 +194,16 @@ resource "azurerm_automanage_configuration_profile" "test" { name = "acctest-amcp-%d" resource_group_name = azurerm_resource_group.test.name location = "%s" - configuration_json = jsonencode({ - "Antimalware/Enable":false, - "AzureSecurityCenter/Enable":true, - "Backup/Enable":true, - "BootDiagnostics/Enable":true, - "ChangeTrackingAndInventory/Enable":true, - "GuestConfiguration/Enable":true, - "LogAnalytics/Enable":true, - "UpdateManagement/Enable":true, - "VMInsights/Enable":true + configuration_json = jsonencode({ + "Antimalware/Enable" : false, + "AzureSecurityCenter/Enable" : true, + "Backup/Enable" : true, + "BootDiagnostics/Enable" : true, + "ChangeTrackingAndInventory/Enable" : true, + "GuestConfiguration/Enable" : true, + "LogAnalytics/Enable" : true, + "UpdateManagement/Enable" : true, + "VMInsights/Enable" : true }) tags = { key2 = "value2" diff --git a/website/docs/r/automanage_configuration_profiles.html.markdown b/website/docs/r/automanage_configuration_profiles.html.markdown index 3d856f815168..128b62629836 100644 --- a/website/docs/r/automanage_configuration_profiles.html.markdown +++ b/website/docs/r/automanage_configuration_profiles.html.markdown @@ -22,16 +22,16 @@ resource "azurerm_automanage_configuration_profile" "example" { name = "example-configurationprofile" resource_group_name = azurerm_resource_group.example.name location = azurerm_resource_group.example.location - configuration_json = jsonencode({ - "Antimalware/Enable":false, - "AzureSecurityCenter/Enable":true, - "Backup/Enable":false, - "BootDiagnostics/Enable":true, - "ChangeTrackingAndInventory/Enable":true, - "GuestConfiguration/Enable":true, - "LogAnalytics/Enable":true, - "UpdateManagement/Enable":true, - "VMInsights/Enable":true + configuration_json = jsonencode({ + "Antimalware/Enable" : false, + "AzureSecurityCenter/Enable" : true, + "Backup/Enable" : false, + "BootDiagnostics/Enable" : true, + "ChangeTrackingAndInventory/Enable" : true, + "GuestConfiguration/Enable" : true, + "LogAnalytics/Enable" : true, + "UpdateManagement/Enable" : true, + "VMInsights/Enable" : true }) } ``` @@ -75,4 +75,4 @@ automanage ConfigurationProfiles can be imported using the `resource id`, e.g. ```shell terraform import azurerm_automanage_configuration_profile.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Automanage/configurationProfiles/configurationProfile1 -``` \ No newline at end of file +``` From 3933c8bd338f5b4cc6de99fc372dead52e3689e5 Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Fri, 18 Nov 2022 17:12:38 +0800 Subject: [PATCH 06/27] update for website allowed-subcategories --- website/allowed-subcategories | 1 + 1 file changed, 1 insertion(+) diff --git a/website/allowed-subcategories b/website/allowed-subcategories index 86a8b0778e7b..8d7bf4cc5eee 100644 --- a/website/allowed-subcategories +++ b/website/allowed-subcategories @@ -8,6 +8,7 @@ App Service (Web Apps) Application Insights Attestation Authorization +Automanage Automation Azure Stack HCI Base From fa3943fb83c5b8ee53ecb48c88981701fa0ab7ae Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Fri, 18 Nov 2022 17:17:06 +0800 Subject: [PATCH 07/27] update for website allowed-subcategories --- website/docs/r/automanage_configuration_profiles.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/automanage_configuration_profiles.html.markdown b/website/docs/r/automanage_configuration_profiles.html.markdown index 128b62629836..6f4bdfa78134 100644 --- a/website/docs/r/automanage_configuration_profiles.html.markdown +++ b/website/docs/r/automanage_configuration_profiles.html.markdown @@ -3,7 +3,7 @@ subcategory: "Automanage" layout: "azurerm" page_title: "Azure Resource Manager: azurerm_automanage_configuration_profile" description: |- -Manages a automanage ConfigurationProfile. + Manages a automanage ConfigurationProfile. --- # azurerm_automanage_configuration_profile From d6a0ce8b66d3d02114874b43d92999da2ed21772 Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Mon, 21 Nov 2022 21:25:32 +0800 Subject: [PATCH 08/27] update with make generate --- .github/labeler-pull-request-triage.yml | 3 +++ .teamcity/components/generated/services.kt | 1 + 2 files changed, 4 insertions(+) diff --git a/.github/labeler-pull-request-triage.yml b/.github/labeler-pull-request-triage.yml index f36e9cd5d889..1e09ab8cfb61 100644 --- a/.github/labeler-pull-request-triage.yml +++ b/.github/labeler-pull-request-triage.yml @@ -35,6 +35,9 @@ service/authorization: - internal/services/authorization/**/* - internal/services/managedidentity/**/* +service/automanage: + - internal/services/automanage/**/* + service/automation: - internal/services/automation/**/* diff --git a/.teamcity/components/generated/services.kt b/.teamcity/components/generated/services.kt index 084b18f6e789..647120213afa 100644 --- a/.teamcity/components/generated/services.kt +++ b/.teamcity/components/generated/services.kt @@ -10,6 +10,7 @@ var services = mapOf( "applicationinsights" to "Application Insights", "attestation" to "Attestation", "authorization" to "Authorization", + "automanage" to "Automanage", "automation" to "Automation", "azurestackhci" to "Azure Stack HCI", "batch" to "Batch", From 1eec71dc3d2f71f47700eaf8fa03a2c4f79bcb1c Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Tue, 22 Nov 2022 10:52:51 +0800 Subject: [PATCH 09/27] update with latest update msg --- vendor/modules.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/vendor/modules.txt b/vendor/modules.txt index bf72ce9e5653..452784129ed0 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -604,6 +604,7 @@ github.com/tombuildsstuff/giovanni/version # github.com/tombuildsstuff/kermit v0.20221116.1100927 ## explicit; go 1.18 github.com/tombuildsstuff/kermit/sdk/appplatform/2022-09-01-preview/appplatform +github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage github.com/tombuildsstuff/kermit/sdk/compute/2022-08-01/compute github.com/tombuildsstuff/kermit/sdk/iothub/2022-04-30-preview/iothub github.com/tombuildsstuff/kermit/sdk/network/2022-05-01/network From 7c74819d6c8df92a1244de79c6baf1a80ee98083 Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Tue, 29 Nov 2022 11:07:55 +0800 Subject: [PATCH 10/27] remove setting for read-only properties. --- .../automanage/automanage_configuration_profile_resource.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/services/automanage/automanage_configuration_profile_resource.go b/internal/services/automanage/automanage_configuration_profile_resource.go index 633f33d5db7a..4444ff0642d3 100644 --- a/internal/services/automanage/automanage_configuration_profile_resource.go +++ b/internal/services/automanage/automanage_configuration_profile_resource.go @@ -147,8 +147,6 @@ func (r AutoManageConfigurationProfileResource) Update() sdk.ResourceFunc { resp.Properties.Configuration = &configurationValue } - resp.SystemData = nil - if metadata.ResourceData.HasChange("tags") { resp.Tags = tags.FromTypedObject(model.Tags) } From 2215f0777a9312d873077bd8dfff7b57512d7cee Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Thu, 1 Dec 2022 10:06:09 +0800 Subject: [PATCH 11/27] rename "azurerm_automanage_configuration_profile" to "azurerm_automanage_configuration" --- ...o => automanage_configuration_resource.go} | 52 +++++++++---------- ...automanage_configuration_resource_test.go} | 22 ++++---- internal/services/automanage/client/client.go | 4 +- ...profile.go => automanage_configuration.go} | 18 +++---- ...st.go => automanage_configuration_test.go} | 14 ++--- internal/services/automanage/registration.go | 2 +- internal/services/automanage/resourceid.go | 2 +- ...e_id.go => automanage_configuration_id.go} | 4 +- ...go => automanage_configuration_id_test.go} | 4 +- ...=> automanage_configuration.html.markdown} | 8 +-- 10 files changed, 65 insertions(+), 65 deletions(-) rename internal/services/automanage/{automanage_configuration_profile_resource.go => automanage_configuration_resource.go} (74%) rename internal/services/automanage/{automanage_configuration_profile_resource_test.go => automanage_configuration_resource_test.go} (91%) rename internal/services/automanage/parse/{automanage_configuration_profile.go => automanage_configuration.go} (68%) rename internal/services/automanage/parse/{automanage_configuration_profile_test.go => automanage_configuration_test.go} (85%) rename internal/services/automanage/validate/{automanage_configuration_profile_id.go => automanage_configuration_id.go} (68%) rename internal/services/automanage/validate/{automanage_configuration_profile_id_test.go => automanage_configuration_id_test.go} (93%) rename website/docs/r/{automanage_configuration_profiles.html.markdown => automanage_configuration.html.markdown} (88%) diff --git a/internal/services/automanage/automanage_configuration_profile_resource.go b/internal/services/automanage/automanage_configuration_resource.go similarity index 74% rename from internal/services/automanage/automanage_configuration_profile_resource.go rename to internal/services/automanage/automanage_configuration_resource.go index 633f33d5db7a..7004203d489f 100644 --- a/internal/services/automanage/automanage_configuration_profile_resource.go +++ b/internal/services/automanage/automanage_configuration_resource.go @@ -18,7 +18,7 @@ import ( "github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage" ) -type AutoManageConfigurationProfileModel struct { +type AutoManageConfigurationModel struct { Name string `tfschema:"name"` ResourceGroupName string `tfschema:"resource_group_name"` Configuration string `tfschema:"configuration_json"` @@ -26,23 +26,23 @@ type AutoManageConfigurationProfileModel struct { Tags map[string]string `tfschema:"tags"` } -type AutoManageConfigurationProfileResource struct{} +type AutoManageConfigurationResource struct{} -var _ sdk.ResourceWithUpdate = AutoManageConfigurationProfileResource{} +var _ sdk.ResourceWithUpdate = AutoManageConfigurationResource{} -func (r AutoManageConfigurationProfileResource) ResourceType() string { - return "azurerm_automanage_configuration_profile" +func (r AutoManageConfigurationResource) ResourceType() string { + return "azurerm_automanage_configuration" } -func (r AutoManageConfigurationProfileResource) ModelObject() interface{} { - return &AutoManageConfigurationProfileModel{} +func (r AutoManageConfigurationResource) ModelObject() interface{} { + return &AutoManageConfigurationModel{} } -func (r AutoManageConfigurationProfileResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { - return validate.AutomanageConfigurationProfileID +func (r AutoManageConfigurationResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { + return validate.AutomanageConfigurationID } -func (r AutoManageConfigurationProfileResource) Arguments() map[string]*pluginsdk.Schema { +func (r AutoManageConfigurationResource) Arguments() map[string]*pluginsdk.Schema { return map[string]*pluginsdk.Schema{ "name": { Type: pluginsdk.TypeString, @@ -66,22 +66,22 @@ func (r AutoManageConfigurationProfileResource) Arguments() map[string]*pluginsd } } -func (r AutoManageConfigurationProfileResource) Attributes() map[string]*pluginsdk.Schema { +func (r AutoManageConfigurationResource) Attributes() map[string]*pluginsdk.Schema { return map[string]*pluginsdk.Schema{} } -func (r AutoManageConfigurationProfileResource) Create() sdk.ResourceFunc { +func (r AutoManageConfigurationResource) Create() sdk.ResourceFunc { return sdk.ResourceFunc{ Timeout: 30 * time.Minute, Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { - var model AutoManageConfigurationProfileModel + var model AutoManageConfigurationModel if err := metadata.Decode(&model); err != nil { return fmt.Errorf("decoding: %+v", err) } - client := metadata.Client.Automanage.ConfigurationProfileClient + client := metadata.Client.Automanage.ConfigurationClient subscriptionId := metadata.Client.Account.SubscriptionId - id := parse.NewAutomanageConfigurationProfileID(subscriptionId, model.ResourceGroupName, model.Name) + id := parse.NewAutomanageConfigurationID(subscriptionId, model.ResourceGroupName, model.Name) existing, err := client.Get(ctx, id.ConfigurationProfileName, id.ResourceGroup) if err != nil && !utils.ResponseWasNotFound(existing.Response) { return fmt.Errorf("checking for existing %s: %+v", id, err) @@ -116,18 +116,18 @@ func (r AutoManageConfigurationProfileResource) Create() sdk.ResourceFunc { } } -func (r AutoManageConfigurationProfileResource) Update() sdk.ResourceFunc { +func (r AutoManageConfigurationResource) Update() sdk.ResourceFunc { return sdk.ResourceFunc{ Timeout: 30 * time.Minute, Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { - client := metadata.Client.Automanage.ConfigurationProfileClient + client := metadata.Client.Automanage.ConfigurationClient - id, err := parse.AutomanageConfigurationProfileID(metadata.ResourceData.Id()) + id, err := parse.AutomanageConfigurationID(metadata.ResourceData.Id()) if err != nil { return err } - var model AutoManageConfigurationProfileModel + var model AutoManageConfigurationModel if err := metadata.Decode(&model); err != nil { return fmt.Errorf("decoding: %+v", err) } @@ -162,13 +162,13 @@ func (r AutoManageConfigurationProfileResource) Update() sdk.ResourceFunc { } } -func (r AutoManageConfigurationProfileResource) Read() sdk.ResourceFunc { +func (r AutoManageConfigurationResource) Read() sdk.ResourceFunc { return sdk.ResourceFunc{ Timeout: 5 * time.Minute, Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { - client := metadata.Client.Automanage.ConfigurationProfileClient + client := metadata.Client.Automanage.ConfigurationClient - id, err := parse.AutomanageConfigurationProfileID(metadata.ResourceData.Id()) + id, err := parse.AutomanageConfigurationID(metadata.ResourceData.Id()) if err != nil { return err } @@ -182,7 +182,7 @@ func (r AutoManageConfigurationProfileResource) Read() sdk.ResourceFunc { return fmt.Errorf("retrieving %s: %+v", *id, err) } - state := AutoManageConfigurationProfileModel{ + state := AutoManageConfigurationModel{ Name: id.ConfigurationProfileName, ResourceGroupName: id.ResourceGroup, Location: location.NormalizeNilable(resp.Location), @@ -207,13 +207,13 @@ func (r AutoManageConfigurationProfileResource) Read() sdk.ResourceFunc { } } -func (r AutoManageConfigurationProfileResource) Delete() sdk.ResourceFunc { +func (r AutoManageConfigurationResource) Delete() sdk.ResourceFunc { return sdk.ResourceFunc{ Timeout: 30 * time.Minute, Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { - client := metadata.Client.Automanage.ConfigurationProfileClient + client := metadata.Client.Automanage.ConfigurationClient - id, err := parse.AutomanageConfigurationProfileID(metadata.ResourceData.Id()) + id, err := parse.AutomanageConfigurationID(metadata.ResourceData.Id()) if err != nil { return err } diff --git a/internal/services/automanage/automanage_configuration_profile_resource_test.go b/internal/services/automanage/automanage_configuration_resource_test.go similarity index 91% rename from internal/services/automanage/automanage_configuration_profile_resource_test.go rename to internal/services/automanage/automanage_configuration_resource_test.go index 7532842f61e6..6b3a2553ce34 100644 --- a/internal/services/automanage/automanage_configuration_profile_resource_test.go +++ b/internal/services/automanage/automanage_configuration_resource_test.go @@ -17,7 +17,7 @@ import ( type AutoManageConfigurationProfileResource struct{} func TestAccAutoManageConfigurationProfile_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_automanage_configuration_profile", "test") + data := acceptance.BuildTestData(t, "azurerm_automanage_configuration", "test") r := AutoManageConfigurationProfileResource{} data.ResourceTest(t, r, []acceptance.TestStep{ { @@ -31,7 +31,7 @@ func TestAccAutoManageConfigurationProfile_basic(t *testing.T) { } func TestAccAutoManageConfigurationProfile_requiresImport(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_automanage_configuration_profile", "test") + data := acceptance.BuildTestData(t, "azurerm_automanage_configuration", "test") r := AutoManageConfigurationProfileResource{} data.ResourceTest(t, r, []acceptance.TestStep{ { @@ -45,7 +45,7 @@ func TestAccAutoManageConfigurationProfile_requiresImport(t *testing.T) { } func TestAccAutoManageConfigurationProfile_complete(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_automanage_configuration_profile", "test") + data := acceptance.BuildTestData(t, "azurerm_automanage_configuration", "test") r := AutoManageConfigurationProfileResource{} data.ResourceTest(t, r, []acceptance.TestStep{ { @@ -59,7 +59,7 @@ func TestAccAutoManageConfigurationProfile_complete(t *testing.T) { } func TestAccAutoManageConfigurationProfile_update(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_automanage_configuration_profile", "test") + data := acceptance.BuildTestData(t, "azurerm_automanage_configuration", "test") r := AutoManageConfigurationProfileResource{} data.ResourceTest(t, r, []acceptance.TestStep{ { @@ -80,12 +80,12 @@ func TestAccAutoManageConfigurationProfile_update(t *testing.T) { } func (r AutoManageConfigurationProfileResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := parse.AutomanageConfigurationProfileID(state.ID) + id, err := parse.AutomanageConfigurationID(state.ID) if err != nil { return nil, err } - client := clients.Automanage.ConfigurationProfileClient + client := clients.Automanage.ConfigurationClient resp, err := client.Get(ctx, id.ConfigurationProfileName, id.ResourceGroup) if err != nil { if response.WasNotFound(resp.Response.Response) { @@ -114,7 +114,7 @@ func (r AutoManageConfigurationProfileResource) basic(data acceptance.TestData) return fmt.Sprintf(` %s -resource "azurerm_automanage_configuration_profile" "test" { +resource "azurerm_automanage_configuration" "test" { name = "acctest-amcp-%d" resource_group_name = azurerm_resource_group.test.name location = "%s" @@ -138,8 +138,8 @@ func (r AutoManageConfigurationProfileResource) requiresImport(data acceptance.T return fmt.Sprintf(` %s -resource "azurerm_automanage_configuration_profile" "import" { - name = azurerm_automanage_configuration_profile.test.name +resource "azurerm_automanage_configuration" "import" { + name = azurerm_automanage_configuration.test.name resource_group_name = azurerm_resource_group.test.name location = "%s" configuration_json = jsonencode({ @@ -162,7 +162,7 @@ func (r AutoManageConfigurationProfileResource) complete(data acceptance.TestDat return fmt.Sprintf(` %s -resource "azurerm_automanage_configuration_profile" "test" { +resource "azurerm_automanage_configuration" "test" { name = "acctest-amcp-%d" resource_group_name = azurerm_resource_group.test.name location = "%s" @@ -190,7 +190,7 @@ func (r AutoManageConfigurationProfileResource) update(data acceptance.TestData) return fmt.Sprintf(` %s -resource "azurerm_automanage_configuration_profile" "test" { +resource "azurerm_automanage_configuration" "test" { name = "acctest-amcp-%d" resource_group_name = azurerm_resource_group.test.name location = "%s" diff --git a/internal/services/automanage/client/client.go b/internal/services/automanage/client/client.go index 7c0734a4241b..977ee8e428d4 100644 --- a/internal/services/automanage/client/client.go +++ b/internal/services/automanage/client/client.go @@ -6,7 +6,7 @@ import ( ) type Client struct { - ConfigurationProfileClient *automanage.ConfigurationProfilesClient + ConfigurationClient *automanage.ConfigurationProfilesClient } func NewClient(o *common.ClientOptions) *Client { @@ -14,6 +14,6 @@ func NewClient(o *common.ClientOptions) *Client { o.ConfigureClient(&configurationProfileClient.Client, o.ResourceManagerAuthorizer) return &Client{ - ConfigurationProfileClient: &configurationProfileClient, + ConfigurationClient: &configurationProfileClient, } } diff --git a/internal/services/automanage/parse/automanage_configuration_profile.go b/internal/services/automanage/parse/automanage_configuration.go similarity index 68% rename from internal/services/automanage/parse/automanage_configuration_profile.go rename to internal/services/automanage/parse/automanage_configuration.go index 865a2089eb37..10c9d0b44fde 100644 --- a/internal/services/automanage/parse/automanage_configuration_profile.go +++ b/internal/services/automanage/parse/automanage_configuration.go @@ -9,42 +9,42 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" ) -type AutomanageConfigurationProfileId struct { +type AutomanageConfigurationId struct { SubscriptionId string ResourceGroup string ConfigurationProfileName string } -func NewAutomanageConfigurationProfileID(subscriptionId, resourceGroup, configurationProfileName string) AutomanageConfigurationProfileId { - return AutomanageConfigurationProfileId{ +func NewAutomanageConfigurationID(subscriptionId, resourceGroup, configurationProfileName string) AutomanageConfigurationId { + return AutomanageConfigurationId{ SubscriptionId: subscriptionId, ResourceGroup: resourceGroup, ConfigurationProfileName: configurationProfileName, } } -func (id AutomanageConfigurationProfileId) String() string { +func (id AutomanageConfigurationId) String() string { segments := []string{ fmt.Sprintf("Configuration Profile Name %q", id.ConfigurationProfileName), fmt.Sprintf("Resource Group %q", id.ResourceGroup), } segmentsStr := strings.Join(segments, " / ") - return fmt.Sprintf("%s: (%s)", "Automanage Configuration Profile", segmentsStr) + return fmt.Sprintf("%s: (%s)", "Automanage Configuration", segmentsStr) } -func (id AutomanageConfigurationProfileId) ID() string { +func (id AutomanageConfigurationId) ID() string { fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Automanage/configurationProfiles/%s" return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.ConfigurationProfileName) } -// AutomanageConfigurationProfileID parses a AutomanageConfigurationProfile ID into an AutomanageConfigurationProfileId struct -func AutomanageConfigurationProfileID(input string) (*AutomanageConfigurationProfileId, error) { +// AutomanageConfigurationID parses a AutomanageConfiguration ID into an AutomanageConfigurationId struct +func AutomanageConfigurationID(input string) (*AutomanageConfigurationId, error) { id, err := resourceids.ParseAzureResourceID(input) if err != nil { return nil, err } - resourceId := AutomanageConfigurationProfileId{ + resourceId := AutomanageConfigurationId{ SubscriptionId: id.SubscriptionID, ResourceGroup: id.ResourceGroup, } diff --git a/internal/services/automanage/parse/automanage_configuration_profile_test.go b/internal/services/automanage/parse/automanage_configuration_test.go similarity index 85% rename from internal/services/automanage/parse/automanage_configuration_profile_test.go rename to internal/services/automanage/parse/automanage_configuration_test.go index 471a334a93e1..81fef858b5c6 100644 --- a/internal/services/automanage/parse/automanage_configuration_profile_test.go +++ b/internal/services/automanage/parse/automanage_configuration_test.go @@ -8,21 +8,21 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" ) -var _ resourceids.Id = AutomanageConfigurationProfileId{} +var _ resourceids.Id = AutomanageConfigurationId{} -func TestAutomanageConfigurationProfileIDFormatter(t *testing.T) { - actual := NewAutomanageConfigurationProfileID("12345678-1234-9876-4563-123456789012", "resourceGroup1", "configurationProfile1").ID() +func TestAutomanageConfigurationIDFormatter(t *testing.T) { + actual := NewAutomanageConfigurationID("12345678-1234-9876-4563-123456789012", "resourceGroup1", "configurationProfile1").ID() expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.Automanage/configurationProfiles/configurationProfile1" if actual != expected { t.Fatalf("Expected %q but got %q", expected, actual) } } -func TestAutomanageConfigurationProfileID(t *testing.T) { +func TestAutomanageConfigurationID(t *testing.T) { testData := []struct { Input string Error bool - Expected *AutomanageConfigurationProfileId + Expected *AutomanageConfigurationId }{ { @@ -70,7 +70,7 @@ func TestAutomanageConfigurationProfileID(t *testing.T) { { // valid Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.Automanage/configurationProfiles/configurationProfile1", - Expected: &AutomanageConfigurationProfileId{ + Expected: &AutomanageConfigurationId{ SubscriptionId: "12345678-1234-9876-4563-123456789012", ResourceGroup: "resourceGroup1", ConfigurationProfileName: "configurationProfile1", @@ -87,7 +87,7 @@ func TestAutomanageConfigurationProfileID(t *testing.T) { for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Input) - actual, err := AutomanageConfigurationProfileID(v.Input) + actual, err := AutomanageConfigurationID(v.Input) if err != nil { if v.Error { continue diff --git a/internal/services/automanage/registration.go b/internal/services/automanage/registration.go index acccb86713b6..4cf2841c0351 100644 --- a/internal/services/automanage/registration.go +++ b/internal/services/automanage/registration.go @@ -46,6 +46,6 @@ func (r Registration) DataSources() []sdk.DataSource { // Resources returns a list of Resources supported by this Service func (r Registration) Resources() []sdk.Resource { return []sdk.Resource{ - AutoManageConfigurationProfileResource{}, + AutoManageConfigurationResource{}, } } diff --git a/internal/services/automanage/resourceid.go b/internal/services/automanage/resourceid.go index 016ba9f2009d..912bb4e3655a 100644 --- a/internal/services/automanage/resourceid.go +++ b/internal/services/automanage/resourceid.go @@ -1,4 +1,4 @@ package automanage // leaving the Automanage prefix here to avoid stuttering the property name for now -//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=AutomanageConfigurationProfile -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.Automanage/configurationProfiles/configurationProfile1 +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=AutomanageConfiguration -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.Automanage/configurationProfiles/configurationProfile1 diff --git a/internal/services/automanage/validate/automanage_configuration_profile_id.go b/internal/services/automanage/validate/automanage_configuration_id.go similarity index 68% rename from internal/services/automanage/validate/automanage_configuration_profile_id.go rename to internal/services/automanage/validate/automanage_configuration_id.go index bebe6e519a10..ef5c822a2085 100644 --- a/internal/services/automanage/validate/automanage_configuration_profile_id.go +++ b/internal/services/automanage/validate/automanage_configuration_id.go @@ -8,14 +8,14 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/services/automanage/parse" ) -func AutomanageConfigurationProfileID(input interface{}, key string) (warnings []string, errors []error) { +func AutomanageConfigurationID(input interface{}, key string) (warnings []string, errors []error) { v, ok := input.(string) if !ok { errors = append(errors, fmt.Errorf("expected %q to be a string", key)) return } - if _, err := parse.AutomanageConfigurationProfileID(v); err != nil { + if _, err := parse.AutomanageConfigurationID(v); err != nil { errors = append(errors, err) } diff --git a/internal/services/automanage/validate/automanage_configuration_profile_id_test.go b/internal/services/automanage/validate/automanage_configuration_id_test.go similarity index 93% rename from internal/services/automanage/validate/automanage_configuration_profile_id_test.go rename to internal/services/automanage/validate/automanage_configuration_id_test.go index 44cfb320d04f..6572ae152c8f 100644 --- a/internal/services/automanage/validate/automanage_configuration_profile_id_test.go +++ b/internal/services/automanage/validate/automanage_configuration_id_test.go @@ -4,7 +4,7 @@ package validate import "testing" -func TestAutomanageConfigurationProfileID(t *testing.T) { +func TestAutomanageConfigurationID(t *testing.T) { cases := []struct { Input string Valid bool @@ -66,7 +66,7 @@ func TestAutomanageConfigurationProfileID(t *testing.T) { } for _, tc := range cases { t.Logf("[DEBUG] Testing Value %s", tc.Input) - _, errors := AutomanageConfigurationProfileID(tc.Input, "test") + _, errors := AutomanageConfigurationID(tc.Input, "test") valid := len(errors) == 0 if tc.Valid != valid { diff --git a/website/docs/r/automanage_configuration_profiles.html.markdown b/website/docs/r/automanage_configuration.html.markdown similarity index 88% rename from website/docs/r/automanage_configuration_profiles.html.markdown rename to website/docs/r/automanage_configuration.html.markdown index 6f4bdfa78134..e3175b8ccb53 100644 --- a/website/docs/r/automanage_configuration_profiles.html.markdown +++ b/website/docs/r/automanage_configuration.html.markdown @@ -1,12 +1,12 @@ --- subcategory: "Automanage" layout: "azurerm" -page_title: "Azure Resource Manager: azurerm_automanage_configuration_profile" +page_title: "Azure Resource Manager: azurerm_automanage_configuration" description: |- Manages a automanage ConfigurationProfile. --- -# azurerm_automanage_configuration_profile +# azurerm_automanage_configuration Manages a automanage ConfigurationProfile. @@ -18,7 +18,7 @@ resource "azurerm_resource_group" "example" { location = "West Europe" } -resource "azurerm_automanage_configuration_profile" "example" { +resource "azurerm_automanage_configuration" "example" { name = "example-configurationprofile" resource_group_name = azurerm_resource_group.example.name location = azurerm_resource_group.example.location @@ -74,5 +74,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/d automanage ConfigurationProfiles can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_automanage_configuration_profile.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Automanage/configurationProfiles/configurationProfile1 +terraform import azurerm_automanage_configuration.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Automanage/configurationProfiles/configurationProfile1 ``` From 81ab0434757e13205684cbe4e93c62b7e4bab2b7 Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Thu, 1 Dec 2022 10:26:00 +0800 Subject: [PATCH 12/27] resolve conflict when merging main branch. --- .../2022-05-04/automanage/models.go | 204 ++---------------- 1 file changed, 12 insertions(+), 192 deletions(-) diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/models.go b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/models.go index 6e9c0c024907..4827b1e5ae4e 100644 --- a/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/models.go +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/models.go @@ -79,8 +79,8 @@ type BestPractice struct { Type *string `json:"type,omitempty"` // Name - READ-ONLY; The name of the best practice. For example, azureBestPracticesProduction Name *string `json:"name,omitempty"` - // ConfigurationProfileProperties - Properties of the best practice. - *ConfigurationProfileProperties `json:"properties,omitempty"` + // Properties - Properties of the best practice. + Properties *ConfigurationProfileProperties `json:"properties,omitempty"` // SystemData - READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information. SystemData *SystemData `json:"systemData,omitempty"` } @@ -88,72 +88,12 @@ type BestPractice struct { // MarshalJSON is the custom marshaler for BestPractice. func (bp BestPractice) MarshalJSON() ([]byte, error) { objectMap := make(map[string]interface{}) - if bp.ConfigurationProfileProperties != nil { - objectMap["properties"] = bp.ConfigurationProfileProperties + if bp.Properties != nil { + objectMap["properties"] = bp.Properties } return json.Marshal(objectMap) } -// UnmarshalJSON is the custom unmarshaler for BestPractice struct. -func (bp *BestPractice) 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 "id": - if v != nil { - var ID string - err = json.Unmarshal(*v, &ID) - if err != nil { - return err - } - bp.ID = &ID - } - case "type": - if v != nil { - var typeVar string - err = json.Unmarshal(*v, &typeVar) - if err != nil { - return err - } - bp.Type = &typeVar - } - case "name": - if v != nil { - var name string - err = json.Unmarshal(*v, &name) - if err != nil { - return err - } - bp.Name = &name - } - case "properties": - if v != nil { - var configurationProfileProperties ConfigurationProfileProperties - err = json.Unmarshal(*v, &configurationProfileProperties) - if err != nil { - return err - } - bp.ConfigurationProfileProperties = &configurationProfileProperties - } - case "systemData": - if v != nil { - var systemData SystemData - err = json.Unmarshal(*v, &systemData) - if err != nil { - return err - } - bp.SystemData = &systemData - } - } - } - - return nil -} - // BestPracticeList the response of the list best practice operation. type BestPracticeList struct { autorest.Response `json:"-"` @@ -399,8 +339,8 @@ func (pr ProxyResource) MarshalJSON() ([]byte, error) { // Report definition of the report. type Report struct { autorest.Response `json:"-"` - // AssignmentReportProperties - The properties for the report. - *AssignmentReportProperties `json:"properties,omitempty"` + // Properties - The properties for the report. + Properties *AssignmentReportProperties `json:"properties,omitempty"` // SystemData - READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information. SystemData *SystemData `json:"systemData,omitempty"` // ID - READ-ONLY; Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} @@ -414,72 +354,12 @@ type Report struct { // MarshalJSON is the custom marshaler for Report. func (r Report) MarshalJSON() ([]byte, error) { objectMap := make(map[string]interface{}) - if r.AssignmentReportProperties != nil { - objectMap["properties"] = r.AssignmentReportProperties + if r.Properties != nil { + objectMap["properties"] = r.Properties } return json.Marshal(objectMap) } -// UnmarshalJSON is the custom unmarshaler for Report struct. -func (r *Report) 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 assignmentReportProperties AssignmentReportProperties - err = json.Unmarshal(*v, &assignmentReportProperties) - if err != nil { - return err - } - r.AssignmentReportProperties = &assignmentReportProperties - } - case "systemData": - if v != nil { - var systemData SystemData - err = json.Unmarshal(*v, &systemData) - if err != nil { - return err - } - r.SystemData = &systemData - } - case "id": - if v != nil { - var ID string - err = json.Unmarshal(*v, &ID) - if err != nil { - return err - } - r.ID = &ID - } - case "name": - if v != nil { - var name string - err = json.Unmarshal(*v, &name) - if err != nil { - return err - } - r.Name = &name - } - case "type": - if v != nil { - var typeVar string - err = json.Unmarshal(*v, &typeVar) - if err != nil { - return err - } - r.Type = &typeVar - } - } - } - - return nil -} - // ReportList the response of the list report operation. type ReportList struct { autorest.Response `json:"-"` @@ -526,8 +406,8 @@ func (r Resource) MarshalJSON() ([]byte, error) { // ServicePrincipal the Service Principal Id for the subscription. type ServicePrincipal struct { autorest.Response `json:"-"` - // ServicePrincipalProperties - The Service Principal properties for the subscription - *ServicePrincipalProperties `json:"properties,omitempty"` + // Properties - The Service Principal properties for the subscription + Properties *ServicePrincipalProperties `json:"properties,omitempty"` // SystemData - READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information. SystemData *SystemData `json:"systemData,omitempty"` // ID - READ-ONLY; Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} @@ -541,72 +421,12 @@ type ServicePrincipal struct { // MarshalJSON is the custom marshaler for ServicePrincipal. func (sp ServicePrincipal) MarshalJSON() ([]byte, error) { objectMap := make(map[string]interface{}) - if sp.ServicePrincipalProperties != nil { - objectMap["properties"] = sp.ServicePrincipalProperties + if sp.Properties != nil { + objectMap["properties"] = sp.Properties } return json.Marshal(objectMap) } -// UnmarshalJSON is the custom unmarshaler for ServicePrincipal struct. -func (sp *ServicePrincipal) 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 servicePrincipalProperties ServicePrincipalProperties - err = json.Unmarshal(*v, &servicePrincipalProperties) - if err != nil { - return err - } - sp.ServicePrincipalProperties = &servicePrincipalProperties - } - case "systemData": - if v != nil { - var systemData SystemData - err = json.Unmarshal(*v, &systemData) - if err != nil { - return err - } - sp.SystemData = &systemData - } - case "id": - if v != nil { - var ID string - err = json.Unmarshal(*v, &ID) - if err != nil { - return err - } - sp.ID = &ID - } - case "name": - if v != nil { - var name string - err = json.Unmarshal(*v, &name) - if err != nil { - return err - } - sp.Name = &name - } - case "type": - if v != nil { - var typeVar string - err = json.Unmarshal(*v, &typeVar) - if err != nil { - return err - } - sp.Type = &typeVar - } - } - } - - return nil -} - // ServicePrincipalListResult the list of ServicePrincipals. type ServicePrincipalListResult struct { autorest.Response `json:"-"` From b561dc38f6c7e8c02bb2fc4a4aa2673668ad7095 Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Thu, 13 Apr 2023 11:28:48 +0800 Subject: [PATCH 13/27] update schema --- .../automanage_configuration_resource.go | 647 +++++++++++++++++- 1 file changed, 642 insertions(+), 5 deletions(-) diff --git a/internal/services/automanage/automanage_configuration_resource.go b/internal/services/automanage/automanage_configuration_resource.go index b791805d26d1..d284a2f9ac3c 100644 --- a/internal/services/automanage/automanage_configuration_resource.go +++ b/internal/services/automanage/automanage_configuration_resource.go @@ -4,6 +4,8 @@ import ( "context" "encoding/json" "fmt" + "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" + "regexp" "time" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" @@ -55,11 +57,623 @@ func (r AutoManageConfigurationResource) Arguments() map[string]*pluginsdk.Schem "location": commonschema.Location(), - "configuration_json": { - Type: pluginsdk.TypeString, - Required: true, - ValidateFunc: validation.StringIsJSON, - DiffSuppressFunc: pluginsdk.SuppressJsonDiff, + //"Alerts/AutomanageStatusChanges/Enable": boolean, + "status_change_alert_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + + //"Antimalware/Enable": boolean, + //"Antimalware/EnableRealTimeProtection": boolean, + //"Antimalware/RunScheduledScan": boolean, + //"Antimalware/ScanType": string ("Quick", "Full"), + //"Antimalware/ScanDay": int (0-8) Ex: 0 - daily, 1 - Sunday, 2 - Monday, .... 7 - Saturday, 8 - Disabled, + //"Antimalware/ScanTimeInMinutes": int (0 - 1440), + //"Antimalware/Exclusions/Extensions": string (extensions separated by semicolon. Ex: ".ext1;.ext2"), + //"Antimalware/Exclusions/Paths": string (Paths separated by semicolon. Ex: "c:\excluded-path-1;c:\excluded-path-2"), + //"Antimalware/Exclusions/Processes": string (Processes separated by semicolon. Ex: "proc1.exe;proc2.exe"), + "antimalware": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + "real_time_protection_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + "scheduled_scan_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + "scan_type": { + Type: pluginsdk.TypeString, + Optional: true, + Default: "Quick", + ValidateFunc: validation.StringInSlice([]string{ + "Quick", + "Full", + }, false), + }, + "scan_day": { + Type: pluginsdk.TypeInt, + Optional: true, + Default: 0, + ValidateFunc: validation.IntInSlice([]int{ + 0, 1, 2, 3, 4, 5, 6, 7, 8, + }), + }, + "scan_time_in_minutes": { + Type: pluginsdk.TypeInt, + Optional: true, + Default: 0, + ValidateFunc: validation.IntBetween(0, 1440), + }, + "exclusions": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "extensions": { + Type: pluginsdk.TypeString, + Optional: true, + }, + "paths": { + Type: pluginsdk.TypeString, + Optional: true, + }, + "processes": { + Type: pluginsdk.TypeString, + Optional: true, + }, + }, + }, + }, + }, + }, + }, + + //"AutomationAccount/Enable": boolean, + "automation_account_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + + //"AzureSecurityBaseline/Enable": boolean, + //"AzureSecurityBaseline/AssignmentType": string ("ApplyAndAutoCorrect", "ApplyAndMonitor", "Audit", "DeployAndAutoCorrect"), + "azure_security_baseline": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + "assignment_type": { + Type: pluginsdk.TypeString, + Optional: true, + Default: "ApplyAndAutoCorrect", + ValidateFunc: validation.StringInSlice([]string{ + "ApplyAndAutoCorrect", + "ApplyAndMonitor", + "Audit", + "DeployAndAutoCorrect", + }, false), + }, + }, + }, + }, + + //"Backup/Enable": boolean, + //"Backup/PolicyName": string (length 3 - 150, begin with alphanumeric char, only contain alphanumeric chars and hyphens), + //"Backup/TimeZone": timezone, + //"Backup/InstantRpRetentionRangeInDays": int (1 - 5 if ScheduleRunFrequency is Daily, 5 if ScheduleRunFrequency is Weekly), + //"Backup/SchedulePolicy/ScheduleRunFrequency": string ("Daily", "Weekly"), + //"Backup/SchedulePolicy/ScheduleRunTimes": list of DateTime, + //"Backup/SchedulePolicy/ScheduleRunDays": list of strings (["Sunday", "Monday", "Wednesday", "Thursday", "Friday", "Saturday"]), + //"Backup/SchedulePolicy/SchedulePolicyType": string ("SimpleSchedulePolicy"), + //"Backup/RetentionPolicy/RetentionPolicyType": string ("LongTermRetentionPolicy"), + //"Backup/RetentionPolicy/DailySchedule/RetentionTimes": list of DateTime, + //"Backup/RetentionPolicy/DailySchedule/RetentionDuration/Count": int (7 - 9999), + //"Backup/RetentionPolicy/DailySchedule/RetentionDuration/DurationType": string ("Days"), + //"Backup/RetentionPolicy/WeeklySchedule/RetentionTimes":, list of DateTime + //"Backup/RetentionPolicy/WeeklySchedule/RetentionDuration/Count":, int (1 - 5163) + //"Backup/RetentionPolicy/WeeklySchedule/RetentionDuration/DurationType": string ("Weeks"), + "backup": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + "policy_name": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringMatch(regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9-]{2,149}$`), "Policy name must be 3 - 150 characters long, begin with an alphanumeric character, and only contain alphanumeric characters and hyphens."), + }, + "time_zone": { + Type: pluginsdk.TypeString, + Optional: true, + Default: "UTC", + }, + "instant_rp_retention_range_in_days": { + Type: pluginsdk.TypeInt, + Optional: true, + Default: 5, + ValidateFunc: validation.IntBetween(1, 5), + }, + "schedule_policy": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "schedule_run_frequency": { + Type: pluginsdk.TypeString, + Optional: true, + Default: "Daily", + ValidateFunc: validation.StringInSlice([]string{ + "Daily", + "Weekly", + }, false), + }, + "schedule_run_times": { + Type: pluginsdk.TypeList, + Optional: true, + + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateFunc: validation.IsRFC3339Time, + }, + }, + "schedule_run_days": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateFunc: validation.StringInSlice([]string{ + "Sunday", + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", + }, false), + }, + }, + "schedule_policy_type": { + Type: pluginsdk.TypeString, + Optional: true, + Default: "SimpleSchedulePolicy", + ValidateFunc: validation.StringInSlice([]string{ + "SimpleSchedulePolicy", + }, false), + }, + }, + }, + }, + "retention_policy": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "retention_policy_type": { + Type: pluginsdk.TypeString, + Optional: true, + Default: "LongTermRetentionPolicy", + ValidateFunc: validation.StringInSlice([]string{ + "LongTermRetentionPolicy", + }, false), + }, + "daily_schedule": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "retention_times": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateFunc: validation.IsRFC3339Time, + }, + }, + "retention_duration": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "count": { + Type: pluginsdk.TypeInt, + Optional: true, + Default: 7, + ValidateFunc: validation.IntBetween(7, 9999), + }, + "duration_type": { + Type: pluginsdk.TypeString, + Optional: true, + Default: "Days", + ValidateFunc: validation.StringInSlice([]string{ + "Days", + }, false), + }, + }, + }, + }, + }, + }, + }, + "weekly_schedule": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "retention_times": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateFunc: validation.IsRFC3339Time, + }, + }, + "retention_duration": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "count": { + Type: pluginsdk.TypeInt, + Optional: true, + Default: 4, + ValidateFunc: validation.IntBetween(4, 9999), + }, + "duration_type": { + Type: pluginsdk.TypeString, + Optional: true, + Default: "Weeks", + ValidateFunc: validation.StringInSlice([]string{ + "Weeks", + }, false), + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + + //"BootDiagnostics/Enable": boolean, + "boot_diagnostics_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + + //"ChangeTrackingAndInventory/Enable": boolean, + "change_tracking_and_inventory_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + + // "DefenderForCloud/Enable": boolean, + "defender_for_cloud_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + //"GuestConfiguration/Enable": boolean, + "guest_configuration_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + + //"LogAnalytics/Enable": boolean, + //"LogAnalytics/Reprovision": boolean, + //"LogAnalytics/Workspace": resource ID (Log analytics workspace ID), + "log_analytics": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + "reprovision": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + "workspace_id": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: azure.ValidateResourceID, + }, + }, + }, + }, + + //"TrustedLaunchVM/Backup/Enable": boolean, + //"TrustedLaunchVM/Backup/PolicyName": string (length 3 - 150, begin with alphanumeric char, only contain alphanumeric chars and hyphens), + //"TrustedLaunchVM/Backup/TimeZone": timezone, + //"TrustedLaunchVM/Backup/InstantRpRetentionRangeInDays": int (1 - 30), + //"TrustedLaunchVM/Backup/SchedulePolicy/ScheduleRunFrequency": string ("Hourly", "Daily", "Weekly"), + //"TrustedLaunchVM/Backup/SchedulePolicy/SchedulePolicyType": string ("SimpleSchedulePolicyV2"), + //"TrustedLaunchVM/Backup/RetentionPolicy/RetentionPolicyType":, string ("LongTermRetentionPolicy") + //"TrustedLaunchVM/Backup/SchedulePolicy/HourlySchedule/Interval": int (4, 6, 8, 12), + //"TrustedLaunchVM/Backup/SchedulePolicy/HourlySchedule/ScheduleWindowStartTime": DateTime, + //"TrustedLaunchVM/Backup/SchedulePolicy/HourlySchedule/ScheduleWindowDuration": int (4, 8, 12, 16, 20, 24), + //"TrustedLaunchVM/Backup/RetentionPolicy/DailySchedule/RetentionTimes": list of DateTime, + //"TrustedLaunchVM/Backup/RetentionPolicy/DailySchedule/RetentionDuration/Count": int (7 - 9999), + //"TrustedLaunchVM/Backup/RetentionPolicy/DailySchedule/RetentionDuration/DurationType": string ("Hours", "Days"), + //"TrustedLaunchVM/Backup/SchedulePolicy/DailySchedule/ScheduleWindowStartTime": DateTime, + //"TrustedLaunchVM/Backup/SchedulePolicy/WeeklySchedule/ScheduleRunDays": list of strings (["Sunday", "Monday", "Wednesday", "Thursday", "Friday", "Saturday"]), + //"TrustedLaunchVM/Backup/RetentionPolicy/WeeklySchedule/RetentionDuration/Count": int (1 - 1563), + //"TrustedLaunchVM/Backup/RetentionPolicy/WeeklySchedule/RetentionDuration/DurationType": string ("Weeks"), + "trusted_launch_vm_backup": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + "policy_name": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringMatch(regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9-]{2,149}$`), "policy name must be 3 - 150 characters long, begin with an alphanumeric character, and only contain alphanumeric characters and hyphens"), + }, + "time_zone": { + Type: pluginsdk.TypeString, + Optional: true, + Default: "UTC", + }, + "instant_rp_retention_range_in_days": { + Type: pluginsdk.TypeInt, + Optional: true, + Default: 30, + ValidateFunc: validation.IntBetween(1, 30), + }, + "schedule_policy": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "schedule_run_frequency": { + Type: pluginsdk.TypeString, + Optional: true, + Default: "Daily", + ValidateFunc: validation.StringInSlice([]string{ + "Hourly", + "Daily", + "Weekly", + }, false), + }, + "schedule_policy_type": { + Type: pluginsdk.TypeString, + Optional: true, + Default: "SimpleSchedulePolicyV2", + ValidateFunc: validation.StringInSlice([]string{ + "SimpleSchedulePolicyV2", + }, false), + }, + "hourly_schedule": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "interval": { + Type: pluginsdk.TypeInt, + Optional: true, + Default: 4, + ValidateFunc: validation.IntInSlice([]int{4, 6, 8, 12}), + }, + "schedule_window_start_time": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.IsRFC3339Time, + }, + "schedule_window_duration": { + Type: pluginsdk.TypeInt, + Optional: true, + Default: 4, + ValidateFunc: validation.IntInSlice([]int{4, 8, 12, 16, 20, 24}), + }, + }, + }, + }, + "daily_schedule": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "schedule_window_start_time": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.IsRFC3339Time, + }, + }, + }, + }, + "weekly_schedule": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "schedule_run_days": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateFunc: validation.StringInSlice([]string{ + "Sunday", + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", + }, false), + }, + }, + }, + }, + }, + }, + }, + }, + "retention_policy": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "retention_policy_type": { + Type: pluginsdk.TypeString, + Optional: true, + Default: "LongTermRetentionPolicy", + ValidateFunc: validation.StringInSlice([]string{ + "LongTermRetentionPolicy", + }, false), + }, + "daily_schedule": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "retention_times": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateFunc: validation.IsRFC3339Time, + }, + }, + "retention_duration": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "count": { + Type: pluginsdk.TypeInt, + Optional: true, + Default: 7, + ValidateFunc: validation.IntBetween(7, 9999), + }, + "duration_type": { + Type: pluginsdk.TypeString, + Optional: true, + Default: "Days", + ValidateFunc: validation.StringInSlice([]string{ + "Days", + }, false), + }, + }, + }, + }, + }, + }, + }, + "weekly_schedule": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "retention_duration": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "count": { + Type: pluginsdk.TypeInt, + Optional: true, + Default: 4, + ValidateFunc: validation.IntBetween(4, 9999), + }, + "duration_type": { + Type: pluginsdk.TypeString, + Optional: true, + Default: "Weeks", + ValidateFunc: validation.StringInSlice([]string{ + "Weeks", + }, false), + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + + //"UpdateManagement/Enable": boolean, + "update_management_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + + //"VMInsights/Enable": boolean, + "vm_insights_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + + //"WindowsAdminCenter/Enable": boolean, + "windows_admin_center_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, }, "tags": commonschema.Tags(), @@ -224,3 +838,26 @@ func (r AutoManageConfigurationResource) Delete() sdk.ResourceFunc { }, } } + +func backupResourceSchema() *pluginsdk.Schema { + return &pluginsdk.Schema{ + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "backup_retention_days": { + Type: pluginsdk.TypeInt, + Optional: true, + ValidateFunc: validation.IntBetween(7, 9999), + }, + + "storage_account_id": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: azure.ValidateResourceID, + }, + }, + }, + } +} From d40948b380abfad69e610f819a8b03d8f74c6bd7 Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Tue, 18 Apr 2023 10:06:38 +0800 Subject: [PATCH 14/27] update model --- .../automanage_configuration_resource.go | 183 ++++++++++++++---- 1 file changed, 150 insertions(+), 33 deletions(-) diff --git a/internal/services/automanage/automanage_configuration_resource.go b/internal/services/automanage/automanage_configuration_resource.go index d284a2f9ac3c..ae06936188b0 100644 --- a/internal/services/automanage/automanage_configuration_resource.go +++ b/internal/services/automanage/automanage_configuration_resource.go @@ -2,14 +2,13 @@ package automanage import ( "context" - "encoding/json" "fmt" - "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "regexp" "time" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" + "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" "github.com/hashicorp/terraform-provider-azurerm/internal/services/automanage/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/automanage/validate" @@ -20,12 +19,127 @@ import ( "github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage" ) +type AzureSecurityBaselineConfiguration struct { + Enabled bool `tfschema:"enabled"` + AssignmentType string `tfschema:"assignment_type"` +} + +type SchedulePolicyConfiguration struct { + ScheduleRunFrequency string `tfschema:"schedule_run_frequency"` + ScheduleRunTimes []string `tfschema:"schedule_run_times"` + ScheduleRunDays []string `tfschema:"schedule_run_days"` +} + +type RetentionDurationConfiguration struct { + Count int `tfschema:"count"` + DurationType string `tfschema:"duration_type"` +} + +type DailyScheduleConfiguration struct { + RetentionTimes []string `tfschema:"retention_times"` + RetentionDuration *RetentionDurationConfiguration `tfschema:"retention_duration"` +} + +type WeeklyScheduleConfiguration struct { + RetentionTimes []string `tfschema:"retention_times"` + RetentionDuration *RetentionDurationConfiguration `tfschema:"retention_duration"` +} + +type RetentionPolicyConfiguration struct { + RetentionPolicyType string `tfschema:"retention_policy_type"` + DailySchedule *DailyScheduleConfiguration `tfschema:"daily_schedule"` + WeeklySchedule *WeeklyScheduleConfiguration `tfschema:"weekly_schedule"` +} + +type BackupConfiguration struct { + Enabled bool `tfschema:"enabled"` + PolicyName string `tfschema:"policy_name"` + TimeZone string `tfschema:"time_zone"` + InstantRpRetentionRangeInDays int `tfschema:"instant_rp_retention_range_in_days"` + SchedulePolicy *SchedulePolicyConfiguration `tfschema:"schedule_policy"` + RetentionPolicy *RetentionPolicyConfiguration `tfschema:"retention_policy"` +} + +type LogAnalyticsConfiguration struct { + Enabled bool `tfschema:"enabled"` + Reprovision bool `tfschema:"reprovision"` + WorkspaceId string `tfschema:"workspace_id"` +} + +type HourlyScheduleConfigurationV2 struct { + Interval int `tfschema:"interval"` + ScheduleWindowStartTime string `tfschema:"schedule_window_start_time"` + ScheduleWindowDuration int `tfschema:"schedule_window_duration"` +} + +type DailyScheduleConfigurationV2 struct { + ScheduleWindowStartTime string `tfschema:"schedule_window_start_time"` +} + +type WeeklyScheduleConfigurationV2 struct { + ScheduleRunDays []string `tfschema:"schedule_run_days"` +} + +type SchedulePolicyConfigurationV2 struct { + ScheduleRunFrequency string `tfschema:"schedule_run_frequency"` + ScheduleRunTimes []string `tfschema:"schedule_run_times"` + HourlySchedule *HourlyScheduleConfigurationV2 `tfschema:"hourly_schedule"` + DailySchedule *DailyScheduleConfigurationV2 `tfschema:"daily_schedule"` + WeeklySchedule *WeeklyScheduleConfigurationV2 `tfschema:"weekly_schedule"` +} + +type WeeklyScheduleConfigurationV3 struct { + RetentionDuration *RetentionDurationConfiguration `tfschema:"retention_duration"` +} + +type RetentionPolicyConfigurationV2 struct { + RetentionPolicyType string `tfschema:"retention_policy_type"` + DailySchedule *DailyScheduleConfiguration `tfschema:"daily_schedule"` + WeeklySchedule *WeeklyScheduleConfigurationV3 `tfschema:"weekly_schedule"` +} + +type TrustedLaunchVMBackUpConfiguration struct { + Enabled bool `tfschema:"enabled"` + PolicyName string `tfschema:"policy_name"` + TimeZone string `tfschema:"time_zone"` + InstantRpRetentionRangeInDays int `tfschema:"instant_rp_retention_range_in_days"` + SchedulePolicy *SchedulePolicyConfigurationV2 `tfschema:"schedule_policy"` + RetentionPolicy *RetentionPolicyConfigurationV2 `tfschema:"retention_policy"` +} + type AutoManageConfigurationModel struct { - Name string `tfschema:"name"` - ResourceGroupName string `tfschema:"resource_group_name"` - Configuration string `tfschema:"configuration_json"` - Location string `tfschema:"location"` - Tags map[string]string `tfschema:"tags"` + Name string `tfschema:"name"` + ResourceGroupName string `tfschema:"resource_group_name"` + StatusChangeAlertEnabled bool `tfschema:"status_change_alert_enabled"` + Antimalware *AntimalwareConfiguration `tfschema:"antimalware"` + AutomationAccountEnabled bool `tfschema:"automation_account_enabled"` + AzureSecurityBaseline *AzureSecurityBaselineConfiguration `tfschema:"azure_security_baseline"` + Backup *BackupConfiguration `tfschema:"backup"` + BootDiagnosticsEnabled bool `tfschema:"boot_diagnostics_enabled"` + ChangeTrackingEnabled bool `tfschema:"change_tracking_enabled"` + DefenderForCloudEnabled bool `tfschema:"defender_for_cloud_enabled"` + GuestConfigurationEnabled bool `tfschema:"guest_configuration_enabled"` + LogAnalytics *LogAnalyticsConfiguration `tfschema:"log_analytics"` + TrustedLaunchVMBackUp *TrustedLaunchVMBackUpConfiguration `tfschema:"trusted_launch_vm_backup"` + + Location string `tfschema:"location"` + Tags map[string]string `tfschema:"tags"` +} + +type ExclusionConfiguration struct { + Extensions []string `tfschema:"extensions"` + Paths []string `tfschema:"paths"` + Processes []string `tfschema:"processes"` +} + +type AntimalwareConfiguration struct { + Enabled bool `tfschema:"enabled"` + Exclusions *ExclusionConfiguration `tfschema:"exclusions"` + RealTimeProtectionEnabled bool `tfschema:"real_time_protection_enabled"` + ScheduledScanEnabled bool `tfschema:"scheduled_scan_enabled"` + ScanType string `tfschema:"scan_type"` + ScanDay int `tfschema:"scan_day"` + ScanTimeInMinutes int `tfschema:"scan_time_in_minutes"` } type AutoManageConfigurationResource struct{} @@ -711,13 +825,36 @@ func (r AutoManageConfigurationResource) Create() sdk.ResourceFunc { Tags: tags.FromTypedObject(model.Tags), } - if model.Configuration != "" { - var configurationValue interface{} - err = json.Unmarshal([]byte(model.Configuration), &configurationValue) - if err != nil { - return err + // Convert all to a map[string]interface{} and convert to a json property + jsonConfig := make(map[string]interface{}) + + if model.AutomationAccountEnabled { + jsonConfig["AutomationAccount"] = map[string]interface{}{ + "Enable": model.AutomationAccountEnabled, + } + } + + if model.Antimalware != nil { + jsonConfig["Antimalware"] = map[string]interface{}{ + "Enable": model.Antimalware.Enabled, + } + if exclusions := model.Antimalware.Exclusions; exclusions != nil { + + } + } + + if model.BootDiagnosticsEnabled { + jsonConfig["BootDiagnostics"] = map[string]interface{}{ + "Enable": model.BootDiagnosticsEnabled, + } + } + + if model.StatusChangeAlertEnabled { + jsonConfig["Alert"] = map[string]interface{}{ + "AutomanageStatusChanges": map[string]interface{}{ + "Enable": model.StatusChangeAlertEnabled, + }, } - properties.Properties.Configuration = &configurationValue } if _, err := client.CreateOrUpdate(ctx, id.ConfigurationProfileName, id.ResourceGroup, properties); err != nil { @@ -751,16 +888,6 @@ func (r AutoManageConfigurationResource) Update() sdk.ResourceFunc { return fmt.Errorf("retrieving %s: %+v", *id, err) } - if metadata.ResourceData.HasChange("configuration_json") { - var configurationValue interface{} - err := json.Unmarshal([]byte(model.Configuration), &configurationValue) - if err != nil { - return err - } - - resp.Properties.Configuration = &configurationValue - } - if metadata.ResourceData.HasChange("tags") { resp.Tags = tags.FromTypedObject(model.Tags) } @@ -800,16 +927,6 @@ func (r AutoManageConfigurationResource) Read() sdk.ResourceFunc { Location: location.NormalizeNilable(resp.Location), } - if properties := resp.Properties; properties != nil { - if properties.Configuration != nil { - configurationValue, err := json.Marshal(properties.Configuration) - if err != nil { - return err - } - - state.Configuration = string(configurationValue) - } - } if resp.Tags != nil { state.Tags = tags.ToTypedObject(resp.Tags) } From f6fc1a275571c2068144cefdbb2488019771e729 Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Tue, 18 Apr 2023 10:07:21 +0800 Subject: [PATCH 15/27] update model --- .../automanage_configuration_resource.go | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/internal/services/automanage/automanage_configuration_resource.go b/internal/services/automanage/automanage_configuration_resource.go index ae06936188b0..95dd853ae650 100644 --- a/internal/services/automanage/automanage_configuration_resource.go +++ b/internal/services/automanage/automanage_configuration_resource.go @@ -955,26 +955,3 @@ func (r AutoManageConfigurationResource) Delete() sdk.ResourceFunc { }, } } - -func backupResourceSchema() *pluginsdk.Schema { - return &pluginsdk.Schema{ - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "backup_retention_days": { - Type: pluginsdk.TypeInt, - Optional: true, - ValidateFunc: validation.IntBetween(7, 9999), - }, - - "storage_account_id": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: azure.ValidateResourceID, - }, - }, - }, - } -} From fd874ca6c89a8a1758fa692ec1a9d8d36ee9c6b9 Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Tue, 18 Apr 2023 16:52:24 +0800 Subject: [PATCH 16/27] update 1st part of supported properties. --- .../automanage_configuration_resource.go | 816 ++++-------------- .../automanage_configuration_resource_test.go | 66 +- 2 files changed, 215 insertions(+), 667 deletions(-) diff --git a/internal/services/automanage/automanage_configuration_resource.go b/internal/services/automanage/automanage_configuration_resource.go index 95dd853ae650..34e19173d2fd 100644 --- a/internal/services/automanage/automanage_configuration_resource.go +++ b/internal/services/automanage/automanage_configuration_resource.go @@ -2,13 +2,12 @@ package automanage import ( "context" + "encoding/json" "fmt" - "regexp" "time" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" - "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" "github.com/hashicorp/terraform-provider-azurerm/internal/services/automanage/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/automanage/validate" @@ -19,127 +18,36 @@ import ( "github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage" ) -type AzureSecurityBaselineConfiguration struct { - Enabled bool `tfschema:"enabled"` - AssignmentType string `tfschema:"assignment_type"` -} - -type SchedulePolicyConfiguration struct { - ScheduleRunFrequency string `tfschema:"schedule_run_frequency"` - ScheduleRunTimes []string `tfschema:"schedule_run_times"` - ScheduleRunDays []string `tfschema:"schedule_run_days"` -} - -type RetentionDurationConfiguration struct { - Count int `tfschema:"count"` - DurationType string `tfschema:"duration_type"` -} - -type DailyScheduleConfiguration struct { - RetentionTimes []string `tfschema:"retention_times"` - RetentionDuration *RetentionDurationConfiguration `tfschema:"retention_duration"` -} - -type WeeklyScheduleConfiguration struct { - RetentionTimes []string `tfschema:"retention_times"` - RetentionDuration *RetentionDurationConfiguration `tfschema:"retention_duration"` -} - -type RetentionPolicyConfiguration struct { - RetentionPolicyType string `tfschema:"retention_policy_type"` - DailySchedule *DailyScheduleConfiguration `tfschema:"daily_schedule"` - WeeklySchedule *WeeklyScheduleConfiguration `tfschema:"weekly_schedule"` -} - -type BackupConfiguration struct { - Enabled bool `tfschema:"enabled"` - PolicyName string `tfschema:"policy_name"` - TimeZone string `tfschema:"time_zone"` - InstantRpRetentionRangeInDays int `tfschema:"instant_rp_retention_range_in_days"` - SchedulePolicy *SchedulePolicyConfiguration `tfschema:"schedule_policy"` - RetentionPolicy *RetentionPolicyConfiguration `tfschema:"retention_policy"` -} - -type LogAnalyticsConfiguration struct { - Enabled bool `tfschema:"enabled"` - Reprovision bool `tfschema:"reprovision"` - WorkspaceId string `tfschema:"workspace_id"` -} - -type HourlyScheduleConfigurationV2 struct { - Interval int `tfschema:"interval"` - ScheduleWindowStartTime string `tfschema:"schedule_window_start_time"` - ScheduleWindowDuration int `tfschema:"schedule_window_duration"` -} +type ConfigurationModel struct { + Name string `tfschema:"name"` + ResourceGroupName string `tfschema:"resource_group_name"` -type DailyScheduleConfigurationV2 struct { - ScheduleWindowStartTime string `tfschema:"schedule_window_start_time"` -} - -type WeeklyScheduleConfigurationV2 struct { - ScheduleRunDays []string `tfschema:"schedule_run_days"` -} - -type SchedulePolicyConfigurationV2 struct { - ScheduleRunFrequency string `tfschema:"schedule_run_frequency"` - ScheduleRunTimes []string `tfschema:"schedule_run_times"` - HourlySchedule *HourlyScheduleConfigurationV2 `tfschema:"hourly_schedule"` - DailySchedule *DailyScheduleConfigurationV2 `tfschema:"daily_schedule"` - WeeklySchedule *WeeklyScheduleConfigurationV2 `tfschema:"weekly_schedule"` -} - -type WeeklyScheduleConfigurationV3 struct { - RetentionDuration *RetentionDurationConfiguration `tfschema:"retention_duration"` -} - -type RetentionPolicyConfigurationV2 struct { - RetentionPolicyType string `tfschema:"retention_policy_type"` - DailySchedule *DailyScheduleConfiguration `tfschema:"daily_schedule"` - WeeklySchedule *WeeklyScheduleConfigurationV3 `tfschema:"weekly_schedule"` -} - -type TrustedLaunchVMBackUpConfiguration struct { - Enabled bool `tfschema:"enabled"` - PolicyName string `tfschema:"policy_name"` - TimeZone string `tfschema:"time_zone"` - InstantRpRetentionRangeInDays int `tfschema:"instant_rp_retention_range_in_days"` - SchedulePolicy *SchedulePolicyConfigurationV2 `tfschema:"schedule_policy"` - RetentionPolicy *RetentionPolicyConfigurationV2 `tfschema:"retention_policy"` -} - -type AutoManageConfigurationModel struct { - Name string `tfschema:"name"` - ResourceGroupName string `tfschema:"resource_group_name"` - StatusChangeAlertEnabled bool `tfschema:"status_change_alert_enabled"` - Antimalware *AntimalwareConfiguration `tfschema:"antimalware"` - AutomationAccountEnabled bool `tfschema:"automation_account_enabled"` - AzureSecurityBaseline *AzureSecurityBaselineConfiguration `tfschema:"azure_security_baseline"` - Backup *BackupConfiguration `tfschema:"backup"` - BootDiagnosticsEnabled bool `tfschema:"boot_diagnostics_enabled"` - ChangeTrackingEnabled bool `tfschema:"change_tracking_enabled"` - DefenderForCloudEnabled bool `tfschema:"defender_for_cloud_enabled"` - GuestConfigurationEnabled bool `tfschema:"guest_configuration_enabled"` - LogAnalytics *LogAnalyticsConfiguration `tfschema:"log_analytics"` - TrustedLaunchVMBackUp *TrustedLaunchVMBackUpConfiguration `tfschema:"trusted_launch_vm_backup"` + Antimalware *AntimalwareConfiguration `tfschema:"antimalware"` + AutomationAccountEnabled bool `tfschema:"automation_account_enabled"` + BootDiagnosticsEnabled bool `tfschema:"boot_diagnostics_enabled"` + ChangeTrackingEnabled bool `tfschema:"change_tracking_enabled"` + DefenderForCloudEnabled bool `tfschema:"defender_for_cloud_enabled"` + GuestConfigurationEnabled bool `tfschema:"guest_configuration_enabled"` + StatusChangeAlertEnabled bool `tfschema:"status_change_alert_enabled"` Location string `tfschema:"location"` Tags map[string]string `tfschema:"tags"` } -type ExclusionConfiguration struct { - Extensions []string `tfschema:"extensions"` - Paths []string `tfschema:"paths"` - Processes []string `tfschema:"processes"` +type AntimalwareConfiguration struct { + Enabled bool `tfschema:"enabled"` + Exclusions *AntimalwareExclusions `tfschema:"exclusions"` + RealTimeProtectionEnabled bool `tfschema:"real_time_protection_enabled"` + ScheduledScanEnabled bool `tfschema:"scheduled_scan_enabled"` + ScanType string `tfschema:"scheduled_scan_type"` + ScanDay int `tfschema:"scheduled_scan_day"` + ScanTimeInMinutes int `tfschema:"scheduled_scan_time_in_minutes"` } -type AntimalwareConfiguration struct { - Enabled bool `tfschema:"enabled"` - Exclusions *ExclusionConfiguration `tfschema:"exclusions"` - RealTimeProtectionEnabled bool `tfschema:"real_time_protection_enabled"` - ScheduledScanEnabled bool `tfschema:"scheduled_scan_enabled"` - ScanType string `tfschema:"scan_type"` - ScanDay int `tfschema:"scan_day"` - ScanTimeInMinutes int `tfschema:"scan_time_in_minutes"` +type AntimalwareExclusions struct { + Extensions string `tfschema:"extensions"` + Paths string `tfschema:"paths"` + Processes string `tfschema:"processes"` } type AutoManageConfigurationResource struct{} @@ -151,7 +59,7 @@ func (r AutoManageConfigurationResource) ResourceType() string { } func (r AutoManageConfigurationResource) ModelObject() interface{} { - return &AutoManageConfigurationModel{} + return &ConfigurationModel{} } func (r AutoManageConfigurationResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { @@ -171,13 +79,6 @@ func (r AutoManageConfigurationResource) Arguments() map[string]*pluginsdk.Schem "location": commonschema.Location(), - //"Alerts/AutomanageStatusChanges/Enable": boolean, - "status_change_alert_enabled": { - Type: pluginsdk.TypeBool, - Optional: true, - Default: false, - }, - //"Antimalware/Enable": boolean, //"Antimalware/EnableRealTimeProtection": boolean, //"Antimalware/RunScheduledScan": boolean, @@ -208,7 +109,7 @@ func (r AutoManageConfigurationResource) Arguments() map[string]*pluginsdk.Schem Optional: true, Default: false, }, - "scan_type": { + "scheduled_scan_type": { Type: pluginsdk.TypeString, Optional: true, Default: "Quick", @@ -217,7 +118,7 @@ func (r AutoManageConfigurationResource) Arguments() map[string]*pluginsdk.Schem "Full", }, false), }, - "scan_day": { + "scheduled_scan_day": { Type: pluginsdk.TypeInt, Optional: true, Default: 0, @@ -225,7 +126,7 @@ func (r AutoManageConfigurationResource) Arguments() map[string]*pluginsdk.Schem 0, 1, 2, 3, 4, 5, 6, 7, 8, }), }, - "scan_time_in_minutes": { + "scheduled_scan_time_in_minutes": { Type: pluginsdk.TypeInt, Optional: true, Default: 0, @@ -263,228 +164,6 @@ func (r AutoManageConfigurationResource) Arguments() map[string]*pluginsdk.Schem Default: false, }, - //"AzureSecurityBaseline/Enable": boolean, - //"AzureSecurityBaseline/AssignmentType": string ("ApplyAndAutoCorrect", "ApplyAndMonitor", "Audit", "DeployAndAutoCorrect"), - "azure_security_baseline": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "enabled": { - Type: pluginsdk.TypeBool, - Optional: true, - Default: false, - }, - "assignment_type": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "ApplyAndAutoCorrect", - ValidateFunc: validation.StringInSlice([]string{ - "ApplyAndAutoCorrect", - "ApplyAndMonitor", - "Audit", - "DeployAndAutoCorrect", - }, false), - }, - }, - }, - }, - - //"Backup/Enable": boolean, - //"Backup/PolicyName": string (length 3 - 150, begin with alphanumeric char, only contain alphanumeric chars and hyphens), - //"Backup/TimeZone": timezone, - //"Backup/InstantRpRetentionRangeInDays": int (1 - 5 if ScheduleRunFrequency is Daily, 5 if ScheduleRunFrequency is Weekly), - //"Backup/SchedulePolicy/ScheduleRunFrequency": string ("Daily", "Weekly"), - //"Backup/SchedulePolicy/ScheduleRunTimes": list of DateTime, - //"Backup/SchedulePolicy/ScheduleRunDays": list of strings (["Sunday", "Monday", "Wednesday", "Thursday", "Friday", "Saturday"]), - //"Backup/SchedulePolicy/SchedulePolicyType": string ("SimpleSchedulePolicy"), - //"Backup/RetentionPolicy/RetentionPolicyType": string ("LongTermRetentionPolicy"), - //"Backup/RetentionPolicy/DailySchedule/RetentionTimes": list of DateTime, - //"Backup/RetentionPolicy/DailySchedule/RetentionDuration/Count": int (7 - 9999), - //"Backup/RetentionPolicy/DailySchedule/RetentionDuration/DurationType": string ("Days"), - //"Backup/RetentionPolicy/WeeklySchedule/RetentionTimes":, list of DateTime - //"Backup/RetentionPolicy/WeeklySchedule/RetentionDuration/Count":, int (1 - 5163) - //"Backup/RetentionPolicy/WeeklySchedule/RetentionDuration/DurationType": string ("Weeks"), - "backup": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "enabled": { - Type: pluginsdk.TypeBool, - Optional: true, - Default: false, - }, - "policy_name": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: validation.StringMatch(regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9-]{2,149}$`), "Policy name must be 3 - 150 characters long, begin with an alphanumeric character, and only contain alphanumeric characters and hyphens."), - }, - "time_zone": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "UTC", - }, - "instant_rp_retention_range_in_days": { - Type: pluginsdk.TypeInt, - Optional: true, - Default: 5, - ValidateFunc: validation.IntBetween(1, 5), - }, - "schedule_policy": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "schedule_run_frequency": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "Daily", - ValidateFunc: validation.StringInSlice([]string{ - "Daily", - "Weekly", - }, false), - }, - "schedule_run_times": { - Type: pluginsdk.TypeList, - Optional: true, - - Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - ValidateFunc: validation.IsRFC3339Time, - }, - }, - "schedule_run_days": { - Type: pluginsdk.TypeList, - Optional: true, - Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - ValidateFunc: validation.StringInSlice([]string{ - "Sunday", - "Monday", - "Tuesday", - "Wednesday", - "Thursday", - "Friday", - "Saturday", - }, false), - }, - }, - "schedule_policy_type": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "SimpleSchedulePolicy", - ValidateFunc: validation.StringInSlice([]string{ - "SimpleSchedulePolicy", - }, false), - }, - }, - }, - }, - "retention_policy": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "retention_policy_type": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "LongTermRetentionPolicy", - ValidateFunc: validation.StringInSlice([]string{ - "LongTermRetentionPolicy", - }, false), - }, - "daily_schedule": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "retention_times": { - Type: pluginsdk.TypeList, - Optional: true, - Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - ValidateFunc: validation.IsRFC3339Time, - }, - }, - "retention_duration": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "count": { - Type: pluginsdk.TypeInt, - Optional: true, - Default: 7, - ValidateFunc: validation.IntBetween(7, 9999), - }, - "duration_type": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "Days", - ValidateFunc: validation.StringInSlice([]string{ - "Days", - }, false), - }, - }, - }, - }, - }, - }, - }, - "weekly_schedule": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "retention_times": { - Type: pluginsdk.TypeList, - Optional: true, - Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - ValidateFunc: validation.IsRFC3339Time, - }, - }, - "retention_duration": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "count": { - Type: pluginsdk.TypeInt, - Optional: true, - Default: 4, - ValidateFunc: validation.IntBetween(4, 9999), - }, - "duration_type": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "Weeks", - ValidateFunc: validation.StringInSlice([]string{ - "Weeks", - }, false), - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - //"BootDiagnostics/Enable": boolean, "boot_diagnostics_enabled": { Type: pluginsdk.TypeBool, @@ -512,279 +191,8 @@ func (r AutoManageConfigurationResource) Arguments() map[string]*pluginsdk.Schem Default: false, }, - //"LogAnalytics/Enable": boolean, - //"LogAnalytics/Reprovision": boolean, - //"LogAnalytics/Workspace": resource ID (Log analytics workspace ID), - "log_analytics": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "enabled": { - Type: pluginsdk.TypeBool, - Optional: true, - Default: false, - }, - "reprovision": { - Type: pluginsdk.TypeBool, - Optional: true, - Default: false, - }, - "workspace_id": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: azure.ValidateResourceID, - }, - }, - }, - }, - - //"TrustedLaunchVM/Backup/Enable": boolean, - //"TrustedLaunchVM/Backup/PolicyName": string (length 3 - 150, begin with alphanumeric char, only contain alphanumeric chars and hyphens), - //"TrustedLaunchVM/Backup/TimeZone": timezone, - //"TrustedLaunchVM/Backup/InstantRpRetentionRangeInDays": int (1 - 30), - //"TrustedLaunchVM/Backup/SchedulePolicy/ScheduleRunFrequency": string ("Hourly", "Daily", "Weekly"), - //"TrustedLaunchVM/Backup/SchedulePolicy/SchedulePolicyType": string ("SimpleSchedulePolicyV2"), - //"TrustedLaunchVM/Backup/RetentionPolicy/RetentionPolicyType":, string ("LongTermRetentionPolicy") - //"TrustedLaunchVM/Backup/SchedulePolicy/HourlySchedule/Interval": int (4, 6, 8, 12), - //"TrustedLaunchVM/Backup/SchedulePolicy/HourlySchedule/ScheduleWindowStartTime": DateTime, - //"TrustedLaunchVM/Backup/SchedulePolicy/HourlySchedule/ScheduleWindowDuration": int (4, 8, 12, 16, 20, 24), - //"TrustedLaunchVM/Backup/RetentionPolicy/DailySchedule/RetentionTimes": list of DateTime, - //"TrustedLaunchVM/Backup/RetentionPolicy/DailySchedule/RetentionDuration/Count": int (7 - 9999), - //"TrustedLaunchVM/Backup/RetentionPolicy/DailySchedule/RetentionDuration/DurationType": string ("Hours", "Days"), - //"TrustedLaunchVM/Backup/SchedulePolicy/DailySchedule/ScheduleWindowStartTime": DateTime, - //"TrustedLaunchVM/Backup/SchedulePolicy/WeeklySchedule/ScheduleRunDays": list of strings (["Sunday", "Monday", "Wednesday", "Thursday", "Friday", "Saturday"]), - //"TrustedLaunchVM/Backup/RetentionPolicy/WeeklySchedule/RetentionDuration/Count": int (1 - 1563), - //"TrustedLaunchVM/Backup/RetentionPolicy/WeeklySchedule/RetentionDuration/DurationType": string ("Weeks"), - "trusted_launch_vm_backup": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "enabled": { - Type: pluginsdk.TypeBool, - Optional: true, - Default: false, - }, - "policy_name": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: validation.StringMatch(regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9-]{2,149}$`), "policy name must be 3 - 150 characters long, begin with an alphanumeric character, and only contain alphanumeric characters and hyphens"), - }, - "time_zone": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "UTC", - }, - "instant_rp_retention_range_in_days": { - Type: pluginsdk.TypeInt, - Optional: true, - Default: 30, - ValidateFunc: validation.IntBetween(1, 30), - }, - "schedule_policy": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "schedule_run_frequency": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "Daily", - ValidateFunc: validation.StringInSlice([]string{ - "Hourly", - "Daily", - "Weekly", - }, false), - }, - "schedule_policy_type": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "SimpleSchedulePolicyV2", - ValidateFunc: validation.StringInSlice([]string{ - "SimpleSchedulePolicyV2", - }, false), - }, - "hourly_schedule": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "interval": { - Type: pluginsdk.TypeInt, - Optional: true, - Default: 4, - ValidateFunc: validation.IntInSlice([]int{4, 6, 8, 12}), - }, - "schedule_window_start_time": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: validation.IsRFC3339Time, - }, - "schedule_window_duration": { - Type: pluginsdk.TypeInt, - Optional: true, - Default: 4, - ValidateFunc: validation.IntInSlice([]int{4, 8, 12, 16, 20, 24}), - }, - }, - }, - }, - "daily_schedule": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "schedule_window_start_time": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: validation.IsRFC3339Time, - }, - }, - }, - }, - "weekly_schedule": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "schedule_run_days": { - Type: pluginsdk.TypeList, - Optional: true, - Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - ValidateFunc: validation.StringInSlice([]string{ - "Sunday", - "Monday", - "Tuesday", - "Wednesday", - "Thursday", - "Friday", - "Saturday", - }, false), - }, - }, - }, - }, - }, - }, - }, - }, - "retention_policy": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "retention_policy_type": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "LongTermRetentionPolicy", - ValidateFunc: validation.StringInSlice([]string{ - "LongTermRetentionPolicy", - }, false), - }, - "daily_schedule": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "retention_times": { - Type: pluginsdk.TypeList, - Optional: true, - Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - ValidateFunc: validation.IsRFC3339Time, - }, - }, - "retention_duration": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "count": { - Type: pluginsdk.TypeInt, - Optional: true, - Default: 7, - ValidateFunc: validation.IntBetween(7, 9999), - }, - "duration_type": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "Days", - ValidateFunc: validation.StringInSlice([]string{ - "Days", - }, false), - }, - }, - }, - }, - }, - }, - }, - "weekly_schedule": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "retention_duration": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "count": { - Type: pluginsdk.TypeInt, - Optional: true, - Default: 4, - ValidateFunc: validation.IntBetween(4, 9999), - }, - "duration_type": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "Weeks", - ValidateFunc: validation.StringInSlice([]string{ - "Weeks", - }, false), - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - - //"UpdateManagement/Enable": boolean, - "update_management_enabled": { - Type: pluginsdk.TypeBool, - Optional: true, - Default: false, - }, - - //"VMInsights/Enable": boolean, - "vm_insights_enabled": { - Type: pluginsdk.TypeBool, - Optional: true, - Default: false, - }, - - //"WindowsAdminCenter/Enable": boolean, - "windows_admin_center_enabled": { + //"Alerts/AutomanageStatusChanges/Enable": boolean, + "status_change_alert_enabled": { Type: pluginsdk.TypeBool, Optional: true, Default: false, @@ -802,7 +210,7 @@ func (r AutoManageConfigurationResource) Create() sdk.ResourceFunc { return sdk.ResourceFunc{ Timeout: 30 * time.Minute, Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { - var model AutoManageConfigurationModel + var model ConfigurationModel if err := metadata.Decode(&model); err != nil { return fmt.Errorf("decoding: %+v", err) } @@ -828,35 +236,46 @@ func (r AutoManageConfigurationResource) Create() sdk.ResourceFunc { // Convert all to a map[string]interface{} and convert to a json property jsonConfig := make(map[string]interface{}) - if model.AutomationAccountEnabled { - jsonConfig["AutomationAccount"] = map[string]interface{}{ - "Enable": model.AutomationAccountEnabled, - } - } - if model.Antimalware != nil { - jsonConfig["Antimalware"] = map[string]interface{}{ - "Enable": model.Antimalware.Enabled, + jsonConfig["Antimalware/Enable"] = model.Antimalware.Enabled + jsonConfig["Antimalware/RealTimeProtectionEnabled"] = model.Antimalware.RealTimeProtectionEnabled + jsonConfig["Antimalware/RunScheduledScan"] = model.Antimalware.ScheduledScanEnabled + jsonConfig["Antimalware/ScanType"] = model.Antimalware.ScanType + jsonConfig["Antimalware/ScanDay"] = model.Antimalware.ScanDay + jsonConfig["Antimalware/ScanTimeInMinutes"] = model.Antimalware.ScanTimeInMinutes + if model.Antimalware.Exclusions != nil { + jsonConfig["Antimalware/Exclusions/Extensions"] = model.Antimalware.Exclusions.Extensions + jsonConfig["Antimalware/Exclusions/Paths"] = model.Antimalware.Exclusions.Paths + jsonConfig["Antimalware/Exclusions/Processes"] = model.Antimalware.Exclusions.Processes } - if exclusions := model.Antimalware.Exclusions; exclusions != nil { + } - } + if model.AutomationAccountEnabled { + jsonConfig["AutomationAccount/Enable"] = model.AutomationAccountEnabled } if model.BootDiagnosticsEnabled { - jsonConfig["BootDiagnostics"] = map[string]interface{}{ - "Enable": model.BootDiagnosticsEnabled, - } + jsonConfig["BootDiagnostics/Enable"] = model.BootDiagnosticsEnabled + } + + if model.ChangeTrackingEnabled { + jsonConfig["ChangeTracking/Enable"] = model.ChangeTrackingEnabled + } + + if model.DefenderForCloudEnabled { + jsonConfig["DefenderForCloud/Enable"] = model.DefenderForCloudEnabled + } + + if model.GuestConfigurationEnabled { + jsonConfig["GuestConfiguration/Enable"] = model.GuestConfigurationEnabled } if model.StatusChangeAlertEnabled { - jsonConfig["Alert"] = map[string]interface{}{ - "AutomanageStatusChanges": map[string]interface{}{ - "Enable": model.StatusChangeAlertEnabled, - }, - } + jsonConfig["Alerts/AutomanageStatusChanges/Enable"] = model.StatusChangeAlertEnabled } + properties.Properties.Configuration = &jsonConfig + if _, err := client.CreateOrUpdate(ctx, id.ConfigurationProfileName, id.ResourceGroup, properties); err != nil { return fmt.Errorf("creating %s: %+v", id, err) } @@ -878,7 +297,7 @@ func (r AutoManageConfigurationResource) Update() sdk.ResourceFunc { return err } - var model AutoManageConfigurationModel + var model ConfigurationModel if err := metadata.Decode(&model); err != nil { return fmt.Errorf("decoding: %+v", err) } @@ -888,11 +307,71 @@ func (r AutoManageConfigurationResource) Update() sdk.ResourceFunc { return fmt.Errorf("retrieving %s: %+v", *id, err) } + jsonConfig := make(map[string]interface{}) + + if resp.Properties != nil && resp.Properties.Configuration != nil { + err := json.Unmarshal([]byte(resp.Properties.Configuration.(string)), &jsonConfig) + if err != nil { + return fmt.Errorf("unmarshalling %s: %+v", *id, err) + } + } + + if model.Antimalware != nil { + jsonConfig["Antimalware/Enable"] = model.Antimalware.Enabled + jsonConfig["Antimalware/RealTimeProtectionEnabled"] = model.Antimalware.RealTimeProtectionEnabled + jsonConfig["Antimalware/RunScheduledScan"] = model.Antimalware.ScheduledScanEnabled + jsonConfig["Antimalware/ScanType"] = model.Antimalware.ScanType + jsonConfig["Antimalware/ScanDay"] = model.Antimalware.ScanDay + jsonConfig["Antimalware/ScanTimeInMinutes"] = model.Antimalware.ScanTimeInMinutes + if model.Antimalware.Exclusions != nil { + jsonConfig["Antimalware/Exclusions/Extensions"] = model.Antimalware.Exclusions.Extensions + jsonConfig["Antimalware/Exclusions/Paths"] = model.Antimalware.Exclusions.Paths + jsonConfig["Antimalware/Exclusions/Processes"] = model.Antimalware.Exclusions.Processes + } + } + + if metadata.ResourceData.HasChange("automation_account_enabled") { + jsonConfig["AutomationAccount/Enable"] = model.AutomationAccountEnabled + } + + if metadata.ResourceData.HasChange("boot_diagnostics_enabled") { + jsonConfig["BootDiagnostics/Enable"] = model.BootDiagnosticsEnabled + } + + if metadata.ResourceData.HasChange("change_tracking_enabled") { + jsonConfig["ChangeTracking/Enable"] = model.ChangeTrackingEnabled + } + + if metadata.ResourceData.HasChange("defender_for_cloud_enabled") { + jsonConfig["DefenderForCloud/Enable"] = model.DefenderForCloudEnabled + } + + if metadata.ResourceData.HasChange("guest_configuration_enabled") { + jsonConfig["GuestConfiguration/Enable"] = model.GuestConfigurationEnabled + } + + if metadata.ResourceData.HasChange("status_change_alert_enabled") { + jsonConfig["Alerts/AutomanageStatusChanges/Enable"] = model.StatusChangeAlertEnabled + } + if metadata.ResourceData.HasChange("tags") { resp.Tags = tags.FromTypedObject(model.Tags) } - if _, err := client.CreateOrUpdate(ctx, id.ConfigurationProfileName, id.ResourceGroup, resp); err != nil { + configBytes, err := json.Marshal(jsonConfig) + if err != nil { + return fmt.Errorf("marshalling %s: %+v", *id, err) + } + + properties := automanage.ConfigurationProfile{ + Location: utils.String(metadata.ResourceData.Get("location").(string)), + Properties: &automanage.ConfigurationProfileProperties{ + Configuration: configBytes, + }, + Tags: resp.Tags, + } + + if _, err := client.CreateOrUpdate(ctx, id.ConfigurationProfileName, id.ResourceGroup, properties); err != nil { return fmt.Errorf("updating %s: %+v", *id, err) } @@ -921,12 +400,63 @@ func (r AutoManageConfigurationResource) Read() sdk.ResourceFunc { return fmt.Errorf("retrieving %s: %+v", *id, err) } - state := AutoManageConfigurationModel{ + state := ConfigurationModel{ Name: id.ConfigurationProfileName, ResourceGroupName: id.ResourceGroup, Location: location.NormalizeNilable(resp.Location), } + if resp.Properties != nil && resp.Properties.Configuration != nil { + configMap := make(map[string]interface{}) + err := json.Unmarshal(resp.Properties.Configuration.([]byte), &configMap) + if err != nil { + return fmt.Errorf("unmarshalling %s: %+v", *id, err) + } + + if configMap["Antimalware/Enable"] != nil { + state.Antimalware = &AntimalwareConfiguration{ + Enabled: configMap["Antimalware/Enable"].(bool), + RealTimeProtectionEnabled: configMap["Antimalware/RealTimeProtectionEnabled"].(bool), + ScheduledScanEnabled: configMap["Antimalware/RunScheduledScan"].(bool), + ScanType: configMap["Antimalware/ScanType"].(string), + ScanDay: configMap["Antimalware/ScanDay"].(int), + ScanTimeInMinutes: configMap["Antimalware/ScanTimeInMinutes"].(int), + } + + if configMap["Antimalware/Exclusions/Extensions"] != nil { + state.Antimalware.Exclusions = &AntimalwareExclusions{ + Extensions: configMap["Antimalware/Exclusions/Extensions"].(string), + Paths: configMap["Antimalware/Exclusions/Paths"].(string), + Processes: configMap["Antimalware/Exclusions/Processes"].(string), + } + } + } + + if configMap["AutomationAccount/Enable"] != nil { + state.AutomationAccountEnabled = configMap["AutomationAccount/Enable"].(bool) + } + + if configMap["BootDiagnostics/Enable"] != nil { + state.BootDiagnosticsEnabled = configMap["BootDiagnostics/Enable"].(bool) + } + + if configMap["ChangeTracking/Enable"] != nil { + state.ChangeTrackingEnabled = configMap["ChangeTracking/Enable"].(bool) + } + + if configMap["DefenderForCloud/Enable"] != nil { + state.DefenderForCloudEnabled = configMap["DefenderForServers/Enable"].(bool) + } + + if configMap["GuestConfiguration/Enable"] != nil { + state.GuestConfigurationEnabled = configMap["GuestConfiguration/Enable"].(bool) + } + + if configMap["Alerts/AutomanageStatusChanges/Enable"] != nil { + state.StatusChangeAlertEnabled = configMap["Alerts/AutomanageStatusChanges/Enable"].(bool) + } + } + if resp.Tags != nil { state.Tags = tags.ToTypedObject(resp.Tags) } diff --git a/internal/services/automanage/automanage_configuration_resource_test.go b/internal/services/automanage/automanage_configuration_resource_test.go index 6b3a2553ce34..f5232caf8131 100644 --- a/internal/services/automanage/automanage_configuration_resource_test.go +++ b/internal/services/automanage/automanage_configuration_resource_test.go @@ -118,17 +118,28 @@ resource "azurerm_automanage_configuration" "test" { name = "acctest-amcp-%d" resource_group_name = azurerm_resource_group.test.name location = "%s" - configuration_json = jsonencode({ - "Antimalware/Enable" : false, - "AzureSecurityCenter/Enable" : true, - "Backup/Enable" : false, - "BootDiagnostics/Enable" : true, - "ChangeTrackingAndInventory/Enable" : true, - "GuestConfiguration/Enable" : true, - "LogAnalytics/Enable" : true, - "UpdateManagement/Enable" : true, - "VMInsights/Enable" : true - }) + antimalware { + enabled = true + exclusions { + extensions = "exe;dll" + paths = "C:\\Windows\\Temp;D:\\Temp" + processes = "svchost.exe;notepad.exe" + } + real_time_protection = true + scheduled_scan_enabled = true + scheduled_scan_type = "Quick" + scheduled_scan_day = 1 + scheduled_scan_time_in_minutes = 1339 + } + automation_account_enabled = true + boot_diagnostics_enabled = true + change_tracking_and_inventory_enabled = true + defender_for_cloud_enabled = true + guest_configuration_enabled = true + status_change_alert_enabled = true + tags = { + "env" = "test" + } } `, template, data.RandomInteger, data.Locations.Primary) } @@ -166,21 +177,28 @@ resource "azurerm_automanage_configuration" "test" { name = "acctest-amcp-%d" resource_group_name = azurerm_resource_group.test.name location = "%s" - configuration_json = jsonencode({ - "Antimalware/Enable" : false, - "AzureSecurityCenter/Enable" : true, - "Backup/Enable" : false, - "BootDiagnostics/Enable" : true, - "ChangeTrackingAndInventory/Enable" : true, - "GuestConfiguration/Enable" : true, - "LogAnalytics/Enable" : true, - "UpdateManagement/Enable" : true, - "VMInsights/Enable" : true - }) + antimalware { + enabled = true + exclusions { + extensions = "exe;dll" + paths = "C:\\Windows\\Temp;D:\\Temp" + processes = "svchost.exe;notepad.exe" + } + real_time_protection_enabled = true + scheduled_scan_enabled = true + scheduled_scan_type = "Quick" + scheduled_scan_day = 1 + scheduled_scan_time_in_minutes = 1339 + } + automation_account_enabled = true + boot_diagnostics_enabled = true + change_tracking_and_inventory_enabled = true + defender_for_cloud_enabled = true + guest_configuration_enabled = true + status_change_alert_enabled = true tags = { - key = "value" + "env" = "test" } - } `, template, data.RandomInteger, data.Locations.Primary) } From cd9fdcfc79c20dd12ad2c1eb3355a101d3201985 Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Tue, 18 Apr 2023 16:52:24 +0800 Subject: [PATCH 17/27] update 1st part of supported properties. --- .../automanage_configuration_resource.go | 816 ++++-------------- .../automanage_configuration_resource_test.go | 66 +- 2 files changed, 217 insertions(+), 665 deletions(-) diff --git a/internal/services/automanage/automanage_configuration_resource.go b/internal/services/automanage/automanage_configuration_resource.go index 95dd853ae650..309ca9f7b6ec 100644 --- a/internal/services/automanage/automanage_configuration_resource.go +++ b/internal/services/automanage/automanage_configuration_resource.go @@ -2,13 +2,12 @@ package automanage import ( "context" + "encoding/json" "fmt" - "regexp" "time" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" - "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" "github.com/hashicorp/terraform-provider-azurerm/internal/services/automanage/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/automanage/validate" @@ -19,127 +18,36 @@ import ( "github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage" ) -type AzureSecurityBaselineConfiguration struct { - Enabled bool `tfschema:"enabled"` - AssignmentType string `tfschema:"assignment_type"` -} - -type SchedulePolicyConfiguration struct { - ScheduleRunFrequency string `tfschema:"schedule_run_frequency"` - ScheduleRunTimes []string `tfschema:"schedule_run_times"` - ScheduleRunDays []string `tfschema:"schedule_run_days"` -} - -type RetentionDurationConfiguration struct { - Count int `tfschema:"count"` - DurationType string `tfschema:"duration_type"` -} - -type DailyScheduleConfiguration struct { - RetentionTimes []string `tfschema:"retention_times"` - RetentionDuration *RetentionDurationConfiguration `tfschema:"retention_duration"` -} - -type WeeklyScheduleConfiguration struct { - RetentionTimes []string `tfschema:"retention_times"` - RetentionDuration *RetentionDurationConfiguration `tfschema:"retention_duration"` -} - -type RetentionPolicyConfiguration struct { - RetentionPolicyType string `tfschema:"retention_policy_type"` - DailySchedule *DailyScheduleConfiguration `tfschema:"daily_schedule"` - WeeklySchedule *WeeklyScheduleConfiguration `tfschema:"weekly_schedule"` -} - -type BackupConfiguration struct { - Enabled bool `tfschema:"enabled"` - PolicyName string `tfschema:"policy_name"` - TimeZone string `tfschema:"time_zone"` - InstantRpRetentionRangeInDays int `tfschema:"instant_rp_retention_range_in_days"` - SchedulePolicy *SchedulePolicyConfiguration `tfschema:"schedule_policy"` - RetentionPolicy *RetentionPolicyConfiguration `tfschema:"retention_policy"` -} - -type LogAnalyticsConfiguration struct { - Enabled bool `tfschema:"enabled"` - Reprovision bool `tfschema:"reprovision"` - WorkspaceId string `tfschema:"workspace_id"` -} - -type HourlyScheduleConfigurationV2 struct { - Interval int `tfschema:"interval"` - ScheduleWindowStartTime string `tfschema:"schedule_window_start_time"` - ScheduleWindowDuration int `tfschema:"schedule_window_duration"` -} +type ConfigurationModel struct { + Name string `tfschema:"name"` + ResourceGroupName string `tfschema:"resource_group_name"` -type DailyScheduleConfigurationV2 struct { - ScheduleWindowStartTime string `tfschema:"schedule_window_start_time"` -} - -type WeeklyScheduleConfigurationV2 struct { - ScheduleRunDays []string `tfschema:"schedule_run_days"` -} - -type SchedulePolicyConfigurationV2 struct { - ScheduleRunFrequency string `tfschema:"schedule_run_frequency"` - ScheduleRunTimes []string `tfschema:"schedule_run_times"` - HourlySchedule *HourlyScheduleConfigurationV2 `tfschema:"hourly_schedule"` - DailySchedule *DailyScheduleConfigurationV2 `tfschema:"daily_schedule"` - WeeklySchedule *WeeklyScheduleConfigurationV2 `tfschema:"weekly_schedule"` -} - -type WeeklyScheduleConfigurationV3 struct { - RetentionDuration *RetentionDurationConfiguration `tfschema:"retention_duration"` -} - -type RetentionPolicyConfigurationV2 struct { - RetentionPolicyType string `tfschema:"retention_policy_type"` - DailySchedule *DailyScheduleConfiguration `tfschema:"daily_schedule"` - WeeklySchedule *WeeklyScheduleConfigurationV3 `tfschema:"weekly_schedule"` -} - -type TrustedLaunchVMBackUpConfiguration struct { - Enabled bool `tfschema:"enabled"` - PolicyName string `tfschema:"policy_name"` - TimeZone string `tfschema:"time_zone"` - InstantRpRetentionRangeInDays int `tfschema:"instant_rp_retention_range_in_days"` - SchedulePolicy *SchedulePolicyConfigurationV2 `tfschema:"schedule_policy"` - RetentionPolicy *RetentionPolicyConfigurationV2 `tfschema:"retention_policy"` -} - -type AutoManageConfigurationModel struct { - Name string `tfschema:"name"` - ResourceGroupName string `tfschema:"resource_group_name"` - StatusChangeAlertEnabled bool `tfschema:"status_change_alert_enabled"` - Antimalware *AntimalwareConfiguration `tfschema:"antimalware"` - AutomationAccountEnabled bool `tfschema:"automation_account_enabled"` - AzureSecurityBaseline *AzureSecurityBaselineConfiguration `tfschema:"azure_security_baseline"` - Backup *BackupConfiguration `tfschema:"backup"` - BootDiagnosticsEnabled bool `tfschema:"boot_diagnostics_enabled"` - ChangeTrackingEnabled bool `tfschema:"change_tracking_enabled"` - DefenderForCloudEnabled bool `tfschema:"defender_for_cloud_enabled"` - GuestConfigurationEnabled bool `tfschema:"guest_configuration_enabled"` - LogAnalytics *LogAnalyticsConfiguration `tfschema:"log_analytics"` - TrustedLaunchVMBackUp *TrustedLaunchVMBackUpConfiguration `tfschema:"trusted_launch_vm_backup"` + Antimalware []AntimalwareConfiguration `tfschema:"antimalware"` + AutomationAccountEnabled bool `tfschema:"automation_account_enabled"` + BootDiagnosticsEnabled bool `tfschema:"boot_diagnostics_enabled"` + ChangeTrackingEnabled bool `tfschema:"change_tracking_enabled"` + DefenderForCloudEnabled bool `tfschema:"defender_for_cloud_enabled"` + GuestConfigurationEnabled bool `tfschema:"guest_configuration_enabled"` + StatusChangeAlertEnabled bool `tfschema:"status_change_alert_enabled"` Location string `tfschema:"location"` Tags map[string]string `tfschema:"tags"` } -type ExclusionConfiguration struct { - Extensions []string `tfschema:"extensions"` - Paths []string `tfschema:"paths"` - Processes []string `tfschema:"processes"` -} - type AntimalwareConfiguration struct { Enabled bool `tfschema:"enabled"` - Exclusions *ExclusionConfiguration `tfschema:"exclusions"` + Exclusions []AntimalwareExclusions `tfschema:"exclusions"` RealTimeProtectionEnabled bool `tfschema:"real_time_protection_enabled"` ScheduledScanEnabled bool `tfschema:"scheduled_scan_enabled"` - ScanType string `tfschema:"scan_type"` - ScanDay int `tfschema:"scan_day"` - ScanTimeInMinutes int `tfschema:"scan_time_in_minutes"` + ScanType string `tfschema:"scheduled_scan_type"` + ScanDay int `tfschema:"scheduled_scan_day"` + ScanTimeInMinutes int `tfschema:"scheduled_scan_time_in_minutes"` +} + +type AntimalwareExclusions struct { + Extensions string `tfschema:"extensions"` + Paths string `tfschema:"paths"` + Processes string `tfschema:"processes"` } type AutoManageConfigurationResource struct{} @@ -151,7 +59,7 @@ func (r AutoManageConfigurationResource) ResourceType() string { } func (r AutoManageConfigurationResource) ModelObject() interface{} { - return &AutoManageConfigurationModel{} + return &ConfigurationModel{} } func (r AutoManageConfigurationResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { @@ -171,13 +79,6 @@ func (r AutoManageConfigurationResource) Arguments() map[string]*pluginsdk.Schem "location": commonschema.Location(), - //"Alerts/AutomanageStatusChanges/Enable": boolean, - "status_change_alert_enabled": { - Type: pluginsdk.TypeBool, - Optional: true, - Default: false, - }, - //"Antimalware/Enable": boolean, //"Antimalware/EnableRealTimeProtection": boolean, //"Antimalware/RunScheduledScan": boolean, @@ -208,7 +109,7 @@ func (r AutoManageConfigurationResource) Arguments() map[string]*pluginsdk.Schem Optional: true, Default: false, }, - "scan_type": { + "scheduled_scan_type": { Type: pluginsdk.TypeString, Optional: true, Default: "Quick", @@ -217,7 +118,7 @@ func (r AutoManageConfigurationResource) Arguments() map[string]*pluginsdk.Schem "Full", }, false), }, - "scan_day": { + "scheduled_scan_day": { Type: pluginsdk.TypeInt, Optional: true, Default: 0, @@ -225,7 +126,7 @@ func (r AutoManageConfigurationResource) Arguments() map[string]*pluginsdk.Schem 0, 1, 2, 3, 4, 5, 6, 7, 8, }), }, - "scan_time_in_minutes": { + "scheduled_scan_time_in_minutes": { Type: pluginsdk.TypeInt, Optional: true, Default: 0, @@ -263,228 +164,6 @@ func (r AutoManageConfigurationResource) Arguments() map[string]*pluginsdk.Schem Default: false, }, - //"AzureSecurityBaseline/Enable": boolean, - //"AzureSecurityBaseline/AssignmentType": string ("ApplyAndAutoCorrect", "ApplyAndMonitor", "Audit", "DeployAndAutoCorrect"), - "azure_security_baseline": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "enabled": { - Type: pluginsdk.TypeBool, - Optional: true, - Default: false, - }, - "assignment_type": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "ApplyAndAutoCorrect", - ValidateFunc: validation.StringInSlice([]string{ - "ApplyAndAutoCorrect", - "ApplyAndMonitor", - "Audit", - "DeployAndAutoCorrect", - }, false), - }, - }, - }, - }, - - //"Backup/Enable": boolean, - //"Backup/PolicyName": string (length 3 - 150, begin with alphanumeric char, only contain alphanumeric chars and hyphens), - //"Backup/TimeZone": timezone, - //"Backup/InstantRpRetentionRangeInDays": int (1 - 5 if ScheduleRunFrequency is Daily, 5 if ScheduleRunFrequency is Weekly), - //"Backup/SchedulePolicy/ScheduleRunFrequency": string ("Daily", "Weekly"), - //"Backup/SchedulePolicy/ScheduleRunTimes": list of DateTime, - //"Backup/SchedulePolicy/ScheduleRunDays": list of strings (["Sunday", "Monday", "Wednesday", "Thursday", "Friday", "Saturday"]), - //"Backup/SchedulePolicy/SchedulePolicyType": string ("SimpleSchedulePolicy"), - //"Backup/RetentionPolicy/RetentionPolicyType": string ("LongTermRetentionPolicy"), - //"Backup/RetentionPolicy/DailySchedule/RetentionTimes": list of DateTime, - //"Backup/RetentionPolicy/DailySchedule/RetentionDuration/Count": int (7 - 9999), - //"Backup/RetentionPolicy/DailySchedule/RetentionDuration/DurationType": string ("Days"), - //"Backup/RetentionPolicy/WeeklySchedule/RetentionTimes":, list of DateTime - //"Backup/RetentionPolicy/WeeklySchedule/RetentionDuration/Count":, int (1 - 5163) - //"Backup/RetentionPolicy/WeeklySchedule/RetentionDuration/DurationType": string ("Weeks"), - "backup": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "enabled": { - Type: pluginsdk.TypeBool, - Optional: true, - Default: false, - }, - "policy_name": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: validation.StringMatch(regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9-]{2,149}$`), "Policy name must be 3 - 150 characters long, begin with an alphanumeric character, and only contain alphanumeric characters and hyphens."), - }, - "time_zone": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "UTC", - }, - "instant_rp_retention_range_in_days": { - Type: pluginsdk.TypeInt, - Optional: true, - Default: 5, - ValidateFunc: validation.IntBetween(1, 5), - }, - "schedule_policy": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "schedule_run_frequency": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "Daily", - ValidateFunc: validation.StringInSlice([]string{ - "Daily", - "Weekly", - }, false), - }, - "schedule_run_times": { - Type: pluginsdk.TypeList, - Optional: true, - - Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - ValidateFunc: validation.IsRFC3339Time, - }, - }, - "schedule_run_days": { - Type: pluginsdk.TypeList, - Optional: true, - Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - ValidateFunc: validation.StringInSlice([]string{ - "Sunday", - "Monday", - "Tuesday", - "Wednesday", - "Thursday", - "Friday", - "Saturday", - }, false), - }, - }, - "schedule_policy_type": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "SimpleSchedulePolicy", - ValidateFunc: validation.StringInSlice([]string{ - "SimpleSchedulePolicy", - }, false), - }, - }, - }, - }, - "retention_policy": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "retention_policy_type": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "LongTermRetentionPolicy", - ValidateFunc: validation.StringInSlice([]string{ - "LongTermRetentionPolicy", - }, false), - }, - "daily_schedule": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "retention_times": { - Type: pluginsdk.TypeList, - Optional: true, - Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - ValidateFunc: validation.IsRFC3339Time, - }, - }, - "retention_duration": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "count": { - Type: pluginsdk.TypeInt, - Optional: true, - Default: 7, - ValidateFunc: validation.IntBetween(7, 9999), - }, - "duration_type": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "Days", - ValidateFunc: validation.StringInSlice([]string{ - "Days", - }, false), - }, - }, - }, - }, - }, - }, - }, - "weekly_schedule": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "retention_times": { - Type: pluginsdk.TypeList, - Optional: true, - Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - ValidateFunc: validation.IsRFC3339Time, - }, - }, - "retention_duration": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "count": { - Type: pluginsdk.TypeInt, - Optional: true, - Default: 4, - ValidateFunc: validation.IntBetween(4, 9999), - }, - "duration_type": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "Weeks", - ValidateFunc: validation.StringInSlice([]string{ - "Weeks", - }, false), - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - //"BootDiagnostics/Enable": boolean, "boot_diagnostics_enabled": { Type: pluginsdk.TypeBool, @@ -512,279 +191,8 @@ func (r AutoManageConfigurationResource) Arguments() map[string]*pluginsdk.Schem Default: false, }, - //"LogAnalytics/Enable": boolean, - //"LogAnalytics/Reprovision": boolean, - //"LogAnalytics/Workspace": resource ID (Log analytics workspace ID), - "log_analytics": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "enabled": { - Type: pluginsdk.TypeBool, - Optional: true, - Default: false, - }, - "reprovision": { - Type: pluginsdk.TypeBool, - Optional: true, - Default: false, - }, - "workspace_id": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: azure.ValidateResourceID, - }, - }, - }, - }, - - //"TrustedLaunchVM/Backup/Enable": boolean, - //"TrustedLaunchVM/Backup/PolicyName": string (length 3 - 150, begin with alphanumeric char, only contain alphanumeric chars and hyphens), - //"TrustedLaunchVM/Backup/TimeZone": timezone, - //"TrustedLaunchVM/Backup/InstantRpRetentionRangeInDays": int (1 - 30), - //"TrustedLaunchVM/Backup/SchedulePolicy/ScheduleRunFrequency": string ("Hourly", "Daily", "Weekly"), - //"TrustedLaunchVM/Backup/SchedulePolicy/SchedulePolicyType": string ("SimpleSchedulePolicyV2"), - //"TrustedLaunchVM/Backup/RetentionPolicy/RetentionPolicyType":, string ("LongTermRetentionPolicy") - //"TrustedLaunchVM/Backup/SchedulePolicy/HourlySchedule/Interval": int (4, 6, 8, 12), - //"TrustedLaunchVM/Backup/SchedulePolicy/HourlySchedule/ScheduleWindowStartTime": DateTime, - //"TrustedLaunchVM/Backup/SchedulePolicy/HourlySchedule/ScheduleWindowDuration": int (4, 8, 12, 16, 20, 24), - //"TrustedLaunchVM/Backup/RetentionPolicy/DailySchedule/RetentionTimes": list of DateTime, - //"TrustedLaunchVM/Backup/RetentionPolicy/DailySchedule/RetentionDuration/Count": int (7 - 9999), - //"TrustedLaunchVM/Backup/RetentionPolicy/DailySchedule/RetentionDuration/DurationType": string ("Hours", "Days"), - //"TrustedLaunchVM/Backup/SchedulePolicy/DailySchedule/ScheduleWindowStartTime": DateTime, - //"TrustedLaunchVM/Backup/SchedulePolicy/WeeklySchedule/ScheduleRunDays": list of strings (["Sunday", "Monday", "Wednesday", "Thursday", "Friday", "Saturday"]), - //"TrustedLaunchVM/Backup/RetentionPolicy/WeeklySchedule/RetentionDuration/Count": int (1 - 1563), - //"TrustedLaunchVM/Backup/RetentionPolicy/WeeklySchedule/RetentionDuration/DurationType": string ("Weeks"), - "trusted_launch_vm_backup": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "enabled": { - Type: pluginsdk.TypeBool, - Optional: true, - Default: false, - }, - "policy_name": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: validation.StringMatch(regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9-]{2,149}$`), "policy name must be 3 - 150 characters long, begin with an alphanumeric character, and only contain alphanumeric characters and hyphens"), - }, - "time_zone": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "UTC", - }, - "instant_rp_retention_range_in_days": { - Type: pluginsdk.TypeInt, - Optional: true, - Default: 30, - ValidateFunc: validation.IntBetween(1, 30), - }, - "schedule_policy": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "schedule_run_frequency": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "Daily", - ValidateFunc: validation.StringInSlice([]string{ - "Hourly", - "Daily", - "Weekly", - }, false), - }, - "schedule_policy_type": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "SimpleSchedulePolicyV2", - ValidateFunc: validation.StringInSlice([]string{ - "SimpleSchedulePolicyV2", - }, false), - }, - "hourly_schedule": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "interval": { - Type: pluginsdk.TypeInt, - Optional: true, - Default: 4, - ValidateFunc: validation.IntInSlice([]int{4, 6, 8, 12}), - }, - "schedule_window_start_time": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: validation.IsRFC3339Time, - }, - "schedule_window_duration": { - Type: pluginsdk.TypeInt, - Optional: true, - Default: 4, - ValidateFunc: validation.IntInSlice([]int{4, 8, 12, 16, 20, 24}), - }, - }, - }, - }, - "daily_schedule": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "schedule_window_start_time": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: validation.IsRFC3339Time, - }, - }, - }, - }, - "weekly_schedule": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "schedule_run_days": { - Type: pluginsdk.TypeList, - Optional: true, - Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - ValidateFunc: validation.StringInSlice([]string{ - "Sunday", - "Monday", - "Tuesday", - "Wednesday", - "Thursday", - "Friday", - "Saturday", - }, false), - }, - }, - }, - }, - }, - }, - }, - }, - "retention_policy": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "retention_policy_type": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "LongTermRetentionPolicy", - ValidateFunc: validation.StringInSlice([]string{ - "LongTermRetentionPolicy", - }, false), - }, - "daily_schedule": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "retention_times": { - Type: pluginsdk.TypeList, - Optional: true, - Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - ValidateFunc: validation.IsRFC3339Time, - }, - }, - "retention_duration": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "count": { - Type: pluginsdk.TypeInt, - Optional: true, - Default: 7, - ValidateFunc: validation.IntBetween(7, 9999), - }, - "duration_type": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "Days", - ValidateFunc: validation.StringInSlice([]string{ - "Days", - }, false), - }, - }, - }, - }, - }, - }, - }, - "weekly_schedule": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "retention_duration": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "count": { - Type: pluginsdk.TypeInt, - Optional: true, - Default: 4, - ValidateFunc: validation.IntBetween(4, 9999), - }, - "duration_type": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "Weeks", - ValidateFunc: validation.StringInSlice([]string{ - "Weeks", - }, false), - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - - //"UpdateManagement/Enable": boolean, - "update_management_enabled": { - Type: pluginsdk.TypeBool, - Optional: true, - Default: false, - }, - - //"VMInsights/Enable": boolean, - "vm_insights_enabled": { - Type: pluginsdk.TypeBool, - Optional: true, - Default: false, - }, - - //"WindowsAdminCenter/Enable": boolean, - "windows_admin_center_enabled": { + //"Alerts/AutomanageStatusChanges/Enable": boolean, + "status_change_alert_enabled": { Type: pluginsdk.TypeBool, Optional: true, Default: false, @@ -802,7 +210,7 @@ func (r AutoManageConfigurationResource) Create() sdk.ResourceFunc { return sdk.ResourceFunc{ Timeout: 30 * time.Minute, Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { - var model AutoManageConfigurationModel + var model ConfigurationModel if err := metadata.Decode(&model); err != nil { return fmt.Errorf("decoding: %+v", err) } @@ -828,35 +236,47 @@ func (r AutoManageConfigurationResource) Create() sdk.ResourceFunc { // Convert all to a map[string]interface{} and convert to a json property jsonConfig := make(map[string]interface{}) - if model.AutomationAccountEnabled { - jsonConfig["AutomationAccount"] = map[string]interface{}{ - "Enable": model.AutomationAccountEnabled, + if model.Antimalware != nil && len(model.Antimalware) > 0 { + antimalwareConfig := model.Antimalware[0] + jsonConfig["Antimalware/Enable"] = antimalwareConfig.Enabled + jsonConfig["Antimalware/RealTimeProtectionEnabled"] = antimalwareConfig.RealTimeProtectionEnabled + jsonConfig["Antimalware/RunScheduledScan"] = antimalwareConfig.ScheduledScanEnabled + jsonConfig["Antimalware/ScanType"] = antimalwareConfig.ScanType + jsonConfig["Antimalware/ScanDay"] = antimalwareConfig.ScanDay + jsonConfig["Antimalware/ScanTimeInMinutes"] = antimalwareConfig.ScanTimeInMinutes + if antimalwareConfig.Exclusions != nil && len(antimalwareConfig.Exclusions) > 0 { + jsonConfig["Antimalware/Exclusions/Extensions"] = antimalwareConfig.Exclusions[0].Extensions + jsonConfig["Antimalware/Exclusions/Paths"] = antimalwareConfig.Exclusions[0].Paths + jsonConfig["Antimalware/Exclusions/Processes"] = antimalwareConfig.Exclusions[0].Processes } } - if model.Antimalware != nil { - jsonConfig["Antimalware"] = map[string]interface{}{ - "Enable": model.Antimalware.Enabled, - } - if exclusions := model.Antimalware.Exclusions; exclusions != nil { - - } + if model.AutomationAccountEnabled { + jsonConfig["AutomationAccount/Enable"] = model.AutomationAccountEnabled } if model.BootDiagnosticsEnabled { - jsonConfig["BootDiagnostics"] = map[string]interface{}{ - "Enable": model.BootDiagnosticsEnabled, - } + jsonConfig["BootDiagnostics/Enable"] = model.BootDiagnosticsEnabled + } + + if model.ChangeTrackingEnabled { + jsonConfig["ChangeTracking/Enable"] = model.ChangeTrackingEnabled + } + + if model.DefenderForCloudEnabled { + jsonConfig["DefenderForCloud/Enable"] = model.DefenderForCloudEnabled + } + + if model.GuestConfigurationEnabled { + jsonConfig["GuestConfiguration/Enable"] = model.GuestConfigurationEnabled } if model.StatusChangeAlertEnabled { - jsonConfig["Alert"] = map[string]interface{}{ - "AutomanageStatusChanges": map[string]interface{}{ - "Enable": model.StatusChangeAlertEnabled, - }, - } + jsonConfig["Alerts/AutomanageStatusChanges/Enable"] = model.StatusChangeAlertEnabled } + properties.Properties.Configuration = &jsonConfig + if _, err := client.CreateOrUpdate(ctx, id.ConfigurationProfileName, id.ResourceGroup, properties); err != nil { return fmt.Errorf("creating %s: %+v", id, err) } @@ -878,7 +298,7 @@ func (r AutoManageConfigurationResource) Update() sdk.ResourceFunc { return err } - var model AutoManageConfigurationModel + var model ConfigurationModel if err := metadata.Decode(&model); err != nil { return fmt.Errorf("decoding: %+v", err) } @@ -888,11 +308,72 @@ func (r AutoManageConfigurationResource) Update() sdk.ResourceFunc { return fmt.Errorf("retrieving %s: %+v", *id, err) } + jsonConfig := make(map[string]interface{}) + + if resp.Properties != nil && resp.Properties.Configuration != nil { + err := json.Unmarshal([]byte(resp.Properties.Configuration.(string)), &jsonConfig) + if err != nil { + return fmt.Errorf("unmarshalling %s: %+v", *id, err) + } + } + + if model.Antimalware != nil { + antimalwareConfig := model.Antimalware[0] + jsonConfig["Antimalware/Enable"] = antimalwareConfig.Enabled + jsonConfig["Antimalware/RealTimeProtectionEnabled"] = antimalwareConfig.RealTimeProtectionEnabled + jsonConfig["Antimalware/RunScheduledScan"] = antimalwareConfig.ScheduledScanEnabled + jsonConfig["Antimalware/ScanType"] = antimalwareConfig.ScanType + jsonConfig["Antimalware/ScanDay"] = antimalwareConfig.ScanDay + jsonConfig["Antimalware/ScanTimeInMinutes"] = antimalwareConfig.ScanTimeInMinutes + if antimalwareConfig.Exclusions != nil && len(antimalwareConfig.Exclusions) > 0 { + jsonConfig["Antimalware/Exclusions/Extensions"] = antimalwareConfig.Exclusions[0].Extensions + jsonConfig["Antimalware/Exclusions/Paths"] = antimalwareConfig.Exclusions[0].Paths + jsonConfig["Antimalware/Exclusions/Processes"] = antimalwareConfig.Exclusions[0].Processes + } + } + + if metadata.ResourceData.HasChange("automation_account_enabled") { + jsonConfig["AutomationAccount/Enable"] = model.AutomationAccountEnabled + } + + if metadata.ResourceData.HasChange("boot_diagnostics_enabled") { + jsonConfig["BootDiagnostics/Enable"] = model.BootDiagnosticsEnabled + } + + if metadata.ResourceData.HasChange("change_tracking_enabled") { + jsonConfig["ChangeTracking/Enable"] = model.ChangeTrackingEnabled + } + + if metadata.ResourceData.HasChange("defender_for_cloud_enabled") { + jsonConfig["DefenderForCloud/Enable"] = model.DefenderForCloudEnabled + } + + if metadata.ResourceData.HasChange("guest_configuration_enabled") { + jsonConfig["GuestConfiguration/Enable"] = model.GuestConfigurationEnabled + } + + if metadata.ResourceData.HasChange("status_change_alert_enabled") { + jsonConfig["Alerts/AutomanageStatusChanges/Enable"] = model.StatusChangeAlertEnabled + } + if metadata.ResourceData.HasChange("tags") { resp.Tags = tags.FromTypedObject(model.Tags) } - if _, err := client.CreateOrUpdate(ctx, id.ConfigurationProfileName, id.ResourceGroup, resp); err != nil { + configBytes, err := json.Marshal(jsonConfig) + if err != nil { + return fmt.Errorf("marshalling %s: %+v", *id, err) + } + + properties := automanage.ConfigurationProfile{ + Location: utils.String(metadata.ResourceData.Get("location").(string)), + Properties: &automanage.ConfigurationProfileProperties{ + Configuration: configBytes, + }, + Tags: resp.Tags, + } + + if _, err := client.CreateOrUpdate(ctx, id.ConfigurationProfileName, id.ResourceGroup, properties); err != nil { return fmt.Errorf("updating %s: %+v", *id, err) } @@ -921,12 +402,65 @@ func (r AutoManageConfigurationResource) Read() sdk.ResourceFunc { return fmt.Errorf("retrieving %s: %+v", *id, err) } - state := AutoManageConfigurationModel{ + state := ConfigurationModel{ Name: id.ConfigurationProfileName, ResourceGroupName: id.ResourceGroup, Location: location.NormalizeNilable(resp.Location), } + if resp.Properties != nil && resp.Properties.Configuration != nil { + configMap := make(map[string]interface{}) + err := json.Unmarshal(resp.Properties.Configuration.([]byte), &configMap) + if err != nil { + return fmt.Errorf("unmarshalling %s: %+v", *id, err) + } + + if configMap["Antimalware/Enable"] != nil { + state.Antimalware = make([]AntimalwareConfiguration, 1) + state.Antimalware[0] = AntimalwareConfiguration{ + Enabled: configMap["Antimalware/Enable"].(bool), + RealTimeProtectionEnabled: configMap["Antimalware/RealTimeProtectionEnabled"].(bool), + ScheduledScanEnabled: configMap["Antimalware/RunScheduledScan"].(bool), + ScanType: configMap["Antimalware/ScanType"].(string), + ScanDay: configMap["Antimalware/ScanDay"].(int), + ScanTimeInMinutes: configMap["Antimalware/ScanTimeInMinutes"].(int), + } + + if configMap["Antimalware/Exclusions/Extensions"] != nil { + state.Antimalware[0].Exclusions = make([]AntimalwareExclusions, 1) + state.Antimalware[0].Exclusions[0] = AntimalwareExclusions{ + Extensions: configMap["Antimalware/Exclusions/Extensions"].(string), + Paths: configMap["Antimalware/Exclusions/Paths"].(string), + Processes: configMap["Antimalware/Exclusions/Processes"].(string), + } + } + } + + if configMap["AutomationAccount/Enable"] != nil { + state.AutomationAccountEnabled = configMap["AutomationAccount/Enable"].(bool) + } + + if configMap["BootDiagnostics/Enable"] != nil { + state.BootDiagnosticsEnabled = configMap["BootDiagnostics/Enable"].(bool) + } + + if configMap["ChangeTracking/Enable"] != nil { + state.ChangeTrackingEnabled = configMap["ChangeTracking/Enable"].(bool) + } + + if configMap["DefenderForCloud/Enable"] != nil { + state.DefenderForCloudEnabled = configMap["DefenderForServers/Enable"].(bool) + } + + if configMap["GuestConfiguration/Enable"] != nil { + state.GuestConfigurationEnabled = configMap["GuestConfiguration/Enable"].(bool) + } + + if configMap["Alerts/AutomanageStatusChanges/Enable"] != nil { + state.StatusChangeAlertEnabled = configMap["Alerts/AutomanageStatusChanges/Enable"].(bool) + } + } + if resp.Tags != nil { state.Tags = tags.ToTypedObject(resp.Tags) } diff --git a/internal/services/automanage/automanage_configuration_resource_test.go b/internal/services/automanage/automanage_configuration_resource_test.go index 6b3a2553ce34..f5232caf8131 100644 --- a/internal/services/automanage/automanage_configuration_resource_test.go +++ b/internal/services/automanage/automanage_configuration_resource_test.go @@ -118,17 +118,28 @@ resource "azurerm_automanage_configuration" "test" { name = "acctest-amcp-%d" resource_group_name = azurerm_resource_group.test.name location = "%s" - configuration_json = jsonencode({ - "Antimalware/Enable" : false, - "AzureSecurityCenter/Enable" : true, - "Backup/Enable" : false, - "BootDiagnostics/Enable" : true, - "ChangeTrackingAndInventory/Enable" : true, - "GuestConfiguration/Enable" : true, - "LogAnalytics/Enable" : true, - "UpdateManagement/Enable" : true, - "VMInsights/Enable" : true - }) + antimalware { + enabled = true + exclusions { + extensions = "exe;dll" + paths = "C:\\Windows\\Temp;D:\\Temp" + processes = "svchost.exe;notepad.exe" + } + real_time_protection = true + scheduled_scan_enabled = true + scheduled_scan_type = "Quick" + scheduled_scan_day = 1 + scheduled_scan_time_in_minutes = 1339 + } + automation_account_enabled = true + boot_diagnostics_enabled = true + change_tracking_and_inventory_enabled = true + defender_for_cloud_enabled = true + guest_configuration_enabled = true + status_change_alert_enabled = true + tags = { + "env" = "test" + } } `, template, data.RandomInteger, data.Locations.Primary) } @@ -166,21 +177,28 @@ resource "azurerm_automanage_configuration" "test" { name = "acctest-amcp-%d" resource_group_name = azurerm_resource_group.test.name location = "%s" - configuration_json = jsonencode({ - "Antimalware/Enable" : false, - "AzureSecurityCenter/Enable" : true, - "Backup/Enable" : false, - "BootDiagnostics/Enable" : true, - "ChangeTrackingAndInventory/Enable" : true, - "GuestConfiguration/Enable" : true, - "LogAnalytics/Enable" : true, - "UpdateManagement/Enable" : true, - "VMInsights/Enable" : true - }) + antimalware { + enabled = true + exclusions { + extensions = "exe;dll" + paths = "C:\\Windows\\Temp;D:\\Temp" + processes = "svchost.exe;notepad.exe" + } + real_time_protection_enabled = true + scheduled_scan_enabled = true + scheduled_scan_type = "Quick" + scheduled_scan_day = 1 + scheduled_scan_time_in_minutes = 1339 + } + automation_account_enabled = true + boot_diagnostics_enabled = true + change_tracking_and_inventory_enabled = true + defender_for_cloud_enabled = true + guest_configuration_enabled = true + status_change_alert_enabled = true tags = { - key = "value" + "env" = "test" } - } `, template, data.RandomInteger, data.Locations.Primary) } From 5867394d2da6f6e5986d2267fbaaf8e78aed2afc Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Wed, 19 Apr 2023 16:02:26 +0800 Subject: [PATCH 18/27] update test cases for automanage_configuration_resource.go --- .../automanage_configuration_resource.go | 125 +++++++++--------- .../automanage_configuration_resource_test.go | 98 ++++++++------ 2 files changed, 118 insertions(+), 105 deletions(-) diff --git a/internal/services/automanage/automanage_configuration_resource.go b/internal/services/automanage/automanage_configuration_resource.go index 309ca9f7b6ec..8d92328d18df 100644 --- a/internal/services/automanage/automanage_configuration_resource.go +++ b/internal/services/automanage/automanage_configuration_resource.go @@ -2,7 +2,6 @@ package automanage import ( "context" - "encoding/json" "fmt" "time" @@ -25,7 +24,6 @@ type ConfigurationModel struct { Antimalware []AntimalwareConfiguration `tfschema:"antimalware"` AutomationAccountEnabled bool `tfschema:"automation_account_enabled"` BootDiagnosticsEnabled bool `tfschema:"boot_diagnostics_enabled"` - ChangeTrackingEnabled bool `tfschema:"change_tracking_enabled"` DefenderForCloudEnabled bool `tfschema:"defender_for_cloud_enabled"` GuestConfigurationEnabled bool `tfschema:"guest_configuration_enabled"` StatusChangeAlertEnabled bool `tfschema:"status_change_alert_enabled"` @@ -171,13 +169,6 @@ func (r AutoManageConfigurationResource) Arguments() map[string]*pluginsdk.Schem Default: false, }, - //"ChangeTrackingAndInventory/Enable": boolean, - "change_tracking_and_inventory_enabled": { - Type: pluginsdk.TypeBool, - Optional: true, - Default: false, - }, - // "DefenderForCloud/Enable": boolean, "defender_for_cloud_enabled": { Type: pluginsdk.TypeBool, @@ -239,7 +230,7 @@ func (r AutoManageConfigurationResource) Create() sdk.ResourceFunc { if model.Antimalware != nil && len(model.Antimalware) > 0 { antimalwareConfig := model.Antimalware[0] jsonConfig["Antimalware/Enable"] = antimalwareConfig.Enabled - jsonConfig["Antimalware/RealTimeProtectionEnabled"] = antimalwareConfig.RealTimeProtectionEnabled + jsonConfig["Antimalware/EnableRealTimeProtection"] = antimalwareConfig.RealTimeProtectionEnabled jsonConfig["Antimalware/RunScheduledScan"] = antimalwareConfig.ScheduledScanEnabled jsonConfig["Antimalware/ScanType"] = antimalwareConfig.ScanType jsonConfig["Antimalware/ScanDay"] = antimalwareConfig.ScanDay @@ -259,10 +250,6 @@ func (r AutoManageConfigurationResource) Create() sdk.ResourceFunc { jsonConfig["BootDiagnostics/Enable"] = model.BootDiagnosticsEnabled } - if model.ChangeTrackingEnabled { - jsonConfig["ChangeTracking/Enable"] = model.ChangeTrackingEnabled - } - if model.DefenderForCloudEnabled { jsonConfig["DefenderForCloud/Enable"] = model.DefenderForCloudEnabled } @@ -311,16 +298,13 @@ func (r AutoManageConfigurationResource) Update() sdk.ResourceFunc { jsonConfig := make(map[string]interface{}) if resp.Properties != nil && resp.Properties.Configuration != nil { - err := json.Unmarshal([]byte(resp.Properties.Configuration.(string)), &jsonConfig) - if err != nil { - return fmt.Errorf("unmarshalling %s: %+v", *id, err) - } + jsonConfig = resp.Properties.Configuration.(map[string]interface{}) } if model.Antimalware != nil { antimalwareConfig := model.Antimalware[0] jsonConfig["Antimalware/Enable"] = antimalwareConfig.Enabled - jsonConfig["Antimalware/RealTimeProtectionEnabled"] = antimalwareConfig.RealTimeProtectionEnabled + jsonConfig["Antimalware/EnableRealTimeProtection"] = antimalwareConfig.RealTimeProtectionEnabled jsonConfig["Antimalware/RunScheduledScan"] = antimalwareConfig.ScheduledScanEnabled jsonConfig["Antimalware/ScanType"] = antimalwareConfig.ScanType jsonConfig["Antimalware/ScanDay"] = antimalwareConfig.ScanDay @@ -340,10 +324,6 @@ func (r AutoManageConfigurationResource) Update() sdk.ResourceFunc { jsonConfig["BootDiagnostics/Enable"] = model.BootDiagnosticsEnabled } - if metadata.ResourceData.HasChange("change_tracking_enabled") { - jsonConfig["ChangeTracking/Enable"] = model.ChangeTrackingEnabled - } - if metadata.ResourceData.HasChange("defender_for_cloud_enabled") { jsonConfig["DefenderForCloud/Enable"] = model.DefenderForCloudEnabled } @@ -360,15 +340,10 @@ func (r AutoManageConfigurationResource) Update() sdk.ResourceFunc { resp.Tags = tags.FromTypedObject(model.Tags) } - configBytes, err := json.Marshal(jsonConfig) - if err != nil { - return fmt.Errorf("marshalling %s: %+v", *id, err) - } - properties := automanage.ConfigurationProfile{ Location: utils.String(metadata.ResourceData.Get("location").(string)), Properties: &automanage.ConfigurationProfileProperties{ - Configuration: configBytes, + Configuration: &jsonConfig, }, Tags: resp.Tags, } @@ -409,55 +384,31 @@ func (r AutoManageConfigurationResource) Read() sdk.ResourceFunc { } if resp.Properties != nil && resp.Properties.Configuration != nil { - configMap := make(map[string]interface{}) - err := json.Unmarshal(resp.Properties.Configuration.([]byte), &configMap) + configMap := resp.Properties.Configuration.(map[string]interface{}) if err != nil { return fmt.Errorf("unmarshalling %s: %+v", *id, err) } - if configMap["Antimalware/Enable"] != nil { - state.Antimalware = make([]AntimalwareConfiguration, 1) - state.Antimalware[0] = AntimalwareConfiguration{ - Enabled: configMap["Antimalware/Enable"].(bool), - RealTimeProtectionEnabled: configMap["Antimalware/RealTimeProtectionEnabled"].(bool), - ScheduledScanEnabled: configMap["Antimalware/RunScheduledScan"].(bool), - ScanType: configMap["Antimalware/ScanType"].(string), - ScanDay: configMap["Antimalware/ScanDay"].(int), - ScanTimeInMinutes: configMap["Antimalware/ScanTimeInMinutes"].(int), - } - - if configMap["Antimalware/Exclusions/Extensions"] != nil { - state.Antimalware[0].Exclusions = make([]AntimalwareExclusions, 1) - state.Antimalware[0].Exclusions[0] = AntimalwareExclusions{ - Extensions: configMap["Antimalware/Exclusions/Extensions"].(string), - Paths: configMap["Antimalware/Exclusions/Paths"].(string), - Processes: configMap["Antimalware/Exclusions/Processes"].(string), - } - } - } - - if configMap["AutomationAccount/Enable"] != nil { - state.AutomationAccountEnabled = configMap["AutomationAccount/Enable"].(bool) - } + state.Antimalware = flattenAntimarewareConfig(configMap) - if configMap["BootDiagnostics/Enable"] != nil { - state.BootDiagnosticsEnabled = configMap["BootDiagnostics/Enable"].(bool) + if val, ok := configMap["AutomationAccount/Enable"]; ok { + state.AutomationAccountEnabled = val.(bool) } - if configMap["ChangeTracking/Enable"] != nil { - state.ChangeTrackingEnabled = configMap["ChangeTracking/Enable"].(bool) + if val, ok := configMap["BootDiagnostics/Enable"]; ok { + state.BootDiagnosticsEnabled = val.(bool) } - if configMap["DefenderForCloud/Enable"] != nil { - state.DefenderForCloudEnabled = configMap["DefenderForServers/Enable"].(bool) + if val, ok := configMap["DefenderForCloud/Enable"]; ok { + state.DefenderForCloudEnabled = val.(bool) } - if configMap["GuestConfiguration/Enable"] != nil { - state.GuestConfigurationEnabled = configMap["GuestConfiguration/Enable"].(bool) + if val, ok := configMap["GuestConfiguration/Enable"]; ok { + state.GuestConfigurationEnabled = val.(bool) } - if configMap["Alerts/AutomanageStatusChanges/Enable"] != nil { - state.StatusChangeAlertEnabled = configMap["Alerts/AutomanageStatusChanges/Enable"].(bool) + if val, ok := configMap["Alerts/AutomanageStatusChanges/Enable"]; ok { + state.StatusChangeAlertEnabled = val.(bool) } } @@ -489,3 +440,47 @@ func (r AutoManageConfigurationResource) Delete() sdk.ResourceFunc { }, } } + +func flattenAntimarewareConfig(configMap map[string]interface{}) []AntimalwareConfiguration { + antimalware := make([]AntimalwareConfiguration, 1) + antimalware[0] = AntimalwareConfiguration{} + antimalware[0].Exclusions = make([]AntimalwareExclusions, 1) + + if val, ok := configMap["Antimalware/Enable"]; ok { + antimalware[0].Enabled = val.(bool) + } + + if val, ok := configMap["Antimalware/EnableRealTimeProtection"]; ok { + antimalware[0].RealTimeProtectionEnabled = val.(bool) + } + + if val, ok := configMap["Antimalware/RunScheduledScan"]; ok { + antimalware[0].ScheduledScanEnabled = val.(bool) + } + + if val, ok := configMap["Antimalware/ScanType"]; ok { + antimalware[0].ScanType = val.(string) + } + + if val, ok := configMap["Antimalware/ScanDay"]; ok { + antimalware[0].ScanDay = int(val.(float64)) + } + + if val, ok := configMap["Antimalware/ScanTimeInMinutes"]; ok { + antimalware[0].ScanTimeInMinutes = int(val.(float64)) + } + + if val, ok := configMap["Antimalware/Exclusions/Extensions"]; ok { + antimalware[0].Exclusions[0].Extensions = val.(string) + } + + if val, ok := configMap["Antimalware/Exclusions/Paths"]; ok { + antimalware[0].Exclusions[0].Paths = val.(string) + } + + if val, ok := configMap["Antimalware/Exclusions/Processes"]; ok { + antimalware[0].Exclusions[0].Processes = val.(string) + } + + return antimalware +} diff --git a/internal/services/automanage/automanage_configuration_resource_test.go b/internal/services/automanage/automanage_configuration_resource_test.go index f5232caf8131..c2da1e562a31 100644 --- a/internal/services/automanage/automanage_configuration_resource_test.go +++ b/internal/services/automanage/automanage_configuration_resource_test.go @@ -24,6 +24,12 @@ func TestAccAutoManageConfigurationProfile_basic(t *testing.T) { Config: r.basic(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("antimalware.#").HasValue("1"), + check.That(data.ResourceName).Key("antimalware.0.enabled").HasValue("true"), + check.That(data.ResourceName).Key("antimalware.0.exclusions.#").HasValue("1"), + check.That(data.ResourceName).Key("antimalware.0.exclusions.0.extensions").HasValue("exe;dll"), + check.That(data.ResourceName).Key("antimalware.0.real_time_protection_enabled").HasValue("true"), + check.That(data.ResourceName).Key("automation_account_enabled").HasValue("true"), ), }, data.ImportStep(), @@ -52,6 +58,21 @@ func TestAccAutoManageConfigurationProfile_complete(t *testing.T) { Config: r.complete(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("antimalware.#").HasValue("1"), + check.That(data.ResourceName).Key("antimalware.0.enabled").HasValue("true"), + check.That(data.ResourceName).Key("antimalware.0.exclusions.#").HasValue("1"), + check.That(data.ResourceName).Key("antimalware.0.exclusions.0.extensions").HasValue("exe;dll"), + check.That(data.ResourceName).Key("antimalware.0.exclusions.0.processes").HasValue("svchost.exe;notepad.exe"), + check.That(data.ResourceName).Key("antimalware.0.real_time_protection_enabled").HasValue("true"), + check.That(data.ResourceName).Key("antimalware.0.scheduled_scan_enabled").HasValue("true"), + check.That(data.ResourceName).Key("antimalware.0.scheduled_scan_day").HasValue("1"), + check.That(data.ResourceName).Key("antimalware.0.scheduled_scan_type").HasValue("Quick"), + check.That(data.ResourceName).Key("antimalware.0.scheduled_scan_time_in_minutes").HasValue("1339"), + check.That(data.ResourceName).Key("automation_account_enabled").HasValue("true"), + check.That(data.ResourceName).Key("boot_diagnostics_enabled").HasValue("true"), + check.That(data.ResourceName).Key("defender_for_cloud_enabled").HasValue("true"), + check.That(data.ResourceName).Key("guest_configuration_enabled").HasValue("true"), + check.That(data.ResourceName).Key("status_change_alert_enabled").HasValue("true"), ), }, data.ImportStep(), @@ -73,6 +94,21 @@ func TestAccAutoManageConfigurationProfile_update(t *testing.T) { Config: r.update(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("antimalware.#").HasValue("1"), + check.That(data.ResourceName).Key("antimalware.0.enabled").HasValue("true"), + check.That(data.ResourceName).Key("antimalware.0.exclusions.#").HasValue("1"), + check.That(data.ResourceName).Key("antimalware.0.exclusions.0.extensions").HasValue("exe"), + check.That(data.ResourceName).Key("antimalware.0.exclusions.0.processes").HasValue("svchost.exe"), + check.That(data.ResourceName).Key("antimalware.0.real_time_protection_enabled").HasValue("false"), + check.That(data.ResourceName).Key("antimalware.0.scheduled_scan_enabled").HasValue("true"), + check.That(data.ResourceName).Key("antimalware.0.scheduled_scan_day").HasValue("2"), + check.That(data.ResourceName).Key("antimalware.0.scheduled_scan_type").HasValue("Full"), + check.That(data.ResourceName).Key("antimalware.0.scheduled_scan_time_in_minutes").HasValue("1338"), + check.That(data.ResourceName).Key("automation_account_enabled").HasValue("false"), + check.That(data.ResourceName).Key("boot_diagnostics_enabled").HasValue("false"), + check.That(data.ResourceName).Key("defender_for_cloud_enabled").HasValue("false"), + check.That(data.ResourceName).Key("guest_configuration_enabled").HasValue("false"), + check.That(data.ResourceName).Key("status_change_alert_enabled").HasValue("false"), ), }, data.ImportStep(), @@ -122,24 +158,10 @@ resource "azurerm_automanage_configuration" "test" { enabled = true exclusions { extensions = "exe;dll" - paths = "C:\\Windows\\Temp;D:\\Temp" - processes = "svchost.exe;notepad.exe" } - real_time_protection = true - scheduled_scan_enabled = true - scheduled_scan_type = "Quick" - scheduled_scan_day = 1 - scheduled_scan_time_in_minutes = 1339 + real_time_protection_enabled = true } automation_account_enabled = true - boot_diagnostics_enabled = true - change_tracking_and_inventory_enabled = true - defender_for_cloud_enabled = true - guest_configuration_enabled = true - status_change_alert_enabled = true - tags = { - "env" = "test" - } } `, template, data.RandomInteger, data.Locations.Primary) } @@ -153,17 +175,14 @@ resource "azurerm_automanage_configuration" "import" { name = azurerm_automanage_configuration.test.name resource_group_name = azurerm_resource_group.test.name location = "%s" - configuration_json = jsonencode({ - "Antimalware/Enable" : false, - "AzureSecurityCenter/Enable" : true, - "Backup/Enable" : false, - "BootDiagnostics/Enable" : true, - "ChangeTrackingAndInventory/Enable" : true, - "GuestConfiguration/Enable" : true, - "LogAnalytics/Enable" : true, - "UpdateManagement/Enable" : true, - "VMInsights/Enable" : true - }) + antimalware { + enabled = true + exclusions { + extensions = "exe;dll" + } + real_time_protection_enabled = true + } + automation_account_enabled = true } `, config, data.Locations.Primary) } @@ -192,7 +211,6 @@ resource "azurerm_automanage_configuration" "test" { } automation_account_enabled = true boot_diagnostics_enabled = true - change_tracking_and_inventory_enabled = true defender_for_cloud_enabled = true guest_configuration_enabled = true status_change_alert_enabled = true @@ -212,21 +230,21 @@ resource "azurerm_automanage_configuration" "test" { name = "acctest-amcp-%d" resource_group_name = azurerm_resource_group.test.name location = "%s" - configuration_json = jsonencode({ - "Antimalware/Enable" : false, - "AzureSecurityCenter/Enable" : true, - "Backup/Enable" : true, - "BootDiagnostics/Enable" : true, - "ChangeTrackingAndInventory/Enable" : true, - "GuestConfiguration/Enable" : true, - "LogAnalytics/Enable" : true, - "UpdateManagement/Enable" : true, - "VMInsights/Enable" : true - }) + antimalware { + enabled = true + exclusions { + extensions = "exe" + processes = "svchost.exe" + } + real_time_protection_enabled = false + scheduled_scan_enabled = true + scheduled_scan_type = "Full" + scheduled_scan_day = 2 + scheduled_scan_time_in_minutes = 1338 + } tags = { - key2 = "value2" + "env2" = "test2" } - } `, template, data.RandomInteger, data.Locations.Primary) } From 0340f03a6cd395035ea30ef6e1b30073404fd1ab Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Thu, 20 Apr 2023 12:51:42 +0800 Subject: [PATCH 19/27] update document --- .../automanage_configuration_resource.go | 4 +- .../2022-05-04/automanage/version.go | 4 +- vendor/modules.txt | 1 + .../r/automanage_configuration.html.markdown | 77 +++++++++++++++---- 4 files changed, 69 insertions(+), 17 deletions(-) diff --git a/internal/services/automanage/automanage_configuration_resource.go b/internal/services/automanage/automanage_configuration_resource.go index 8d92328d18df..eb269230b2ae 100644 --- a/internal/services/automanage/automanage_configuration_resource.go +++ b/internal/services/automanage/automanage_configuration_resource.go @@ -119,7 +119,7 @@ func (r AutoManageConfigurationResource) Arguments() map[string]*pluginsdk.Schem "scheduled_scan_day": { Type: pluginsdk.TypeInt, Optional: true, - Default: 0, + Default: 8, ValidateFunc: validation.IntInSlice([]int{ 0, 1, 2, 3, 4, 5, 6, 7, 8, }), @@ -128,7 +128,7 @@ func (r AutoManageConfigurationResource) Arguments() map[string]*pluginsdk.Schem Type: pluginsdk.TypeInt, Optional: true, Default: 0, - ValidateFunc: validation.IntBetween(0, 1440), + ValidateFunc: validation.IntBetween(0, 1439), }, "exclusions": { Type: pluginsdk.TypeList, diff --git a/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/version.go b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/version.go index 34adf4eb2f11..80eddeb41231 100644 --- a/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/version.go +++ b/vendor/github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage/version.go @@ -1,6 +1,6 @@ package automanage -import "github.com/Azure/azure-sdk-for-go/version" +import "github.com/tombuildsstuff/kermit/version" // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. @@ -10,7 +10,7 @@ import "github.com/Azure/azure-sdk-for-go/version" // UserAgent returns the UserAgent string to use when sending http.Requests. func UserAgent() string { - return "Azure-SDK-For-Go/" + Version() + " automanage/2022-05-04" + return "tombuildsstuff/kermit/" + Version() + " automanage/2022-05-04" } // Version returns the semantic version (see http://semver.org) of the client. diff --git a/vendor/modules.txt b/vendor/modules.txt index 11508e168649..a1fc966d3bed 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -806,6 +806,7 @@ github.com/tombuildsstuff/giovanni/version # github.com/tombuildsstuff/kermit v0.20230331.1120327 ## explicit; go 1.18 github.com/tombuildsstuff/kermit/sdk/appplatform/2022-11-01-preview/appplatform +github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage github.com/tombuildsstuff/kermit/sdk/batch/2022-01.15.0/batch github.com/tombuildsstuff/kermit/sdk/botservice/2021-05-01-preview/botservice github.com/tombuildsstuff/kermit/sdk/compute/2022-08-01/compute diff --git a/website/docs/r/automanage_configuration.html.markdown b/website/docs/r/automanage_configuration.html.markdown index e3175b8ccb53..f8915d3bee9f 100644 --- a/website/docs/r/automanage_configuration.html.markdown +++ b/website/docs/r/automanage_configuration.html.markdown @@ -19,20 +19,35 @@ resource "azurerm_resource_group" "example" { } resource "azurerm_automanage_configuration" "example" { - name = "example-configurationprofile" + name = "example-acmp" resource_group_name = azurerm_resource_group.example.name location = azurerm_resource_group.example.location - configuration_json = jsonencode({ - "Antimalware/Enable" : false, - "AzureSecurityCenter/Enable" : true, - "Backup/Enable" : false, - "BootDiagnostics/Enable" : true, - "ChangeTrackingAndInventory/Enable" : true, - "GuestConfiguration/Enable" : true, - "LogAnalytics/Enable" : true, - "UpdateManagement/Enable" : true, - "VMInsights/Enable" : true - }) + + antimalware { + enabled = true + + exclusions { + extensions = "exe;dll" + paths = "C:\\Windows\\Temp;D:\\Temp" + processes = "svchost.exe;notepad.exe" + } + + real_time_protection_enabled = true + scheduled_scan_enabled = true + scheduled_scan_type = "Quick" + scheduled_scan_day = 1 + scheduled_scan_time_in_minutes = 1339 + } + + automation_account_enabled = true + boot_diagnostics_enabled = true + defender_for_cloud_enabled = true + guest_configuration_enabled = true + status_change_alert_enabled = true + + tags = { + "env" = "test" + } } ``` @@ -46,10 +61,46 @@ The following arguments are supported: * `location` - (Required) The Azure Region where the automanage ConfigurationProfile should exist. Changing this forces a new automanage ConfigurationProfile to be created. -* `configuration_json` - (Required) configuration dictionary of the configuration profile. Changing this forces a new automanage ConfigurationProfile to be created. +* `antimalware` - (Optional) A `antimalware` block as defined below. + +* `automation_account_enabled` - (Optional) Whether the automation account is enabled. Defaults to `false`. + +* `boot_diagnostics_enabled` - (Optional) Whether the boot diagnostics is enabled. Defaults to `false`. + +* `defender_for_cloud_enabled` - (Optional) Whether the defender for cloud is enabled. Defaults to `false`. + +* `guest_configuration_enabled` - (Optional) Whether the guest configuration is enabled. Defaults to `false`. + +* `status_change_alert_enabled` - (Optional) Whether the status change alert is enabled. Defaults to `false`. --- +* `antimalware` supports the following: + +* `enabled` - (Required) Whether the antimalware is enabled. Defaults to `false`. + +* `exclusions` - (Optional) A `exclusions` block as defined below. + +* `real_time_protection_enabled` - (Optional) Whether the real time protection is enabled. Defaults to `false`. + +* `scheduled_scan_enabled` - (Optional) Whether the scheduled scan is enabled. Defaults to `false`. + +* `scheduled_scan_type` - (Optional) The type of the scheduled scan. Possible values are `Quick` and `Full`. Defaults to `Quick`. + +* `scheduled_scan_day` - (Optional) The day of the scheduled scan. Possible values are `0` to `8` where `0` is daily, `1` to `7` are the days of the week and `8` is Disabled. Defaults to `8`. + +* `scheduled_scan_time_in_minutes` - (Optional) The time of the scheduled scan in minutes. Possible values are `0` to `1439` where `0` is 12:00 AM and `1439` is 11:59 PM. + +--- + +* `exclusions` supports the following: + +* `extensions` - (Optional) The extensions to exclude from the antimalware scan, separated by `;`. For example `.ext1;.ext2`. + +* `paths` - (Optional) The paths to exclude from the antimalware scan, separated by `;`. For example `C:\\Windows\\Temp;D:\\Temp`. + +* `processes` - (Optional) The processes to exclude from the antimalware scan, separated by `;`. For example `svchost.exe;notepad.exe`. + * `tags` - (Optional) A mapping of tags which should be assigned to the automanage ConfigurationProfile. ## Attributes Reference From 646220d004bd198d979e5902f38146ce468e20b4 Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Thu, 20 Apr 2023 14:46:40 +0800 Subject: [PATCH 20/27] update comment --- .../services/automanage/automanage_configuration_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/automanage/automanage_configuration_resource.go b/internal/services/automanage/automanage_configuration_resource.go index eb269230b2ae..268b9fe09732 100644 --- a/internal/services/automanage/automanage_configuration_resource.go +++ b/internal/services/automanage/automanage_configuration_resource.go @@ -224,7 +224,7 @@ func (r AutoManageConfigurationResource) Create() sdk.ResourceFunc { Tags: tags.FromTypedObject(model.Tags), } - // Convert all to a map[string]interface{} and convert to a json property + // building configuration profile in json format jsonConfig := make(map[string]interface{}) if model.Antimalware != nil && len(model.Antimalware) > 0 { From 1350f34cb7c753195655d9e8ec8fdae80ab9294e Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Fri, 21 Apr 2023 08:44:01 +0800 Subject: [PATCH 21/27] update lint --- .../automanage_configuration_resource.go | 26 ++++---- .../automanage_configuration_resource_test.go | 60 +++++++++---------- 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/internal/services/automanage/automanage_configuration_resource.go b/internal/services/automanage/automanage_configuration_resource.go index 8d92328d18df..e993d2445352 100644 --- a/internal/services/automanage/automanage_configuration_resource.go +++ b/internal/services/automanage/automanage_configuration_resource.go @@ -77,15 +77,15 @@ func (r AutoManageConfigurationResource) Arguments() map[string]*pluginsdk.Schem "location": commonschema.Location(), - //"Antimalware/Enable": boolean, - //"Antimalware/EnableRealTimeProtection": boolean, - //"Antimalware/RunScheduledScan": boolean, - //"Antimalware/ScanType": string ("Quick", "Full"), - //"Antimalware/ScanDay": int (0-8) Ex: 0 - daily, 1 - Sunday, 2 - Monday, .... 7 - Saturday, 8 - Disabled, - //"Antimalware/ScanTimeInMinutes": int (0 - 1440), - //"Antimalware/Exclusions/Extensions": string (extensions separated by semicolon. Ex: ".ext1;.ext2"), - //"Antimalware/Exclusions/Paths": string (Paths separated by semicolon. Ex: "c:\excluded-path-1;c:\excluded-path-2"), - //"Antimalware/Exclusions/Processes": string (Processes separated by semicolon. Ex: "proc1.exe;proc2.exe"), + // "Antimalware/Enable": boolean, + // "Antimalware/EnableRealTimeProtection": boolean, + // "Antimalware/RunScheduledScan": boolean, + // "Antimalware/ScanType": string ("Quick", "Full"), + // "Antimalware/ScanDay": int (0-8) Ex: 0 - daily, 1 - Sunday, 2 - Monday, .... 7 - Saturday, 8 - Disabled, + // "Antimalware/ScanTimeInMinutes": int (0 - 1440), + // "Antimalware/Exclusions/Extensions": string (extensions separated by semicolon. Ex: ".ext1;.ext2"), + // "Antimalware/Exclusions/Paths": string (Paths separated by semicolon. Ex: "c:\excluded-path-1;c:\excluded-path-2"), + // "Antimalware/Exclusions/Processes": string (Processes separated by semicolon. Ex: "proc1.exe;proc2.exe"), "antimalware": { Type: pluginsdk.TypeList, Optional: true, @@ -155,14 +155,14 @@ func (r AutoManageConfigurationResource) Arguments() map[string]*pluginsdk.Schem }, }, - //"AutomationAccount/Enable": boolean, + // "AutomationAccount/Enable": boolean, "automation_account_enabled": { Type: pluginsdk.TypeBool, Optional: true, Default: false, }, - //"BootDiagnostics/Enable": boolean, + // "BootDiagnostics/Enable": boolean, "boot_diagnostics_enabled": { Type: pluginsdk.TypeBool, Optional: true, @@ -175,14 +175,14 @@ func (r AutoManageConfigurationResource) Arguments() map[string]*pluginsdk.Schem Optional: true, Default: false, }, - //"GuestConfiguration/Enable": boolean, + // "GuestConfiguration/Enable": boolean, "guest_configuration_enabled": { Type: pluginsdk.TypeBool, Optional: true, Default: false, }, - //"Alerts/AutomanageStatusChanges/Enable": boolean, + // "Alerts/AutomanageStatusChanges/Enable": boolean, "status_change_alert_enabled": { Type: pluginsdk.TypeBool, Optional: true, diff --git a/internal/services/automanage/automanage_configuration_resource_test.go b/internal/services/automanage/automanage_configuration_resource_test.go index c2da1e562a31..988868be3f74 100644 --- a/internal/services/automanage/automanage_configuration_resource_test.go +++ b/internal/services/automanage/automanage_configuration_resource_test.go @@ -155,10 +155,10 @@ resource "azurerm_automanage_configuration" "test" { resource_group_name = azurerm_resource_group.test.name location = "%s" antimalware { - enabled = true - exclusions { + enabled = true + exclusions { extensions = "exe;dll" - } + } real_time_protection_enabled = true } automation_account_enabled = true @@ -176,10 +176,10 @@ resource "azurerm_automanage_configuration" "import" { resource_group_name = azurerm_resource_group.test.name location = "%s" antimalware { - enabled = true - exclusions { + enabled = true + exclusions { extensions = "exe;dll" - } + } real_time_protection_enabled = true } automation_account_enabled = true @@ -197,25 +197,25 @@ resource "azurerm_automanage_configuration" "test" { resource_group_name = azurerm_resource_group.test.name location = "%s" antimalware { - enabled = true - exclusions { + enabled = true + exclusions { extensions = "exe;dll" - paths = "C:\\Windows\\Temp;D:\\Temp" - processes = "svchost.exe;notepad.exe" - } - real_time_protection_enabled = true - scheduled_scan_enabled = true - scheduled_scan_type = "Quick" - scheduled_scan_day = 1 - scheduled_scan_time_in_minutes = 1339 + paths = "C:\\Windows\\Temp;D:\\Temp" + processes = "svchost.exe;notepad.exe" + } + real_time_protection_enabled = true + scheduled_scan_enabled = true + scheduled_scan_type = "Quick" + scheduled_scan_day = 1 + scheduled_scan_time_in_minutes = 1339 } - automation_account_enabled = true - boot_diagnostics_enabled = true - defender_for_cloud_enabled = true + automation_account_enabled = true + boot_diagnostics_enabled = true + defender_for_cloud_enabled = true guest_configuration_enabled = true status_change_alert_enabled = true tags = { - "env" = "test" + "env" = "test" } } `, template, data.RandomInteger, data.Locations.Primary) @@ -231,19 +231,19 @@ resource "azurerm_automanage_configuration" "test" { resource_group_name = azurerm_resource_group.test.name location = "%s" antimalware { - enabled = true - exclusions { + enabled = true + exclusions { extensions = "exe" - processes = "svchost.exe" - } - real_time_protection_enabled = false - scheduled_scan_enabled = true - scheduled_scan_type = "Full" - scheduled_scan_day = 2 - scheduled_scan_time_in_minutes = 1338 + processes = "svchost.exe" + } + real_time_protection_enabled = false + scheduled_scan_enabled = true + scheduled_scan_type = "Full" + scheduled_scan_day = 2 + scheduled_scan_time_in_minutes = 1338 } tags = { - "env2" = "test2" + "env2" = "test2" } } `, template, data.RandomInteger, data.Locations.Primary) From a12b414f6c91c3f27001d8d4ca052bd7c6891281 Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Fri, 21 Apr 2023 08:57:25 +0800 Subject: [PATCH 22/27] update lint --- .../r/automanage_configuration.html.markdown | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/website/docs/r/automanage_configuration.html.markdown b/website/docs/r/automanage_configuration.html.markdown index f8915d3bee9f..2fda7d12ea50 100644 --- a/website/docs/r/automanage_configuration.html.markdown +++ b/website/docs/r/automanage_configuration.html.markdown @@ -22,31 +22,31 @@ resource "azurerm_automanage_configuration" "example" { name = "example-acmp" resource_group_name = azurerm_resource_group.example.name location = azurerm_resource_group.example.location - + antimalware { enabled = true - + exclusions { extensions = "exe;dll" - paths = "C:\\Windows\\Temp;D:\\Temp" - processes = "svchost.exe;notepad.exe" + paths = "C:\\Windows\\Temp;D:\\Temp" + processes = "svchost.exe;notepad.exe" } - + real_time_protection_enabled = true scheduled_scan_enabled = true scheduled_scan_type = "Quick" scheduled_scan_day = 1 scheduled_scan_time_in_minutes = 1339 } - - automation_account_enabled = true - boot_diagnostics_enabled = true - defender_for_cloud_enabled = true + + automation_account_enabled = true + boot_diagnostics_enabled = true + defender_for_cloud_enabled = true guest_configuration_enabled = true status_change_alert_enabled = true - + tags = { - "env" = "test" + "env" = "test" } } ``` From 7c868ae14d829877bf37c67ce56ad9169b2eca10 Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Thu, 25 May 2023 18:08:02 +0800 Subject: [PATCH 23/27] update modules.txt --- vendor/modules.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/modules.txt b/vendor/modules.txt index 270672300dfc..2f643c5d7748 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -825,8 +825,8 @@ github.com/tombuildsstuff/giovanni/version ## explicit; go 1.18 github.com/tombuildsstuff/kermit/sdk/appconfiguration/1.0/appconfiguration github.com/tombuildsstuff/kermit/sdk/appplatform/2022-11-01-preview/appplatform -github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage github.com/tombuildsstuff/kermit/sdk/attestation/2022-08-01/attestation +github.com/tombuildsstuff/kermit/sdk/automanage/2022-05-04/automanage github.com/tombuildsstuff/kermit/sdk/batch/2022-01.15.0/batch github.com/tombuildsstuff/kermit/sdk/botservice/2021-05-01-preview/botservice github.com/tombuildsstuff/kermit/sdk/compute/2022-08-01/compute From 10d849a5b947207fca5c8f1ca7f40174c97659cb Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Thu, 25 May 2023 19:52:05 +0800 Subject: [PATCH 24/27] update generated files --- internal/services/automanage/parse/automanage_configuration.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/automanage/parse/automanage_configuration.go b/internal/services/automanage/parse/automanage_configuration.go index 10c9d0b44fde..cc3d629d2182 100644 --- a/internal/services/automanage/parse/automanage_configuration.go +++ b/internal/services/automanage/parse/automanage_configuration.go @@ -41,7 +41,7 @@ func (id AutomanageConfigurationId) ID() string { func AutomanageConfigurationID(input string) (*AutomanageConfigurationId, error) { id, err := resourceids.ParseAzureResourceID(input) if err != nil { - return nil, err + return nil, fmt.Errorf("parsing %q as an AutomanageConfiguration ID: %+v", input, err) } resourceId := AutomanageConfigurationId{ From f73f1cfab4b484f1f8d342207591cb5aef6d4803 Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Wed, 31 May 2023 14:56:22 +0800 Subject: [PATCH 25/27] remove enable property --- .../automanage_configuration_resource.go | 16 +++------------- .../automanage_configuration_resource_test.go | 7 ------- .../r/automanage_configuration.html.markdown | 4 ---- 3 files changed, 3 insertions(+), 24 deletions(-) diff --git a/internal/services/automanage/automanage_configuration_resource.go b/internal/services/automanage/automanage_configuration_resource.go index 53cbc12cee89..b4409a8fdc81 100644 --- a/internal/services/automanage/automanage_configuration_resource.go +++ b/internal/services/automanage/automanage_configuration_resource.go @@ -33,7 +33,6 @@ type ConfigurationModel struct { } type AntimalwareConfiguration struct { - Enabled bool `tfschema:"enabled"` Exclusions []AntimalwareExclusions `tfschema:"exclusions"` RealTimeProtectionEnabled bool `tfschema:"real_time_protection_enabled"` ScheduledScanEnabled bool `tfschema:"scheduled_scan_enabled"` @@ -77,7 +76,7 @@ func (r AutoManageConfigurationResource) Arguments() map[string]*pluginsdk.Schem "location": commonschema.Location(), - // "Antimalware/Enable": boolean, + // "Antimalware/Enable": boolean, true if block exists // "Antimalware/EnableRealTimeProtection": boolean, // "Antimalware/RunScheduledScan": boolean, // "Antimalware/ScanType": string ("Quick", "Full"), @@ -92,11 +91,6 @@ func (r AutoManageConfigurationResource) Arguments() map[string]*pluginsdk.Schem MaxItems: 1, Elem: &pluginsdk.Resource{ Schema: map[string]*pluginsdk.Schema{ - "enabled": { - Type: pluginsdk.TypeBool, - Optional: true, - Default: false, - }, "real_time_protection_enabled": { Type: pluginsdk.TypeBool, Optional: true, @@ -229,7 +223,7 @@ func (r AutoManageConfigurationResource) Create() sdk.ResourceFunc { if model.Antimalware != nil && len(model.Antimalware) > 0 { antimalwareConfig := model.Antimalware[0] - jsonConfig["Antimalware/Enable"] = antimalwareConfig.Enabled + jsonConfig["Antimalware/Enable"] = true jsonConfig["Antimalware/EnableRealTimeProtection"] = antimalwareConfig.RealTimeProtectionEnabled jsonConfig["Antimalware/RunScheduledScan"] = antimalwareConfig.ScheduledScanEnabled jsonConfig["Antimalware/ScanType"] = antimalwareConfig.ScanType @@ -303,7 +297,7 @@ func (r AutoManageConfigurationResource) Update() sdk.ResourceFunc { if model.Antimalware != nil { antimalwareConfig := model.Antimalware[0] - jsonConfig["Antimalware/Enable"] = antimalwareConfig.Enabled + jsonConfig["Antimalware/Enable"] = true jsonConfig["Antimalware/EnableRealTimeProtection"] = antimalwareConfig.RealTimeProtectionEnabled jsonConfig["Antimalware/RunScheduledScan"] = antimalwareConfig.ScheduledScanEnabled jsonConfig["Antimalware/ScanType"] = antimalwareConfig.ScanType @@ -446,10 +440,6 @@ func flattenAntimarewareConfig(configMap map[string]interface{}) []AntimalwareCo antimalware[0] = AntimalwareConfiguration{} antimalware[0].Exclusions = make([]AntimalwareExclusions, 1) - if val, ok := configMap["Antimalware/Enable"]; ok { - antimalware[0].Enabled = val.(bool) - } - if val, ok := configMap["Antimalware/EnableRealTimeProtection"]; ok { antimalware[0].RealTimeProtectionEnabled = val.(bool) } diff --git a/internal/services/automanage/automanage_configuration_resource_test.go b/internal/services/automanage/automanage_configuration_resource_test.go index 988868be3f74..d8f92c342c48 100644 --- a/internal/services/automanage/automanage_configuration_resource_test.go +++ b/internal/services/automanage/automanage_configuration_resource_test.go @@ -25,7 +25,6 @@ func TestAccAutoManageConfigurationProfile_basic(t *testing.T) { Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("antimalware.#").HasValue("1"), - check.That(data.ResourceName).Key("antimalware.0.enabled").HasValue("true"), check.That(data.ResourceName).Key("antimalware.0.exclusions.#").HasValue("1"), check.That(data.ResourceName).Key("antimalware.0.exclusions.0.extensions").HasValue("exe;dll"), check.That(data.ResourceName).Key("antimalware.0.real_time_protection_enabled").HasValue("true"), @@ -59,7 +58,6 @@ func TestAccAutoManageConfigurationProfile_complete(t *testing.T) { Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("antimalware.#").HasValue("1"), - check.That(data.ResourceName).Key("antimalware.0.enabled").HasValue("true"), check.That(data.ResourceName).Key("antimalware.0.exclusions.#").HasValue("1"), check.That(data.ResourceName).Key("antimalware.0.exclusions.0.extensions").HasValue("exe;dll"), check.That(data.ResourceName).Key("antimalware.0.exclusions.0.processes").HasValue("svchost.exe;notepad.exe"), @@ -95,7 +93,6 @@ func TestAccAutoManageConfigurationProfile_update(t *testing.T) { Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("antimalware.#").HasValue("1"), - check.That(data.ResourceName).Key("antimalware.0.enabled").HasValue("true"), check.That(data.ResourceName).Key("antimalware.0.exclusions.#").HasValue("1"), check.That(data.ResourceName).Key("antimalware.0.exclusions.0.extensions").HasValue("exe"), check.That(data.ResourceName).Key("antimalware.0.exclusions.0.processes").HasValue("svchost.exe"), @@ -155,7 +152,6 @@ resource "azurerm_automanage_configuration" "test" { resource_group_name = azurerm_resource_group.test.name location = "%s" antimalware { - enabled = true exclusions { extensions = "exe;dll" } @@ -176,7 +172,6 @@ resource "azurerm_automanage_configuration" "import" { resource_group_name = azurerm_resource_group.test.name location = "%s" antimalware { - enabled = true exclusions { extensions = "exe;dll" } @@ -197,7 +192,6 @@ resource "azurerm_automanage_configuration" "test" { resource_group_name = azurerm_resource_group.test.name location = "%s" antimalware { - enabled = true exclusions { extensions = "exe;dll" paths = "C:\\Windows\\Temp;D:\\Temp" @@ -231,7 +225,6 @@ resource "azurerm_automanage_configuration" "test" { resource_group_name = azurerm_resource_group.test.name location = "%s" antimalware { - enabled = true exclusions { extensions = "exe" processes = "svchost.exe" diff --git a/website/docs/r/automanage_configuration.html.markdown b/website/docs/r/automanage_configuration.html.markdown index 2fda7d12ea50..1596d2ec052a 100644 --- a/website/docs/r/automanage_configuration.html.markdown +++ b/website/docs/r/automanage_configuration.html.markdown @@ -24,8 +24,6 @@ resource "azurerm_automanage_configuration" "example" { location = azurerm_resource_group.example.location antimalware { - enabled = true - exclusions { extensions = "exe;dll" paths = "C:\\Windows\\Temp;D:\\Temp" @@ -77,8 +75,6 @@ The following arguments are supported: * `antimalware` supports the following: -* `enabled` - (Required) Whether the antimalware is enabled. Defaults to `false`. - * `exclusions` - (Optional) A `exclusions` block as defined below. * `real_time_protection_enabled` - (Optional) Whether the real time protection is enabled. Defaults to `false`. From 2e818fde0b399b9cc59cbca460fb4ab049091a17 Mon Sep 17 00:00:00 2001 From: Yun Liu Date: Thu, 1 Jun 2023 11:24:35 +0800 Subject: [PATCH 26/27] add accTest and refine update logic --- .../automanage_configuration_resource.go | 13 +++--- .../automanage_configuration_resource_test.go | 45 +++++++++++++++---- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/internal/services/automanage/automanage_configuration_resource.go b/internal/services/automanage/automanage_configuration_resource.go index b4409a8fdc81..becc10581f44 100644 --- a/internal/services/automanage/automanage_configuration_resource.go +++ b/internal/services/automanage/automanage_configuration_resource.go @@ -291,11 +291,7 @@ func (r AutoManageConfigurationResource) Update() sdk.ResourceFunc { jsonConfig := make(map[string]interface{}) - if resp.Properties != nil && resp.Properties.Configuration != nil { - jsonConfig = resp.Properties.Configuration.(map[string]interface{}) - } - - if model.Antimalware != nil { + if model.Antimalware != nil && len(model.Antimalware) > 0 { antimalwareConfig := model.Antimalware[0] jsonConfig["Antimalware/Enable"] = true jsonConfig["Antimalware/EnableRealTimeProtection"] = antimalwareConfig.RealTimeProtectionEnabled @@ -379,9 +375,6 @@ func (r AutoManageConfigurationResource) Read() sdk.ResourceFunc { if resp.Properties != nil && resp.Properties.Configuration != nil { configMap := resp.Properties.Configuration.(map[string]interface{}) - if err != nil { - return fmt.Errorf("unmarshalling %s: %+v", *id, err) - } state.Antimalware = flattenAntimarewareConfig(configMap) @@ -436,6 +429,10 @@ func (r AutoManageConfigurationResource) Delete() sdk.ResourceFunc { } func flattenAntimarewareConfig(configMap map[string]interface{}) []AntimalwareConfiguration { + if val, ok := configMap["Antimalware/Enable"]; !ok || (val == nil) { + return nil + } + antimalware := make([]AntimalwareConfiguration, 1) antimalware[0] = AntimalwareConfiguration{} antimalware[0].Exclusions = make([]AntimalwareExclusions, 1) diff --git a/internal/services/automanage/automanage_configuration_resource_test.go b/internal/services/automanage/automanage_configuration_resource_test.go index d8f92c342c48..c61ed5f47312 100644 --- a/internal/services/automanage/automanage_configuration_resource_test.go +++ b/internal/services/automanage/automanage_configuration_resource_test.go @@ -22,6 +22,20 @@ func TestAccAutoManageConfigurationProfile_basic(t *testing.T) { data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccAutoManageConfigurationProfile_antimalware(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_automanage_configuration", "test") + r := AutoManageConfigurationProfileResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.antimalware(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("antimalware.#").HasValue("1"), @@ -32,6 +46,15 @@ func TestAccAutoManageConfigurationProfile_basic(t *testing.T) { ), }, data.ImportStep(), + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("antimalware.#").HasValue("0"), + check.That(data.ResourceName).Key("automation_account_enabled").HasValue("false"), + ), + }, + data.ImportStep(), }) } @@ -147,6 +170,19 @@ func (r AutoManageConfigurationProfileResource) basic(data acceptance.TestData) return fmt.Sprintf(` %s +resource "azurerm_automanage_configuration" "test" { + name = "acctest-amcp-%d" + resource_group_name = azurerm_resource_group.test.name + location = "%s" +} +`, template, data.RandomInteger, data.Locations.Primary) +} + +func (r AutoManageConfigurationProfileResource) antimalware(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` + %s + resource "azurerm_automanage_configuration" "test" { name = "acctest-amcp-%d" resource_group_name = azurerm_resource_group.test.name @@ -163,7 +199,7 @@ resource "azurerm_automanage_configuration" "test" { } func (r AutoManageConfigurationProfileResource) requiresImport(data acceptance.TestData) string { - config := r.basic(data) + config := r.antimalware(data) return fmt.Sprintf(` %s @@ -171,13 +207,6 @@ resource "azurerm_automanage_configuration" "import" { name = azurerm_automanage_configuration.test.name resource_group_name = azurerm_resource_group.test.name location = "%s" - antimalware { - exclusions { - extensions = "exe;dll" - } - real_time_protection_enabled = true - } - automation_account_enabled = true } `, config, data.Locations.Primary) } From cf9e33565f4a00987e803a1ca2167e2ebdedcee8 Mon Sep 17 00:00:00 2001 From: stephybun Date: Thu, 1 Jun 2023 11:09:30 +0200 Subject: [PATCH 27/27] fix naming and casing of resource in docs --- .../r/automanage_configuration.html.markdown | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/website/docs/r/automanage_configuration.html.markdown b/website/docs/r/automanage_configuration.html.markdown index 1596d2ec052a..1473202bc255 100644 --- a/website/docs/r/automanage_configuration.html.markdown +++ b/website/docs/r/automanage_configuration.html.markdown @@ -3,12 +3,12 @@ subcategory: "Automanage" layout: "azurerm" page_title: "Azure Resource Manager: azurerm_automanage_configuration" description: |- - Manages a automanage ConfigurationProfile. + Manages an Automanage Configuration. --- # azurerm_automanage_configuration -Manages a automanage ConfigurationProfile. +Manages an Automanage Configuration. ## Example Usage @@ -53,17 +53,17 @@ resource "azurerm_automanage_configuration" "example" { The following arguments are supported: -* `name` - (Required) The name which should be used for this automanage ConfigurationProfile. Changing this forces a new automanage ConfigurationProfile to be created. +* `name` - (Required) The name which should be used for this Automanage Configuration. Changing this forces a new Automanage Configuration to be created. -* `resource_group_name` - (Required) The name of the Resource Group where the automanage ConfigurationProfile should exist. Changing this forces a new automanage ConfigurationProfile to be created. +* `resource_group_name` - (Required) The name of the Resource Group where the Automanage Configuration should exist. Changing this forces a new Automanage Configuration to be created. -* `location` - (Required) The Azure Region where the automanage ConfigurationProfile should exist. Changing this forces a new automanage ConfigurationProfile to be created. +* `location` - (Required) The Azure Region where the Automanage Configuration should exist. Changing this forces a new Automanage Configuration to be created. * `antimalware` - (Optional) A `antimalware` block as defined below. * `automation_account_enabled` - (Optional) Whether the automation account is enabled. Defaults to `false`. -* `boot_diagnostics_enabled` - (Optional) Whether the boot diagnostics is enabled. Defaults to `false`. +* `boot_diagnostics_enabled` - (Optional) Whether the boot diagnostics are enabled. Defaults to `false`. * `defender_for_cloud_enabled` - (Optional) Whether the defender for cloud is enabled. Defaults to `false`. @@ -97,13 +97,13 @@ The following arguments are supported: * `processes` - (Optional) The processes to exclude from the antimalware scan, separated by `;`. For example `svchost.exe;notepad.exe`. -* `tags` - (Optional) A mapping of tags which should be assigned to the automanage ConfigurationProfile. +* `tags` - (Optional) A mapping of tags which should be assigned to the Automanage Configuration. ## Attributes Reference In addition to the Arguments listed above - the following Attributes are exported: -* `id` - The ID of the automanage ConfigurationProfile. +* `id` - The ID of the Automanage Configuration. * `type` - The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts". @@ -111,14 +111,14 @@ In addition to the Arguments listed above - the following Attributes are exporte The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: -* `create` - (Defaults to 30 minutes) Used when creating the automanage ConfigurationProfile. -* `read` - (Defaults to 5 minutes) Used when retrieving the automanage ConfigurationProfile. -* `update` - (Defaults to 30 minutes) Used when updating the automanage ConfigurationProfile. -* `delete` - (Defaults to 30 minutes) Used when deleting the automanage ConfigurationProfile. +* `create` - (Defaults to 30 minutes) Used when creating the Automanage Configuration. +* `read` - (Defaults to 5 minutes) Used when retrieving the Automanage Configuration. +* `update` - (Defaults to 30 minutes) Used when updating the Automanage Configuration. +* `delete` - (Defaults to 30 minutes) Used when deleting the Automanage Configuration. ## Import -automanage ConfigurationProfiles can be imported using the `resource id`, e.g. +Automanage Configuration can be imported using the `resource id`, e.g. ```shell terraform import azurerm_automanage_configuration.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Automanage/configurationProfiles/configurationProfile1