From b7f0835d9e456a17099e4fbafb4da6e540cb865d Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Mon, 27 Jun 2022 14:06:37 +0800 Subject: [PATCH 1/4] New Resource: azurerm_log_analytics_query_pack --- internal/provider/services.go | 1 + .../services/loganalytics/client/client.go | 6 + .../log_analytics_query_pack_resource.go | 198 ++++++++++++++++ .../log_analytics_query_pack_resource_test.go | 138 +++++++++++ .../services/loganalytics/registration.go | 15 +- .../services/privatedns/parse/a_record.go | 75 ++++++ .../privatedns/parse/a_record_test.go | 128 ++++++++++ .../services/privatedns/parse/aaaa_record.go | 75 ++++++ .../privatedns/parse/aaaa_record_test.go | 128 ++++++++++ .../services/privatedns/parse/cname_record.go | 75 ++++++ .../privatedns/parse/cname_record_test.go | 128 ++++++++++ .../services/privatedns/parse/mx_record.go | 75 ++++++ .../privatedns/parse/mx_record_test.go | 128 ++++++++++ .../privatedns/parse/private_dns_zone.go | 69 ++++++ .../privatedns/parse/private_dns_zone_test.go | 112 +++++++++ .../services/privatedns/parse/ptr_record.go | 75 ++++++ .../privatedns/parse/ptr_record_test.go | 128 ++++++++++ .../services/privatedns/parse/srv_record.go | 75 ++++++ .../privatedns/parse/srv_record_test.go | 128 ++++++++++ .../services/privatedns/parse/txt_record.go | 75 ++++++ .../privatedns/parse/txt_record_test.go | 128 ++++++++++ .../privatedns/parse/virtual_network_link.go | 75 ++++++ .../parse/virtual_network_link_test.go | 128 ++++++++++ .../privatedns/validate/a_record_id.go | 23 ++ .../privatedns/validate/a_record_id_test.go | 88 +++++++ .../privatedns/validate/aaaa_record_id.go | 23 ++ .../validate/aaaa_record_id_test.go | 88 +++++++ .../privatedns/validate/cname_record_id.go | 23 ++ .../validate/cname_record_id_test.go | 88 +++++++ .../privatedns/validate/mx_record_id.go | 23 ++ .../privatedns/validate/mx_record_id_test.go | 88 +++++++ .../validate/private_dns_zone_id.go | 23 ++ .../validate/private_dns_zone_id_test.go | 76 ++++++ .../privatedns/validate/ptr_record_id.go | 23 ++ .../privatedns/validate/ptr_record_id_test.go | 88 +++++++ .../privatedns/validate/srv_record_id.go | 23 ++ .../privatedns/validate/srv_record_id_test.go | 88 +++++++ .../privatedns/validate/txt_record_id.go | 23 ++ .../privatedns/validate/txt_record_id_test.go | 88 +++++++ .../validate/virtual_network_link_id.go | 23 ++ .../validate/virtual_network_link_id_test.go | 88 +++++++ .../2019-09-01/operationalinsights/client.go | 18 ++ .../operationalinsights/id_queries.go | 137 +++++++++++ .../operationalinsights/id_querypack.go | 124 ++++++++++ .../method_queriesdelete_autorest.go | 65 ++++++ .../method_queriesget_autorest.go | 67 ++++++ .../method_querieslist_autorest.go | 220 +++++++++++++++++ .../method_queriesput_autorest.go | 68 ++++++ .../method_queriessearch_autorest.go | 221 ++++++++++++++++++ .../method_queriesupdate_autorest.go | 68 ++++++ ...ethod_querypackscreateorupdate_autorest.go | 68 ++++++ .../method_querypacksdelete_autorest.go | 65 ++++++ .../method_querypacksget_autorest.go | 67 ++++++ .../method_querypackslist_autorest.go | 187 +++++++++++++++ ..._querypackslistbyresourcegroup_autorest.go | 187 +++++++++++++++ .../method_querypacksupdatetags_autorest.go | 68 ++++++ .../model_loganalyticsquerypack.go | 13 ++ .../model_loganalyticsquerypackproperties.go | 41 ++++ .../model_loganalyticsquerypackquery.go | 16 ++ ...el_loganalyticsquerypackqueryproperties.go | 47 ++++ ...nalyticsquerypackquerypropertiesrelated.go | 10 + ...analyticsquerypackquerysearchproperties.go | 9 + ...csquerypackquerysearchpropertiesrelated.go | 10 + .../operationalinsights/model_tagsresource.go | 8 + .../operationalinsights/predicates.go | 52 +++++ .../2019-09-01/operationalinsights/version.go | 12 + vendor/modules.txt | 1 + .../r/log_analytics_query_pack.html.markdown | 63 +++++ 68 files changed, 5061 insertions(+), 1 deletion(-) create mode 100644 internal/services/loganalytics/log_analytics_query_pack_resource.go create mode 100644 internal/services/loganalytics/log_analytics_query_pack_resource_test.go create mode 100644 internal/services/privatedns/parse/a_record.go create mode 100644 internal/services/privatedns/parse/a_record_test.go create mode 100644 internal/services/privatedns/parse/aaaa_record.go create mode 100644 internal/services/privatedns/parse/aaaa_record_test.go create mode 100644 internal/services/privatedns/parse/cname_record.go create mode 100644 internal/services/privatedns/parse/cname_record_test.go create mode 100644 internal/services/privatedns/parse/mx_record.go create mode 100644 internal/services/privatedns/parse/mx_record_test.go create mode 100644 internal/services/privatedns/parse/private_dns_zone.go create mode 100644 internal/services/privatedns/parse/private_dns_zone_test.go create mode 100644 internal/services/privatedns/parse/ptr_record.go create mode 100644 internal/services/privatedns/parse/ptr_record_test.go create mode 100644 internal/services/privatedns/parse/srv_record.go create mode 100644 internal/services/privatedns/parse/srv_record_test.go create mode 100644 internal/services/privatedns/parse/txt_record.go create mode 100644 internal/services/privatedns/parse/txt_record_test.go create mode 100644 internal/services/privatedns/parse/virtual_network_link.go create mode 100644 internal/services/privatedns/parse/virtual_network_link_test.go create mode 100644 internal/services/privatedns/validate/a_record_id.go create mode 100644 internal/services/privatedns/validate/a_record_id_test.go create mode 100644 internal/services/privatedns/validate/aaaa_record_id.go create mode 100644 internal/services/privatedns/validate/aaaa_record_id_test.go create mode 100644 internal/services/privatedns/validate/cname_record_id.go create mode 100644 internal/services/privatedns/validate/cname_record_id_test.go create mode 100644 internal/services/privatedns/validate/mx_record_id.go create mode 100644 internal/services/privatedns/validate/mx_record_id_test.go create mode 100644 internal/services/privatedns/validate/private_dns_zone_id.go create mode 100644 internal/services/privatedns/validate/private_dns_zone_id_test.go create mode 100644 internal/services/privatedns/validate/ptr_record_id.go create mode 100644 internal/services/privatedns/validate/ptr_record_id_test.go create mode 100644 internal/services/privatedns/validate/srv_record_id.go create mode 100644 internal/services/privatedns/validate/srv_record_id_test.go create mode 100644 internal/services/privatedns/validate/txt_record_id.go create mode 100644 internal/services/privatedns/validate/txt_record_id_test.go create mode 100644 internal/services/privatedns/validate/virtual_network_link_id.go create mode 100644 internal/services/privatedns/validate/virtual_network_link_id_test.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/client.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/id_queries.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/id_querypack.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_queriesdelete_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_queriesget_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querieslist_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_queriesput_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_queriessearch_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_queriesupdate_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querypackscreateorupdate_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querypacksdelete_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querypacksget_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querypackslist_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querypackslistbyresourcegroup_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querypacksupdatetags_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypack.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypackproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypackquery.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypackqueryproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypackquerypropertiesrelated.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypackquerysearchproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypackquerysearchpropertiesrelated.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_tagsresource.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/predicates.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/version.go create mode 100644 website/docs/r/log_analytics_query_pack.html.markdown diff --git a/internal/provider/services.go b/internal/provider/services.go index ca6cd4ec3882..25418d698727 100644 --- a/internal/provider/services.go +++ b/internal/provider/services.go @@ -124,6 +124,7 @@ func SupportedTypedServices() []sdk.TypedServiceRegistration { keyvault.Registration{}, loadbalancer.Registration{}, loadtest.Registration{}, + loganalytics.Registration{}, mssql.Registration{}, policy.Registration{}, resource.Registration{}, diff --git a/internal/services/loganalytics/client/client.go b/internal/services/loganalytics/client/client.go index 844608189cd9..ba0162e3098f 100644 --- a/internal/services/loganalytics/client/client.go +++ b/internal/services/loganalytics/client/client.go @@ -3,6 +3,7 @@ package client import ( "github.com/Azure/azure-sdk-for-go/services/operationalinsights/mgmt/2020-08-01/operationalinsights" "github.com/Azure/azure-sdk-for-go/services/preview/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement" + queryPacks "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights" "github.com/hashicorp/terraform-provider-azurerm/internal/common" ) @@ -12,6 +13,7 @@ type Client struct { DataSourcesClient *operationalinsights.DataSourcesClient LinkedServicesClient *operationalinsights.LinkedServicesClient LinkedStorageAccountClient *operationalinsights.LinkedStorageAccountsClient + QueryPacksClient *queryPacks.OperationalInsightsClient SavedSearchesClient *operationalinsights.SavedSearchesClient SharedKeysClient *operationalinsights.SharedKeysClient SolutionsClient *operationsmanagement.SolutionsClient @@ -50,12 +52,16 @@ func NewClient(o *common.ClientOptions) *Client { LinkedStorageAccountClient := operationalinsights.NewLinkedStorageAccountsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&LinkedStorageAccountClient.Client, o.ResourceManagerAuthorizer) + QueryPacksClient := queryPacks.NewOperationalInsightsClientWithBaseURI(o.ResourceManagerEndpoint) + o.ConfigureClient(&QueryPacksClient.Client, o.ResourceManagerAuthorizer) + return &Client{ ClusterClient: &ClusterClient, DataExportClient: &DataExportClient, DataSourcesClient: &DataSourcesClient, LinkedServicesClient: &LinkedServicesClient, LinkedStorageAccountClient: &LinkedStorageAccountClient, + QueryPacksClient: &QueryPacksClient, SavedSearchesClient: &SavedSearchesClient, SharedKeysClient: &SharedKeysClient, SolutionsClient: &SolutionsClient, diff --git a/internal/services/loganalytics/log_analytics_query_pack_resource.go b/internal/services/loganalytics/log_analytics_query_pack_resource.go new file mode 100644 index 000000000000..faeb9628b672 --- /dev/null +++ b/internal/services/loganalytics/log_analytics_query_pack_resource.go @@ -0,0 +1,198 @@ +package loganalytics + +import ( + "context" + "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" + queryPacks "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights" + "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" + "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" +) + +type LogAnalyticsQueryPackModel struct { + Name string `tfschema:"name"` + ResourceGroupName string `tfschema:"resource_group_name"` + Location string `tfschema:"location"` + Tags map[string]string `tfschema:"tags"` +} + +type LogAnalyticsQueryPackResource struct{} + +var _ sdk.ResourceWithUpdate = LogAnalyticsQueryPackResource{} + +func (r LogAnalyticsQueryPackResource) ResourceType() string { + return "azurerm_log_analytics_query_pack" +} + +func (r LogAnalyticsQueryPackResource) ModelObject() interface{} { + return &LogAnalyticsQueryPackModel{} +} + +func (r LogAnalyticsQueryPackResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { + return queryPacks.ValidateQueryPackID +} + +func (r LogAnalyticsQueryPackResource) 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(), + + "tags": commonschema.Tags(), + } +} + +func (r LogAnalyticsQueryPackResource) Attributes() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{} +} + +func (r LogAnalyticsQueryPackResource) Create() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + var model LogAnalyticsQueryPackModel + if err := metadata.Decode(&model); err != nil { + return fmt.Errorf("decoding: %+v", err) + } + + client := metadata.Client.LogAnalytics.QueryPacksClient + subscriptionId := metadata.Client.Account.SubscriptionId + + id := queryPacks.NewQueryPackID(subscriptionId, model.ResourceGroupName, model.Name) + + existing, err := client.QueryPacksGet(ctx, id) + if err != nil && !response.WasNotFound(existing.HttpResponse) { + return fmt.Errorf("checking for existing %s: %+v", id, err) + } + + if !response.WasNotFound(existing.HttpResponse) { + return metadata.ResourceRequiresImport(r.ResourceType(), id) + } + + properties := &queryPacks.LogAnalyticsQueryPack{ + Location: location.Normalize(model.Location), + Properties: queryPacks.LogAnalyticsQueryPackProperties{}, + Tags: &model.Tags, + } + + if _, err := client.QueryPacksCreateOrUpdate(ctx, id, *properties); err != nil { + return fmt.Errorf("creating %s: %+v", id, err) + } + + metadata.SetID(id) + return nil + }, + } +} + +func (r LogAnalyticsQueryPackResource) Update() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.LogAnalytics.QueryPacksClient + + id, err := queryPacks.ParseQueryPackID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + var model LogAnalyticsQueryPackModel + if err := metadata.Decode(&model); err != nil { + return fmt.Errorf("decoding: %+v", err) + } + + resp, err := client.QueryPacksGet(ctx, *id) + if err != nil { + return fmt.Errorf("retrieving %s: %+v", *id, err) + } + + properties := resp.Model + if properties == nil { + return fmt.Errorf("retrieving %s: properties was nil", id) + } + + if metadata.ResourceData.HasChange("tags") { + properties.Tags = &model.Tags + } + + if _, err := client.QueryPacksCreateOrUpdate(ctx, *id, *properties); err != nil { + return fmt.Errorf("updating %s: %+v", *id, err) + } + + return nil + }, + } +} + +func (r LogAnalyticsQueryPackResource) Read() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 5 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.LogAnalytics.QueryPacksClient + + id, err := queryPacks.ParseQueryPackID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + resp, err := client.QueryPacksGet(ctx, *id) + if err != nil { + if response.WasNotFound(resp.HttpResponse) { + return metadata.MarkAsGone(id) + } + + return fmt.Errorf("retrieving %s: %+v", *id, err) + } + + model := resp.Model + if model == nil { + return fmt.Errorf("retrieving %s: model was nil", id) + } + + state := LogAnalyticsQueryPackModel{ + Name: id.QueryPackName, + ResourceGroupName: id.ResourceGroupName, + Location: location.NormalizeNilable(utils.String(model.Location)), + } + + if model.Tags != nil { + state.Tags = *model.Tags + } + + return metadata.Encode(&state) + }, + } +} + +func (r LogAnalyticsQueryPackResource) Delete() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.LogAnalytics.QueryPacksClient + + id, err := queryPacks.ParseQueryPackID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + if _, err := client.QueryPacksDelete(ctx, *id); err != nil { + return fmt.Errorf("deleting %s: %+v", id, err) + } + + return nil + }, + } +} diff --git a/internal/services/loganalytics/log_analytics_query_pack_resource_test.go b/internal/services/loganalytics/log_analytics_query_pack_resource_test.go new file mode 100644 index 000000000000..c6605715fdd8 --- /dev/null +++ b/internal/services/loganalytics/log_analytics_query_pack_resource_test.go @@ -0,0 +1,138 @@ +package loganalytics_test + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/go-azure-helpers/lang/response" + queryPacks "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights" + "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/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +type LogAnalyticsQueryPackResource struct{} + +func (r LogAnalyticsQueryPackResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + id, err := queryPacks.ParseQueryPackID(state.ID) + if err != nil { + return nil, err + } + + resp, err := client.LogAnalytics.QueryPacksClient.QueryPacksGet(ctx, *id) + if err != nil { + if response.WasNotFound(resp.HttpResponse) { + return utils.Bool(false), nil + } + return nil, fmt.Errorf("retrieving %s: %+v", *id, err) + } + return utils.Bool(true), nil +} + +func TestAccLogAnalyticsQueryPack_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_log_analytics_query_pack", "test") + r := LogAnalyticsQueryPackResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccLogAnalyticsQueryPack_requiresImport(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_log_analytics_query_pack", "test") + r := LogAnalyticsQueryPackResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.RequiresImportErrorStep(r.requiresImport), + }) +} + +func TestAccLogAnalyticsQueryPack_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_log_analytics_query_pack", "test") + r := LogAnalyticsQueryPackResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.update(data, "Test1"), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.update(data, "Test2"), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func (r LogAnalyticsQueryPackResource) basic(data acceptance.TestData) string { + return fmt.Sprintf(` +%[1]s + +resource "azurerm_log_analytics_query_pack" "test" { + name = "acctestlaqp-%[2]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location +} +`, r.template(data), data.RandomInteger) +} + +func (r LogAnalyticsQueryPackResource) update(data acceptance.TestData, tag string) string { + return fmt.Sprintf(` +%[1]s + +resource "azurerm_log_analytics_query_pack" "test" { + name = "acctestlaqp-%[2]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + + tags = { + ENV = "%[3]s" + } +} +`, r.template(data), data.RandomInteger, tag) +} + +func (r LogAnalyticsQueryPackResource) requiresImport(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_log_analytics_query_pack" "import" { + name = azurerm_log_analytics_query_pack.test.name + resource_group_name = azurerm_log_analytics_query_pack.test.resource_group_name + location = azurerm_log_analytics_query_pack.test.location +} +`, r.basic(data)) +} + +func (r LogAnalyticsQueryPackResource) template(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-LA-%[1]d" + location = "%[2]s" +} +`, data.RandomInteger, data.Locations.Primary) +} diff --git a/internal/services/loganalytics/registration.go b/internal/services/loganalytics/registration.go index 975f0e46ca66..1161e33c882a 100644 --- a/internal/services/loganalytics/registration.go +++ b/internal/services/loganalytics/registration.go @@ -7,12 +7,25 @@ import ( type Registration struct{} -var _ sdk.UntypedServiceRegistrationWithAGitHubLabel = Registration{} +var ( + _ sdk.TypedServiceRegistration = Registration{} + _ sdk.UntypedServiceRegistrationWithAGitHubLabel = Registration{} +) func (r Registration) AssociatedGitHubLabel() string { return "service/log-analytics" } +func (r Registration) DataSources() []sdk.DataSource { + return []sdk.DataSource{} +} + +func (r Registration) Resources() []sdk.Resource { + return []sdk.Resource{ + LogAnalyticsQueryPackResource{}, + } +} + // Name is the name of this Service func (r Registration) Name() string { return "Log Analytics" diff --git a/internal/services/privatedns/parse/a_record.go b/internal/services/privatedns/parse/a_record.go new file mode 100644 index 000000000000..1ff34aa6ccba --- /dev/null +++ b/internal/services/privatedns/parse/a_record.go @@ -0,0 +1,75 @@ +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 ARecordId struct { + SubscriptionId string + ResourceGroup string + PrivateDnsZoneName string + AName string +} + +func NewARecordID(subscriptionId, resourceGroup, privateDnsZoneName, aName string) ARecordId { + return ARecordId{ + SubscriptionId: subscriptionId, + ResourceGroup: resourceGroup, + PrivateDnsZoneName: privateDnsZoneName, + AName: aName, + } +} + +func (id ARecordId) String() string { + segments := []string{ + fmt.Sprintf("A Name %q", id.AName), + fmt.Sprintf("Private Dns Zone Name %q", id.PrivateDnsZoneName), + fmt.Sprintf("Resource Group %q", id.ResourceGroup), + } + segmentsStr := strings.Join(segments, " / ") + return fmt.Sprintf("%s: (%s)", "A Record", segmentsStr) +} + +func (id ARecordId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/privateDnsZones/%s/A/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.PrivateDnsZoneName, id.AName) +} + +// ARecordID parses a ARecord ID into an ARecordId struct +func ARecordID(input string) (*ARecordId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + resourceId := ARecordId{ + 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.PrivateDnsZoneName, err = id.PopSegment("privateDnsZones"); err != nil { + return nil, err + } + if resourceId.AName, err = id.PopSegment("A"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} diff --git a/internal/services/privatedns/parse/a_record_test.go b/internal/services/privatedns/parse/a_record_test.go new file mode 100644 index 000000000000..4077882d24ab --- /dev/null +++ b/internal/services/privatedns/parse/a_record_test.go @@ -0,0 +1,128 @@ +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 = ARecordId{} + +func TestARecordIDFormatter(t *testing.T) { + actual := NewARecordID("12345678-1234-9876-4563-123456789012", "resGroup1", "privateDnsZone1", "eh1").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/A/eh1" + if actual != expected { + t.Fatalf("Expected %q but got %q", expected, actual) + } +} + +func TestARecordID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ARecordId + }{ + + { + // 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 PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", + Error: true, + }, + + { + // missing value for PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", + Error: true, + }, + + { + // missing AName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", + Error: true, + }, + + { + // missing value for AName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/A/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/A/eh1", + Expected: &ARecordId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + PrivateDnsZoneName: "privateDnsZone1", + AName: "eh1", + }, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/A/EH1", + Error: true, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ARecordID(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.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { + t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) + } + if actual.AName != v.Expected.AName { + t.Fatalf("Expected %q but got %q for AName", v.Expected.AName, actual.AName) + } + } +} diff --git a/internal/services/privatedns/parse/aaaa_record.go b/internal/services/privatedns/parse/aaaa_record.go new file mode 100644 index 000000000000..c44c0d268b87 --- /dev/null +++ b/internal/services/privatedns/parse/aaaa_record.go @@ -0,0 +1,75 @@ +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 AaaaRecordId struct { + SubscriptionId string + ResourceGroup string + PrivateDnsZoneName string + AAAAName string +} + +func NewAaaaRecordID(subscriptionId, resourceGroup, privateDnsZoneName, aAAAName string) AaaaRecordId { + return AaaaRecordId{ + SubscriptionId: subscriptionId, + ResourceGroup: resourceGroup, + PrivateDnsZoneName: privateDnsZoneName, + AAAAName: aAAAName, + } +} + +func (id AaaaRecordId) String() string { + segments := []string{ + fmt.Sprintf("A A A A Name %q", id.AAAAName), + fmt.Sprintf("Private Dns Zone Name %q", id.PrivateDnsZoneName), + fmt.Sprintf("Resource Group %q", id.ResourceGroup), + } + segmentsStr := strings.Join(segments, " / ") + return fmt.Sprintf("%s: (%s)", "Aaaa Record", segmentsStr) +} + +func (id AaaaRecordId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/privateDnsZones/%s/AAAA/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.PrivateDnsZoneName, id.AAAAName) +} + +// AaaaRecordID parses a AaaaRecord ID into an AaaaRecordId struct +func AaaaRecordID(input string) (*AaaaRecordId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + resourceId := AaaaRecordId{ + 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.PrivateDnsZoneName, err = id.PopSegment("privateDnsZones"); err != nil { + return nil, err + } + if resourceId.AAAAName, err = id.PopSegment("AAAA"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} diff --git a/internal/services/privatedns/parse/aaaa_record_test.go b/internal/services/privatedns/parse/aaaa_record_test.go new file mode 100644 index 000000000000..3d61bf94feac --- /dev/null +++ b/internal/services/privatedns/parse/aaaa_record_test.go @@ -0,0 +1,128 @@ +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 = AaaaRecordId{} + +func TestAaaaRecordIDFormatter(t *testing.T) { + actual := NewAaaaRecordID("12345678-1234-9876-4563-123456789012", "resGroup1", "privateDnsZone1", "eheh1").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/AAAA/eheh1" + if actual != expected { + t.Fatalf("Expected %q but got %q", expected, actual) + } +} + +func TestAaaaRecordID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AaaaRecordId + }{ + + { + // 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 PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", + Error: true, + }, + + { + // missing value for PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", + Error: true, + }, + + { + // missing AAAAName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", + Error: true, + }, + + { + // missing value for AAAAName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/AAAA/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/AAAA/eheh1", + Expected: &AaaaRecordId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + PrivateDnsZoneName: "privateDnsZone1", + AAAAName: "eheh1", + }, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/AAAA/EHEH1", + Error: true, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := AaaaRecordID(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.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { + t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) + } + if actual.AAAAName != v.Expected.AAAAName { + t.Fatalf("Expected %q but got %q for AAAAName", v.Expected.AAAAName, actual.AAAAName) + } + } +} diff --git a/internal/services/privatedns/parse/cname_record.go b/internal/services/privatedns/parse/cname_record.go new file mode 100644 index 000000000000..52de00de2a71 --- /dev/null +++ b/internal/services/privatedns/parse/cname_record.go @@ -0,0 +1,75 @@ +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 CnameRecordId struct { + SubscriptionId string + ResourceGroup string + PrivateDnsZoneName string + CNAMEName string +} + +func NewCnameRecordID(subscriptionId, resourceGroup, privateDnsZoneName, cNAMEName string) CnameRecordId { + return CnameRecordId{ + SubscriptionId: subscriptionId, + ResourceGroup: resourceGroup, + PrivateDnsZoneName: privateDnsZoneName, + CNAMEName: cNAMEName, + } +} + +func (id CnameRecordId) String() string { + segments := []string{ + fmt.Sprintf("C N A M E Name %q", id.CNAMEName), + fmt.Sprintf("Private Dns Zone Name %q", id.PrivateDnsZoneName), + fmt.Sprintf("Resource Group %q", id.ResourceGroup), + } + segmentsStr := strings.Join(segments, " / ") + return fmt.Sprintf("%s: (%s)", "Cname Record", segmentsStr) +} + +func (id CnameRecordId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/privateDnsZones/%s/CNAME/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.PrivateDnsZoneName, id.CNAMEName) +} + +// CnameRecordID parses a CnameRecord ID into an CnameRecordId struct +func CnameRecordID(input string) (*CnameRecordId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + resourceId := CnameRecordId{ + 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.PrivateDnsZoneName, err = id.PopSegment("privateDnsZones"); err != nil { + return nil, err + } + if resourceId.CNAMEName, err = id.PopSegment("CNAME"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} diff --git a/internal/services/privatedns/parse/cname_record_test.go b/internal/services/privatedns/parse/cname_record_test.go new file mode 100644 index 000000000000..5d18f58e25a2 --- /dev/null +++ b/internal/services/privatedns/parse/cname_record_test.go @@ -0,0 +1,128 @@ +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 = CnameRecordId{} + +func TestCnameRecordIDFormatter(t *testing.T) { + actual := NewCnameRecordID("12345678-1234-9876-4563-123456789012", "resGroup1", "privateDnsZone1", "name1").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/CNAME/name1" + if actual != expected { + t.Fatalf("Expected %q but got %q", expected, actual) + } +} + +func TestCnameRecordID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CnameRecordId + }{ + + { + // 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 PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", + Error: true, + }, + + { + // missing value for PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", + Error: true, + }, + + { + // missing CNAMEName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", + Error: true, + }, + + { + // missing value for CNAMEName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/CNAME/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/CNAME/name1", + Expected: &CnameRecordId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + PrivateDnsZoneName: "privateDnsZone1", + CNAMEName: "name1", + }, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/CNAME/NAME1", + Error: true, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := CnameRecordID(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.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { + t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) + } + if actual.CNAMEName != v.Expected.CNAMEName { + t.Fatalf("Expected %q but got %q for CNAMEName", v.Expected.CNAMEName, actual.CNAMEName) + } + } +} diff --git a/internal/services/privatedns/parse/mx_record.go b/internal/services/privatedns/parse/mx_record.go new file mode 100644 index 000000000000..b753efdf2bef --- /dev/null +++ b/internal/services/privatedns/parse/mx_record.go @@ -0,0 +1,75 @@ +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 MxRecordId struct { + SubscriptionId string + ResourceGroup string + PrivateDnsZoneName string + MXName string +} + +func NewMxRecordID(subscriptionId, resourceGroup, privateDnsZoneName, mXName string) MxRecordId { + return MxRecordId{ + SubscriptionId: subscriptionId, + ResourceGroup: resourceGroup, + PrivateDnsZoneName: privateDnsZoneName, + MXName: mXName, + } +} + +func (id MxRecordId) String() string { + segments := []string{ + fmt.Sprintf("M X Name %q", id.MXName), + fmt.Sprintf("Private Dns Zone Name %q", id.PrivateDnsZoneName), + fmt.Sprintf("Resource Group %q", id.ResourceGroup), + } + segmentsStr := strings.Join(segments, " / ") + return fmt.Sprintf("%s: (%s)", "Mx Record", segmentsStr) +} + +func (id MxRecordId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/privateDnsZones/%s/MX/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.PrivateDnsZoneName, id.MXName) +} + +// MxRecordID parses a MxRecord ID into an MxRecordId struct +func MxRecordID(input string) (*MxRecordId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + resourceId := MxRecordId{ + 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.PrivateDnsZoneName, err = id.PopSegment("privateDnsZones"); err != nil { + return nil, err + } + if resourceId.MXName, err = id.PopSegment("MX"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} diff --git a/internal/services/privatedns/parse/mx_record_test.go b/internal/services/privatedns/parse/mx_record_test.go new file mode 100644 index 000000000000..3bd9befb8250 --- /dev/null +++ b/internal/services/privatedns/parse/mx_record_test.go @@ -0,0 +1,128 @@ +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 = MxRecordId{} + +func TestMxRecordIDFormatter(t *testing.T) { + actual := NewMxRecordID("12345678-1234-9876-4563-123456789012", "resGroup1", "privateDnsZone1", "mx1").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/MX/mx1" + if actual != expected { + t.Fatalf("Expected %q but got %q", expected, actual) + } +} + +func TestMxRecordID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MxRecordId + }{ + + { + // 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 PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", + Error: true, + }, + + { + // missing value for PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", + Error: true, + }, + + { + // missing MXName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", + Error: true, + }, + + { + // missing value for MXName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/MX/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/MX/mx1", + Expected: &MxRecordId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + PrivateDnsZoneName: "privateDnsZone1", + MXName: "mx1", + }, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/MX/MX1", + Error: true, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := MxRecordID(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.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { + t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) + } + if actual.MXName != v.Expected.MXName { + t.Fatalf("Expected %q but got %q for MXName", v.Expected.MXName, actual.MXName) + } + } +} diff --git a/internal/services/privatedns/parse/private_dns_zone.go b/internal/services/privatedns/parse/private_dns_zone.go new file mode 100644 index 000000000000..7ed4f6f732b6 --- /dev/null +++ b/internal/services/privatedns/parse/private_dns_zone.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 PrivateDnsZoneId struct { + SubscriptionId string + ResourceGroup string + Name string +} + +func NewPrivateDnsZoneID(subscriptionId, resourceGroup, name string) PrivateDnsZoneId { + return PrivateDnsZoneId{ + SubscriptionId: subscriptionId, + ResourceGroup: resourceGroup, + Name: name, + } +} + +func (id PrivateDnsZoneId) String() string { + segments := []string{ + fmt.Sprintf("Name %q", id.Name), + fmt.Sprintf("Resource Group %q", id.ResourceGroup), + } + segmentsStr := strings.Join(segments, " / ") + return fmt.Sprintf("%s: (%s)", "Private Dns Zone", segmentsStr) +} + +func (id PrivateDnsZoneId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/privateDnsZones/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.Name) +} + +// PrivateDnsZoneID parses a PrivateDnsZone ID into an PrivateDnsZoneId struct +func PrivateDnsZoneID(input string) (*PrivateDnsZoneId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + resourceId := PrivateDnsZoneId{ + 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.Name, err = id.PopSegment("privateDnsZones"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} diff --git a/internal/services/privatedns/parse/private_dns_zone_test.go b/internal/services/privatedns/parse/private_dns_zone_test.go new file mode 100644 index 000000000000..6edb3569ca4c --- /dev/null +++ b/internal/services/privatedns/parse/private_dns_zone_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 = PrivateDnsZoneId{} + +func TestPrivateDnsZoneIDFormatter(t *testing.T) { + actual := NewPrivateDnsZoneID("12345678-1234-9876-4563-123456789012", "resGroup1", "privateDnsZone1").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1" + if actual != expected { + t.Fatalf("Expected %q but got %q", expected, actual) + } +} + +func TestPrivateDnsZoneID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateDnsZoneId + }{ + + { + // 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 Name + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", + Error: true, + }, + + { + // missing value for Name + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1", + Expected: &PrivateDnsZoneId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + Name: "privateDnsZone1", + }, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1", + Error: true, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := PrivateDnsZoneID(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.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + } + } +} diff --git a/internal/services/privatedns/parse/ptr_record.go b/internal/services/privatedns/parse/ptr_record.go new file mode 100644 index 000000000000..c665609f92f5 --- /dev/null +++ b/internal/services/privatedns/parse/ptr_record.go @@ -0,0 +1,75 @@ +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 PtrRecordId struct { + SubscriptionId string + ResourceGroup string + PrivateDnsZoneName string + PTRName string +} + +func NewPtrRecordID(subscriptionId, resourceGroup, privateDnsZoneName, pTRName string) PtrRecordId { + return PtrRecordId{ + SubscriptionId: subscriptionId, + ResourceGroup: resourceGroup, + PrivateDnsZoneName: privateDnsZoneName, + PTRName: pTRName, + } +} + +func (id PtrRecordId) String() string { + segments := []string{ + fmt.Sprintf("P T R Name %q", id.PTRName), + fmt.Sprintf("Private Dns Zone Name %q", id.PrivateDnsZoneName), + fmt.Sprintf("Resource Group %q", id.ResourceGroup), + } + segmentsStr := strings.Join(segments, " / ") + return fmt.Sprintf("%s: (%s)", "Ptr Record", segmentsStr) +} + +func (id PtrRecordId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/privateDnsZones/%s/PTR/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.PrivateDnsZoneName, id.PTRName) +} + +// PtrRecordID parses a PtrRecord ID into an PtrRecordId struct +func PtrRecordID(input string) (*PtrRecordId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + resourceId := PtrRecordId{ + 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.PrivateDnsZoneName, err = id.PopSegment("privateDnsZones"); err != nil { + return nil, err + } + if resourceId.PTRName, err = id.PopSegment("PTR"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} diff --git a/internal/services/privatedns/parse/ptr_record_test.go b/internal/services/privatedns/parse/ptr_record_test.go new file mode 100644 index 000000000000..b16c62f84ae2 --- /dev/null +++ b/internal/services/privatedns/parse/ptr_record_test.go @@ -0,0 +1,128 @@ +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 = PtrRecordId{} + +func TestPtrRecordIDFormatter(t *testing.T) { + actual := NewPtrRecordID("12345678-1234-9876-4563-123456789012", "resGroup1", "privateDnsZone1", "ptr1").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/PTR/ptr1" + if actual != expected { + t.Fatalf("Expected %q but got %q", expected, actual) + } +} + +func TestPtrRecordID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PtrRecordId + }{ + + { + // 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 PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", + Error: true, + }, + + { + // missing value for PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", + Error: true, + }, + + { + // missing PTRName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", + Error: true, + }, + + { + // missing value for PTRName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/PTR/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/PTR/ptr1", + Expected: &PtrRecordId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + PrivateDnsZoneName: "privateDnsZone1", + PTRName: "ptr1", + }, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/PTR/PTR1", + Error: true, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := PtrRecordID(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.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { + t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) + } + if actual.PTRName != v.Expected.PTRName { + t.Fatalf("Expected %q but got %q for PTRName", v.Expected.PTRName, actual.PTRName) + } + } +} diff --git a/internal/services/privatedns/parse/srv_record.go b/internal/services/privatedns/parse/srv_record.go new file mode 100644 index 000000000000..9dffad560e73 --- /dev/null +++ b/internal/services/privatedns/parse/srv_record.go @@ -0,0 +1,75 @@ +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 SrvRecordId struct { + SubscriptionId string + ResourceGroup string + PrivateDnsZoneName string + SRVName string +} + +func NewSrvRecordID(subscriptionId, resourceGroup, privateDnsZoneName, sRVName string) SrvRecordId { + return SrvRecordId{ + SubscriptionId: subscriptionId, + ResourceGroup: resourceGroup, + PrivateDnsZoneName: privateDnsZoneName, + SRVName: sRVName, + } +} + +func (id SrvRecordId) String() string { + segments := []string{ + fmt.Sprintf("S R V Name %q", id.SRVName), + fmt.Sprintf("Private Dns Zone Name %q", id.PrivateDnsZoneName), + fmt.Sprintf("Resource Group %q", id.ResourceGroup), + } + segmentsStr := strings.Join(segments, " / ") + return fmt.Sprintf("%s: (%s)", "Srv Record", segmentsStr) +} + +func (id SrvRecordId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/privateDnsZones/%s/SRV/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.PrivateDnsZoneName, id.SRVName) +} + +// SrvRecordID parses a SrvRecord ID into an SrvRecordId struct +func SrvRecordID(input string) (*SrvRecordId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + resourceId := SrvRecordId{ + 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.PrivateDnsZoneName, err = id.PopSegment("privateDnsZones"); err != nil { + return nil, err + } + if resourceId.SRVName, err = id.PopSegment("SRV"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} diff --git a/internal/services/privatedns/parse/srv_record_test.go b/internal/services/privatedns/parse/srv_record_test.go new file mode 100644 index 000000000000..2fceda33a896 --- /dev/null +++ b/internal/services/privatedns/parse/srv_record_test.go @@ -0,0 +1,128 @@ +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 = SrvRecordId{} + +func TestSrvRecordIDFormatter(t *testing.T) { + actual := NewSrvRecordID("12345678-1234-9876-4563-123456789012", "resGroup1", "privateDnsZone1", "srv1").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/SRV/srv1" + if actual != expected { + t.Fatalf("Expected %q but got %q", expected, actual) + } +} + +func TestSrvRecordID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SrvRecordId + }{ + + { + // 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 PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", + Error: true, + }, + + { + // missing value for PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", + Error: true, + }, + + { + // missing SRVName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", + Error: true, + }, + + { + // missing value for SRVName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/SRV/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/SRV/srv1", + Expected: &SrvRecordId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + PrivateDnsZoneName: "privateDnsZone1", + SRVName: "srv1", + }, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/SRV/SRV1", + Error: true, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := SrvRecordID(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.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { + t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) + } + if actual.SRVName != v.Expected.SRVName { + t.Fatalf("Expected %q but got %q for SRVName", v.Expected.SRVName, actual.SRVName) + } + } +} diff --git a/internal/services/privatedns/parse/txt_record.go b/internal/services/privatedns/parse/txt_record.go new file mode 100644 index 000000000000..3eb8a1ba999a --- /dev/null +++ b/internal/services/privatedns/parse/txt_record.go @@ -0,0 +1,75 @@ +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 TxtRecordId struct { + SubscriptionId string + ResourceGroup string + PrivateDnsZoneName string + TXTName string +} + +func NewTxtRecordID(subscriptionId, resourceGroup, privateDnsZoneName, tXTName string) TxtRecordId { + return TxtRecordId{ + SubscriptionId: subscriptionId, + ResourceGroup: resourceGroup, + PrivateDnsZoneName: privateDnsZoneName, + TXTName: tXTName, + } +} + +func (id TxtRecordId) String() string { + segments := []string{ + fmt.Sprintf("T X T Name %q", id.TXTName), + fmt.Sprintf("Private Dns Zone Name %q", id.PrivateDnsZoneName), + fmt.Sprintf("Resource Group %q", id.ResourceGroup), + } + segmentsStr := strings.Join(segments, " / ") + return fmt.Sprintf("%s: (%s)", "Txt Record", segmentsStr) +} + +func (id TxtRecordId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/privateDnsZones/%s/TXT/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.PrivateDnsZoneName, id.TXTName) +} + +// TxtRecordID parses a TxtRecord ID into an TxtRecordId struct +func TxtRecordID(input string) (*TxtRecordId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + resourceId := TxtRecordId{ + 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.PrivateDnsZoneName, err = id.PopSegment("privateDnsZones"); err != nil { + return nil, err + } + if resourceId.TXTName, err = id.PopSegment("TXT"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} diff --git a/internal/services/privatedns/parse/txt_record_test.go b/internal/services/privatedns/parse/txt_record_test.go new file mode 100644 index 000000000000..4947041f9006 --- /dev/null +++ b/internal/services/privatedns/parse/txt_record_test.go @@ -0,0 +1,128 @@ +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 = TxtRecordId{} + +func TestTxtRecordIDFormatter(t *testing.T) { + actual := NewTxtRecordID("12345678-1234-9876-4563-123456789012", "resGroup1", "privateDnsZone1", "txt1").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/TXT/txt1" + if actual != expected { + t.Fatalf("Expected %q but got %q", expected, actual) + } +} + +func TestTxtRecordID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TxtRecordId + }{ + + { + // 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 PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", + Error: true, + }, + + { + // missing value for PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", + Error: true, + }, + + { + // missing TXTName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", + Error: true, + }, + + { + // missing value for TXTName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/TXT/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/TXT/txt1", + Expected: &TxtRecordId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + PrivateDnsZoneName: "privateDnsZone1", + TXTName: "txt1", + }, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/TXT/TXT1", + Error: true, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := TxtRecordID(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.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { + t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) + } + if actual.TXTName != v.Expected.TXTName { + t.Fatalf("Expected %q but got %q for TXTName", v.Expected.TXTName, actual.TXTName) + } + } +} diff --git a/internal/services/privatedns/parse/virtual_network_link.go b/internal/services/privatedns/parse/virtual_network_link.go new file mode 100644 index 000000000000..7ca1c96fdb84 --- /dev/null +++ b/internal/services/privatedns/parse/virtual_network_link.go @@ -0,0 +1,75 @@ +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 VirtualNetworkLinkId struct { + SubscriptionId string + ResourceGroup string + PrivateDnsZoneName string + Name string +} + +func NewVirtualNetworkLinkID(subscriptionId, resourceGroup, privateDnsZoneName, name string) VirtualNetworkLinkId { + return VirtualNetworkLinkId{ + SubscriptionId: subscriptionId, + ResourceGroup: resourceGroup, + PrivateDnsZoneName: privateDnsZoneName, + Name: name, + } +} + +func (id VirtualNetworkLinkId) String() string { + segments := []string{ + fmt.Sprintf("Name %q", id.Name), + fmt.Sprintf("Private Dns Zone Name %q", id.PrivateDnsZoneName), + fmt.Sprintf("Resource Group %q", id.ResourceGroup), + } + segmentsStr := strings.Join(segments, " / ") + return fmt.Sprintf("%s: (%s)", "Virtual Network Link", segmentsStr) +} + +func (id VirtualNetworkLinkId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/privateDnsZones/%s/virtualNetworkLinks/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.PrivateDnsZoneName, id.Name) +} + +// VirtualNetworkLinkID parses a VirtualNetworkLink ID into an VirtualNetworkLinkId struct +func VirtualNetworkLinkID(input string) (*VirtualNetworkLinkId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + resourceId := VirtualNetworkLinkId{ + 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.PrivateDnsZoneName, err = id.PopSegment("privateDnsZones"); err != nil { + return nil, err + } + if resourceId.Name, err = id.PopSegment("virtualNetworkLinks"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} diff --git a/internal/services/privatedns/parse/virtual_network_link_test.go b/internal/services/privatedns/parse/virtual_network_link_test.go new file mode 100644 index 000000000000..1f45b56b1b67 --- /dev/null +++ b/internal/services/privatedns/parse/virtual_network_link_test.go @@ -0,0 +1,128 @@ +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 = VirtualNetworkLinkId{} + +func TestVirtualNetworkLinkIDFormatter(t *testing.T) { + actual := NewVirtualNetworkLinkID("12345678-1234-9876-4563-123456789012", "resGroup1", "privateDnsZone1", "virtualNetworkLink1").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/virtualNetworkLinks/virtualNetworkLink1" + if actual != expected { + t.Fatalf("Expected %q but got %q", expected, actual) + } +} + +func TestVirtualNetworkLinkID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VirtualNetworkLinkId + }{ + + { + // 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 PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", + Error: true, + }, + + { + // missing value for PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", + Error: true, + }, + + { + // missing Name + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", + Error: true, + }, + + { + // missing value for Name + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/virtualNetworkLinks/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/virtualNetworkLinks/virtualNetworkLink1", + Expected: &VirtualNetworkLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "resGroup1", + PrivateDnsZoneName: "privateDnsZone1", + Name: "virtualNetworkLink1", + }, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/VIRTUALNETWORKLINKS/VIRTUALNETWORKLINK1", + Error: true, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := VirtualNetworkLinkID(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.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { + t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) + } + if actual.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + } + } +} diff --git a/internal/services/privatedns/validate/a_record_id.go b/internal/services/privatedns/validate/a_record_id.go new file mode 100644 index 000000000000..82a9bc624088 --- /dev/null +++ b/internal/services/privatedns/validate/a_record_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/privatedns/parse" +) + +func ARecordID(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.ARecordID(v); err != nil { + errors = append(errors, err) + } + + return +} diff --git a/internal/services/privatedns/validate/a_record_id_test.go b/internal/services/privatedns/validate/a_record_id_test.go new file mode 100644 index 000000000000..137de55ed200 --- /dev/null +++ b/internal/services/privatedns/validate/a_record_id_test.go @@ -0,0 +1,88 @@ +package validate + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import "testing" + +func TestARecordID(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 PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", + Valid: false, + }, + + { + // missing value for PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", + Valid: false, + }, + + { + // missing AName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", + Valid: false, + }, + + { + // missing value for AName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/A/", + Valid: false, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/A/eh1", + Valid: true, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/A/EH1", + Valid: false, + }, + } + for _, tc := range cases { + t.Logf("[DEBUG] Testing Value %s", tc.Input) + _, errors := ARecordID(tc.Input, "test") + valid := len(errors) == 0 + + if tc.Valid != valid { + t.Fatalf("Expected %t but got %t", tc.Valid, valid) + } + } +} diff --git a/internal/services/privatedns/validate/aaaa_record_id.go b/internal/services/privatedns/validate/aaaa_record_id.go new file mode 100644 index 000000000000..4a793181f711 --- /dev/null +++ b/internal/services/privatedns/validate/aaaa_record_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/privatedns/parse" +) + +func AaaaRecordID(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.AaaaRecordID(v); err != nil { + errors = append(errors, err) + } + + return +} diff --git a/internal/services/privatedns/validate/aaaa_record_id_test.go b/internal/services/privatedns/validate/aaaa_record_id_test.go new file mode 100644 index 000000000000..722ad2db77dd --- /dev/null +++ b/internal/services/privatedns/validate/aaaa_record_id_test.go @@ -0,0 +1,88 @@ +package validate + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import "testing" + +func TestAaaaRecordID(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 PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", + Valid: false, + }, + + { + // missing value for PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", + Valid: false, + }, + + { + // missing AAAAName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", + Valid: false, + }, + + { + // missing value for AAAAName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/AAAA/", + Valid: false, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/AAAA/eheh1", + Valid: true, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/AAAA/EHEH1", + Valid: false, + }, + } + for _, tc := range cases { + t.Logf("[DEBUG] Testing Value %s", tc.Input) + _, errors := AaaaRecordID(tc.Input, "test") + valid := len(errors) == 0 + + if tc.Valid != valid { + t.Fatalf("Expected %t but got %t", tc.Valid, valid) + } + } +} diff --git a/internal/services/privatedns/validate/cname_record_id.go b/internal/services/privatedns/validate/cname_record_id.go new file mode 100644 index 000000000000..e7ba85b94910 --- /dev/null +++ b/internal/services/privatedns/validate/cname_record_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/privatedns/parse" +) + +func CnameRecordID(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.CnameRecordID(v); err != nil { + errors = append(errors, err) + } + + return +} diff --git a/internal/services/privatedns/validate/cname_record_id_test.go b/internal/services/privatedns/validate/cname_record_id_test.go new file mode 100644 index 000000000000..0a36d0a361f7 --- /dev/null +++ b/internal/services/privatedns/validate/cname_record_id_test.go @@ -0,0 +1,88 @@ +package validate + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import "testing" + +func TestCnameRecordID(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 PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", + Valid: false, + }, + + { + // missing value for PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", + Valid: false, + }, + + { + // missing CNAMEName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", + Valid: false, + }, + + { + // missing value for CNAMEName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/CNAME/", + Valid: false, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/CNAME/name1", + Valid: true, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/CNAME/NAME1", + Valid: false, + }, + } + for _, tc := range cases { + t.Logf("[DEBUG] Testing Value %s", tc.Input) + _, errors := CnameRecordID(tc.Input, "test") + valid := len(errors) == 0 + + if tc.Valid != valid { + t.Fatalf("Expected %t but got %t", tc.Valid, valid) + } + } +} diff --git a/internal/services/privatedns/validate/mx_record_id.go b/internal/services/privatedns/validate/mx_record_id.go new file mode 100644 index 000000000000..101ee7ae365b --- /dev/null +++ b/internal/services/privatedns/validate/mx_record_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/privatedns/parse" +) + +func MxRecordID(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.MxRecordID(v); err != nil { + errors = append(errors, err) + } + + return +} diff --git a/internal/services/privatedns/validate/mx_record_id_test.go b/internal/services/privatedns/validate/mx_record_id_test.go new file mode 100644 index 000000000000..3856df0dd637 --- /dev/null +++ b/internal/services/privatedns/validate/mx_record_id_test.go @@ -0,0 +1,88 @@ +package validate + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import "testing" + +func TestMxRecordID(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 PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", + Valid: false, + }, + + { + // missing value for PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", + Valid: false, + }, + + { + // missing MXName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", + Valid: false, + }, + + { + // missing value for MXName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/MX/", + Valid: false, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/MX/mx1", + Valid: true, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/MX/MX1", + Valid: false, + }, + } + for _, tc := range cases { + t.Logf("[DEBUG] Testing Value %s", tc.Input) + _, errors := MxRecordID(tc.Input, "test") + valid := len(errors) == 0 + + if tc.Valid != valid { + t.Fatalf("Expected %t but got %t", tc.Valid, valid) + } + } +} diff --git a/internal/services/privatedns/validate/private_dns_zone_id.go b/internal/services/privatedns/validate/private_dns_zone_id.go new file mode 100644 index 000000000000..fc812dc9d7bb --- /dev/null +++ b/internal/services/privatedns/validate/private_dns_zone_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/privatedns/parse" +) + +func PrivateDnsZoneID(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.PrivateDnsZoneID(v); err != nil { + errors = append(errors, err) + } + + return +} diff --git a/internal/services/privatedns/validate/private_dns_zone_id_test.go b/internal/services/privatedns/validate/private_dns_zone_id_test.go new file mode 100644 index 000000000000..273feaa285b2 --- /dev/null +++ b/internal/services/privatedns/validate/private_dns_zone_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 TestPrivateDnsZoneID(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 Name + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", + Valid: false, + }, + + { + // missing value for Name + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", + Valid: false, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1", + Valid: true, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1", + Valid: false, + }, + } + for _, tc := range cases { + t.Logf("[DEBUG] Testing Value %s", tc.Input) + _, errors := PrivateDnsZoneID(tc.Input, "test") + valid := len(errors) == 0 + + if tc.Valid != valid { + t.Fatalf("Expected %t but got %t", tc.Valid, valid) + } + } +} diff --git a/internal/services/privatedns/validate/ptr_record_id.go b/internal/services/privatedns/validate/ptr_record_id.go new file mode 100644 index 000000000000..b135102f829b --- /dev/null +++ b/internal/services/privatedns/validate/ptr_record_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/privatedns/parse" +) + +func PtrRecordID(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.PtrRecordID(v); err != nil { + errors = append(errors, err) + } + + return +} diff --git a/internal/services/privatedns/validate/ptr_record_id_test.go b/internal/services/privatedns/validate/ptr_record_id_test.go new file mode 100644 index 000000000000..8170964a3ba4 --- /dev/null +++ b/internal/services/privatedns/validate/ptr_record_id_test.go @@ -0,0 +1,88 @@ +package validate + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import "testing" + +func TestPtrRecordID(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 PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", + Valid: false, + }, + + { + // missing value for PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", + Valid: false, + }, + + { + // missing PTRName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", + Valid: false, + }, + + { + // missing value for PTRName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/PTR/", + Valid: false, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/PTR/ptr1", + Valid: true, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/PTR/PTR1", + Valid: false, + }, + } + for _, tc := range cases { + t.Logf("[DEBUG] Testing Value %s", tc.Input) + _, errors := PtrRecordID(tc.Input, "test") + valid := len(errors) == 0 + + if tc.Valid != valid { + t.Fatalf("Expected %t but got %t", tc.Valid, valid) + } + } +} diff --git a/internal/services/privatedns/validate/srv_record_id.go b/internal/services/privatedns/validate/srv_record_id.go new file mode 100644 index 000000000000..0ee85e416de3 --- /dev/null +++ b/internal/services/privatedns/validate/srv_record_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/privatedns/parse" +) + +func SrvRecordID(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.SrvRecordID(v); err != nil { + errors = append(errors, err) + } + + return +} diff --git a/internal/services/privatedns/validate/srv_record_id_test.go b/internal/services/privatedns/validate/srv_record_id_test.go new file mode 100644 index 000000000000..cc109ab8cf5b --- /dev/null +++ b/internal/services/privatedns/validate/srv_record_id_test.go @@ -0,0 +1,88 @@ +package validate + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import "testing" + +func TestSrvRecordID(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 PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", + Valid: false, + }, + + { + // missing value for PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", + Valid: false, + }, + + { + // missing SRVName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", + Valid: false, + }, + + { + // missing value for SRVName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/SRV/", + Valid: false, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/SRV/srv1", + Valid: true, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/SRV/SRV1", + Valid: false, + }, + } + for _, tc := range cases { + t.Logf("[DEBUG] Testing Value %s", tc.Input) + _, errors := SrvRecordID(tc.Input, "test") + valid := len(errors) == 0 + + if tc.Valid != valid { + t.Fatalf("Expected %t but got %t", tc.Valid, valid) + } + } +} diff --git a/internal/services/privatedns/validate/txt_record_id.go b/internal/services/privatedns/validate/txt_record_id.go new file mode 100644 index 000000000000..8e9b0c9dfcfb --- /dev/null +++ b/internal/services/privatedns/validate/txt_record_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/privatedns/parse" +) + +func TxtRecordID(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.TxtRecordID(v); err != nil { + errors = append(errors, err) + } + + return +} diff --git a/internal/services/privatedns/validate/txt_record_id_test.go b/internal/services/privatedns/validate/txt_record_id_test.go new file mode 100644 index 000000000000..390bbcc051f3 --- /dev/null +++ b/internal/services/privatedns/validate/txt_record_id_test.go @@ -0,0 +1,88 @@ +package validate + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import "testing" + +func TestTxtRecordID(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 PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", + Valid: false, + }, + + { + // missing value for PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", + Valid: false, + }, + + { + // missing TXTName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", + Valid: false, + }, + + { + // missing value for TXTName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/TXT/", + Valid: false, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/TXT/txt1", + Valid: true, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/TXT/TXT1", + Valid: false, + }, + } + for _, tc := range cases { + t.Logf("[DEBUG] Testing Value %s", tc.Input) + _, errors := TxtRecordID(tc.Input, "test") + valid := len(errors) == 0 + + if tc.Valid != valid { + t.Fatalf("Expected %t but got %t", tc.Valid, valid) + } + } +} diff --git a/internal/services/privatedns/validate/virtual_network_link_id.go b/internal/services/privatedns/validate/virtual_network_link_id.go new file mode 100644 index 000000000000..f538ea86ef15 --- /dev/null +++ b/internal/services/privatedns/validate/virtual_network_link_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/privatedns/parse" +) + +func VirtualNetworkLinkID(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.VirtualNetworkLinkID(v); err != nil { + errors = append(errors, err) + } + + return +} diff --git a/internal/services/privatedns/validate/virtual_network_link_id_test.go b/internal/services/privatedns/validate/virtual_network_link_id_test.go new file mode 100644 index 000000000000..ad87350b81b8 --- /dev/null +++ b/internal/services/privatedns/validate/virtual_network_link_id_test.go @@ -0,0 +1,88 @@ +package validate + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import "testing" + +func TestVirtualNetworkLinkID(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 PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", + Valid: false, + }, + + { + // missing value for PrivateDnsZoneName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", + Valid: false, + }, + + { + // missing Name + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", + Valid: false, + }, + + { + // missing value for Name + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/virtualNetworkLinks/", + Valid: false, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/virtualNetworkLinks/virtualNetworkLink1", + Valid: true, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/VIRTUALNETWORKLINKS/VIRTUALNETWORKLINK1", + Valid: false, + }, + } + for _, tc := range cases { + t.Logf("[DEBUG] Testing Value %s", tc.Input) + _, errors := VirtualNetworkLinkID(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/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/client.go new file mode 100644 index 000000000000..f870e5c2d7b0 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/client.go @@ -0,0 +1,18 @@ +package operationalinsights + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OperationalInsightsClient struct { + Client autorest.Client + baseUri string +} + +func NewOperationalInsightsClientWithBaseURI(endpoint string) OperationalInsightsClient { + return OperationalInsightsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/id_queries.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/id_queries.go new file mode 100644 index 000000000000..55cbdcc5b4d9 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/id_queries.go @@ -0,0 +1,137 @@ +package operationalinsights + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = QueriesId{} + +// QueriesId is a struct representing the Resource ID for a Queries +type QueriesId struct { + SubscriptionId string + ResourceGroupName string + QueryPackName string + Id string +} + +// NewQueriesID returns a new QueriesId struct +func NewQueriesID(subscriptionId string, resourceGroupName string, queryPackName string, id string) QueriesId { + return QueriesId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + QueryPackName: queryPackName, + Id: id, + } +} + +// ParseQueriesID parses 'input' into a QueriesId +func ParseQueriesID(input string) (*QueriesId, error) { + parser := resourceids.NewParserFromResourceIdType(QueriesId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := QueriesId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.QueryPackName, ok = parsed.Parsed["queryPackName"]; !ok { + return nil, fmt.Errorf("the segment 'queryPackName' was not found in the resource id %q", input) + } + + if id.Id, ok = parsed.Parsed["id"]; !ok { + return nil, fmt.Errorf("the segment 'id' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseQueriesIDInsensitively parses 'input' case-insensitively into a QueriesId +// note: this method should only be used for API response data and not user input +func ParseQueriesIDInsensitively(input string) (*QueriesId, error) { + parser := resourceids.NewParserFromResourceIdType(QueriesId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := QueriesId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.QueryPackName, ok = parsed.Parsed["queryPackName"]; !ok { + return nil, fmt.Errorf("the segment 'queryPackName' was not found in the resource id %q", input) + } + + if id.Id, ok = parsed.Parsed["id"]; !ok { + return nil, fmt.Errorf("the segment 'id' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateQueriesID checks that 'input' can be parsed as a Queries ID +func ValidateQueriesID(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 := ParseQueriesID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Queries ID +func (id QueriesId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/queryPacks/%s/queries/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.QueryPackName, id.Id) +} + +// Segments returns a slice of Resource ID Segments which comprise this Queries ID +func (id QueriesId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticQueryPacks", "queryPacks", "queryPacks"), + resourceids.UserSpecifiedSegment("queryPackName", "queryPackValue"), + resourceids.StaticSegment("staticQueries", "queries", "queries"), + resourceids.UserSpecifiedSegment("id", "idValue"), + } +} + +// String returns a human-readable description of this Queries ID +func (id QueriesId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Query Pack Name: %q", id.QueryPackName), + fmt.Sprintf(": %q", id.Id), + } + return fmt.Sprintf("Queries (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/id_querypack.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/id_querypack.go new file mode 100644 index 000000000000..b7a249a5c602 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/id_querypack.go @@ -0,0 +1,124 @@ +package operationalinsights + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = QueryPackId{} + +// QueryPackId is a struct representing the Resource ID for a Query Pack +type QueryPackId struct { + SubscriptionId string + ResourceGroupName string + QueryPackName string +} + +// NewQueryPackID returns a new QueryPackId struct +func NewQueryPackID(subscriptionId string, resourceGroupName string, queryPackName string) QueryPackId { + return QueryPackId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + QueryPackName: queryPackName, + } +} + +// ParseQueryPackID parses 'input' into a QueryPackId +func ParseQueryPackID(input string) (*QueryPackId, error) { + parser := resourceids.NewParserFromResourceIdType(QueryPackId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := QueryPackId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.QueryPackName, ok = parsed.Parsed["queryPackName"]; !ok { + return nil, fmt.Errorf("the segment 'queryPackName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseQueryPackIDInsensitively parses 'input' case-insensitively into a QueryPackId +// note: this method should only be used for API response data and not user input +func ParseQueryPackIDInsensitively(input string) (*QueryPackId, error) { + parser := resourceids.NewParserFromResourceIdType(QueryPackId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := QueryPackId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.QueryPackName, ok = parsed.Parsed["queryPackName"]; !ok { + return nil, fmt.Errorf("the segment 'queryPackName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateQueryPackID checks that 'input' can be parsed as a Query Pack ID +func ValidateQueryPackID(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 := ParseQueryPackID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Query Pack ID +func (id QueryPackId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/queryPacks/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.QueryPackName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Query Pack ID +func (id QueryPackId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticQueryPacks", "queryPacks", "queryPacks"), + resourceids.UserSpecifiedSegment("queryPackName", "queryPackValue"), + } +} + +// String returns a human-readable description of this Query Pack ID +func (id QueryPackId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Query Pack Name: %q", id.QueryPackName), + } + return fmt.Sprintf("Query Pack (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_queriesdelete_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_queriesdelete_autorest.go new file mode 100644 index 000000000000..eb8278f90180 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_queriesdelete_autorest.go @@ -0,0 +1,65 @@ +package operationalinsights + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueriesDeleteOperationResponse struct { + HttpResponse *http.Response +} + +// QueriesDelete ... +func (c OperationalInsightsClient) QueriesDelete(ctx context.Context, id QueriesId) (result QueriesDeleteOperationResponse, err error) { + req, err := c.preparerForQueriesDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueriesDelete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueriesDelete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForQueriesDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueriesDelete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForQueriesDelete prepares the QueriesDelete request. +func (c OperationalInsightsClient) preparerForQueriesDelete(ctx context.Context, id QueriesId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForQueriesDelete handles the response to the QueriesDelete request. The method always +// closes the http.Response Body. +func (c OperationalInsightsClient) responderForQueriesDelete(resp *http.Response) (result QueriesDeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_queriesget_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_queriesget_autorest.go new file mode 100644 index 000000000000..7b014b8e89db --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_queriesget_autorest.go @@ -0,0 +1,67 @@ +package operationalinsights + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueriesGetOperationResponse struct { + HttpResponse *http.Response + Model *LogAnalyticsQueryPackQuery +} + +// QueriesGet ... +func (c OperationalInsightsClient) QueriesGet(ctx context.Context, id QueriesId) (result QueriesGetOperationResponse, err error) { + req, err := c.preparerForQueriesGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueriesGet", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueriesGet", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForQueriesGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueriesGet", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForQueriesGet prepares the QueriesGet request. +func (c OperationalInsightsClient) preparerForQueriesGet(ctx context.Context, id QueriesId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForQueriesGet handles the response to the QueriesGet request. The method always +// closes the http.Response Body. +func (c OperationalInsightsClient) responderForQueriesGet(resp *http.Response) (result QueriesGetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querieslist_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querieslist_autorest.go new file mode 100644 index 000000000000..1254f7c00d55 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querieslist_autorest.go @@ -0,0 +1,220 @@ +package operationalinsights + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueriesListOperationResponse struct { + HttpResponse *http.Response + Model *[]LogAnalyticsQueryPackQuery + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (QueriesListOperationResponse, error) +} + +type QueriesListCompleteResult struct { + Items []LogAnalyticsQueryPackQuery +} + +func (r QueriesListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r QueriesListOperationResponse) LoadMore(ctx context.Context) (resp QueriesListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type QueriesListOperationOptions struct { + IncludeBody *bool + Top *int64 +} + +func DefaultQueriesListOperationOptions() QueriesListOperationOptions { + return QueriesListOperationOptions{} +} + +func (o QueriesListOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o QueriesListOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.IncludeBody != nil { + out["includeBody"] = *o.IncludeBody + } + + if o.Top != nil { + out["$top"] = *o.Top + } + + return out +} + +// QueriesList ... +func (c OperationalInsightsClient) QueriesList(ctx context.Context, id QueryPackId, options QueriesListOperationOptions) (resp QueriesListOperationResponse, err error) { + req, err := c.preparerForQueriesList(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueriesList", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueriesList", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForQueriesList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueriesList", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// QueriesListComplete retrieves all of the results into a single object +func (c OperationalInsightsClient) QueriesListComplete(ctx context.Context, id QueryPackId, options QueriesListOperationOptions) (QueriesListCompleteResult, error) { + return c.QueriesListCompleteMatchingPredicate(ctx, id, options, LogAnalyticsQueryPackQueryOperationPredicate{}) +} + +// QueriesListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c OperationalInsightsClient) QueriesListCompleteMatchingPredicate(ctx context.Context, id QueryPackId, options QueriesListOperationOptions, predicate LogAnalyticsQueryPackQueryOperationPredicate) (resp QueriesListCompleteResult, err error) { + items := make([]LogAnalyticsQueryPackQuery, 0) + + page, err := c.QueriesList(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := QueriesListCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForQueriesList prepares the QueriesList request. +func (c OperationalInsightsClient) preparerForQueriesList(ctx context.Context, id QueryPackId, options QueriesListOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/queries", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForQueriesListWithNextLink prepares the QueriesList request with the given nextLink token. +func (c OperationalInsightsClient) preparerForQueriesListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForQueriesList handles the response to the QueriesList request. The method always +// closes the http.Response Body. +func (c OperationalInsightsClient) responderForQueriesList(resp *http.Response) (result QueriesListOperationResponse, err error) { + type page struct { + Values []LogAnalyticsQueryPackQuery `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result QueriesListOperationResponse, err error) { + req, err := c.preparerForQueriesListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueriesList", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueriesList", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForQueriesList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueriesList", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_queriesput_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_queriesput_autorest.go new file mode 100644 index 000000000000..5e93a3d3e9d7 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_queriesput_autorest.go @@ -0,0 +1,68 @@ +package operationalinsights + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueriesPutOperationResponse struct { + HttpResponse *http.Response + Model *LogAnalyticsQueryPackQuery +} + +// QueriesPut ... +func (c OperationalInsightsClient) QueriesPut(ctx context.Context, id QueriesId, input LogAnalyticsQueryPackQuery) (result QueriesPutOperationResponse, err error) { + req, err := c.preparerForQueriesPut(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueriesPut", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueriesPut", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForQueriesPut(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueriesPut", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForQueriesPut prepares the QueriesPut request. +func (c OperationalInsightsClient) preparerForQueriesPut(ctx context.Context, id QueriesId, input LogAnalyticsQueryPackQuery) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForQueriesPut handles the response to the QueriesPut request. The method always +// closes the http.Response Body. +func (c OperationalInsightsClient) responderForQueriesPut(resp *http.Response) (result QueriesPutOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_queriessearch_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_queriessearch_autorest.go new file mode 100644 index 000000000000..871113c98db0 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_queriessearch_autorest.go @@ -0,0 +1,221 @@ +package operationalinsights + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueriesSearchOperationResponse struct { + HttpResponse *http.Response + Model *[]LogAnalyticsQueryPackQuery + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (QueriesSearchOperationResponse, error) +} + +type QueriesSearchCompleteResult struct { + Items []LogAnalyticsQueryPackQuery +} + +func (r QueriesSearchOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r QueriesSearchOperationResponse) LoadMore(ctx context.Context) (resp QueriesSearchOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type QueriesSearchOperationOptions struct { + IncludeBody *bool + Top *int64 +} + +func DefaultQueriesSearchOperationOptions() QueriesSearchOperationOptions { + return QueriesSearchOperationOptions{} +} + +func (o QueriesSearchOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o QueriesSearchOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.IncludeBody != nil { + out["includeBody"] = *o.IncludeBody + } + + if o.Top != nil { + out["$top"] = *o.Top + } + + return out +} + +// QueriesSearch ... +func (c OperationalInsightsClient) QueriesSearch(ctx context.Context, id QueryPackId, input LogAnalyticsQueryPackQuerySearchProperties, options QueriesSearchOperationOptions) (resp QueriesSearchOperationResponse, err error) { + req, err := c.preparerForQueriesSearch(ctx, id, input, options) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueriesSearch", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueriesSearch", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForQueriesSearch(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueriesSearch", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// QueriesSearchComplete retrieves all of the results into a single object +func (c OperationalInsightsClient) QueriesSearchComplete(ctx context.Context, id QueryPackId, input LogAnalyticsQueryPackQuerySearchProperties, options QueriesSearchOperationOptions) (QueriesSearchCompleteResult, error) { + return c.QueriesSearchCompleteMatchingPredicate(ctx, id, input, options, LogAnalyticsQueryPackQueryOperationPredicate{}) +} + +// QueriesSearchCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c OperationalInsightsClient) QueriesSearchCompleteMatchingPredicate(ctx context.Context, id QueryPackId, input LogAnalyticsQueryPackQuerySearchProperties, options QueriesSearchOperationOptions, predicate LogAnalyticsQueryPackQueryOperationPredicate) (resp QueriesSearchCompleteResult, err error) { + items := make([]LogAnalyticsQueryPackQuery, 0) + + page, err := c.QueriesSearch(ctx, id, input, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := QueriesSearchCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForQueriesSearch prepares the QueriesSearch request. +func (c OperationalInsightsClient) preparerForQueriesSearch(ctx context.Context, id QueryPackId, input LogAnalyticsQueryPackQuerySearchProperties, options QueriesSearchOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/queries/search", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForQueriesSearchWithNextLink prepares the QueriesSearch request with the given nextLink token. +func (c OperationalInsightsClient) preparerForQueriesSearchWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForQueriesSearch handles the response to the QueriesSearch request. The method always +// closes the http.Response Body. +func (c OperationalInsightsClient) responderForQueriesSearch(resp *http.Response) (result QueriesSearchOperationResponse, err error) { + type page struct { + Values []LogAnalyticsQueryPackQuery `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result QueriesSearchOperationResponse, err error) { + req, err := c.preparerForQueriesSearchWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueriesSearch", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueriesSearch", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForQueriesSearch(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueriesSearch", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_queriesupdate_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_queriesupdate_autorest.go new file mode 100644 index 000000000000..8d2380d9c891 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_queriesupdate_autorest.go @@ -0,0 +1,68 @@ +package operationalinsights + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueriesUpdateOperationResponse struct { + HttpResponse *http.Response + Model *LogAnalyticsQueryPackQuery +} + +// QueriesUpdate ... +func (c OperationalInsightsClient) QueriesUpdate(ctx context.Context, id QueriesId, input LogAnalyticsQueryPackQuery) (result QueriesUpdateOperationResponse, err error) { + req, err := c.preparerForQueriesUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueriesUpdate", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueriesUpdate", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForQueriesUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueriesUpdate", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForQueriesUpdate prepares the QueriesUpdate request. +func (c OperationalInsightsClient) preparerForQueriesUpdate(ctx context.Context, id QueriesId, input LogAnalyticsQueryPackQuery) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForQueriesUpdate handles the response to the QueriesUpdate request. The method always +// closes the http.Response Body. +func (c OperationalInsightsClient) responderForQueriesUpdate(resp *http.Response) (result QueriesUpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querypackscreateorupdate_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querypackscreateorupdate_autorest.go new file mode 100644 index 000000000000..5c63cfc96fab --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querypackscreateorupdate_autorest.go @@ -0,0 +1,68 @@ +package operationalinsights + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueryPacksCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + Model *LogAnalyticsQueryPack +} + +// QueryPacksCreateOrUpdate ... +func (c OperationalInsightsClient) QueryPacksCreateOrUpdate(ctx context.Context, id QueryPackId, input LogAnalyticsQueryPack) (result QueryPacksCreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForQueryPacksCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueryPacksCreateOrUpdate", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueryPacksCreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForQueryPacksCreateOrUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueryPacksCreateOrUpdate", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForQueryPacksCreateOrUpdate prepares the QueryPacksCreateOrUpdate request. +func (c OperationalInsightsClient) preparerForQueryPacksCreateOrUpdate(ctx context.Context, id QueryPackId, input LogAnalyticsQueryPack) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForQueryPacksCreateOrUpdate handles the response to the QueryPacksCreateOrUpdate request. The method always +// closes the http.Response Body. +func (c OperationalInsightsClient) responderForQueryPacksCreateOrUpdate(resp *http.Response) (result QueryPacksCreateOrUpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querypacksdelete_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querypacksdelete_autorest.go new file mode 100644 index 000000000000..fd595d13bc48 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querypacksdelete_autorest.go @@ -0,0 +1,65 @@ +package operationalinsights + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueryPacksDeleteOperationResponse struct { + HttpResponse *http.Response +} + +// QueryPacksDelete ... +func (c OperationalInsightsClient) QueryPacksDelete(ctx context.Context, id QueryPackId) (result QueryPacksDeleteOperationResponse, err error) { + req, err := c.preparerForQueryPacksDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueryPacksDelete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueryPacksDelete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForQueryPacksDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueryPacksDelete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForQueryPacksDelete prepares the QueryPacksDelete request. +func (c OperationalInsightsClient) preparerForQueryPacksDelete(ctx context.Context, id QueryPackId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForQueryPacksDelete handles the response to the QueryPacksDelete request. The method always +// closes the http.Response Body. +func (c OperationalInsightsClient) responderForQueryPacksDelete(resp *http.Response) (result QueryPacksDeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querypacksget_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querypacksget_autorest.go new file mode 100644 index 000000000000..072d930b2c2d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querypacksget_autorest.go @@ -0,0 +1,67 @@ +package operationalinsights + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueryPacksGetOperationResponse struct { + HttpResponse *http.Response + Model *LogAnalyticsQueryPack +} + +// QueryPacksGet ... +func (c OperationalInsightsClient) QueryPacksGet(ctx context.Context, id QueryPackId) (result QueryPacksGetOperationResponse, err error) { + req, err := c.preparerForQueryPacksGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueryPacksGet", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueryPacksGet", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForQueryPacksGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueryPacksGet", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForQueryPacksGet prepares the QueryPacksGet request. +func (c OperationalInsightsClient) preparerForQueryPacksGet(ctx context.Context, id QueryPackId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForQueryPacksGet handles the response to the QueryPacksGet request. The method always +// closes the http.Response Body. +func (c OperationalInsightsClient) responderForQueryPacksGet(resp *http.Response) (result QueryPacksGetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querypackslist_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querypackslist_autorest.go new file mode 100644 index 000000000000..579cd4fbb24d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querypackslist_autorest.go @@ -0,0 +1,187 @@ +package operationalinsights + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueryPacksListOperationResponse struct { + HttpResponse *http.Response + Model *[]LogAnalyticsQueryPack + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (QueryPacksListOperationResponse, error) +} + +type QueryPacksListCompleteResult struct { + Items []LogAnalyticsQueryPack +} + +func (r QueryPacksListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r QueryPacksListOperationResponse) LoadMore(ctx context.Context) (resp QueryPacksListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// QueryPacksList ... +func (c OperationalInsightsClient) QueryPacksList(ctx context.Context, id commonids.SubscriptionId) (resp QueryPacksListOperationResponse, err error) { + req, err := c.preparerForQueryPacksList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueryPacksList", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueryPacksList", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForQueryPacksList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueryPacksList", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// QueryPacksListComplete retrieves all of the results into a single object +func (c OperationalInsightsClient) QueryPacksListComplete(ctx context.Context, id commonids.SubscriptionId) (QueryPacksListCompleteResult, error) { + return c.QueryPacksListCompleteMatchingPredicate(ctx, id, LogAnalyticsQueryPackOperationPredicate{}) +} + +// QueryPacksListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c OperationalInsightsClient) QueryPacksListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate LogAnalyticsQueryPackOperationPredicate) (resp QueryPacksListCompleteResult, err error) { + items := make([]LogAnalyticsQueryPack, 0) + + page, err := c.QueryPacksList(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := QueryPacksListCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForQueryPacksList prepares the QueryPacksList request. +func (c OperationalInsightsClient) preparerForQueryPacksList(ctx context.Context, id commonids.SubscriptionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.OperationalInsights/queryPacks", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForQueryPacksListWithNextLink prepares the QueryPacksList request with the given nextLink token. +func (c OperationalInsightsClient) preparerForQueryPacksListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForQueryPacksList handles the response to the QueryPacksList request. The method always +// closes the http.Response Body. +func (c OperationalInsightsClient) responderForQueryPacksList(resp *http.Response) (result QueryPacksListOperationResponse, err error) { + type page struct { + Values []LogAnalyticsQueryPack `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result QueryPacksListOperationResponse, err error) { + req, err := c.preparerForQueryPacksListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueryPacksList", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueryPacksList", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForQueryPacksList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueryPacksList", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querypackslistbyresourcegroup_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querypackslistbyresourcegroup_autorest.go new file mode 100644 index 000000000000..039d8addb9a3 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querypackslistbyresourcegroup_autorest.go @@ -0,0 +1,187 @@ +package operationalinsights + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueryPacksListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + Model *[]LogAnalyticsQueryPack + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (QueryPacksListByResourceGroupOperationResponse, error) +} + +type QueryPacksListByResourceGroupCompleteResult struct { + Items []LogAnalyticsQueryPack +} + +func (r QueryPacksListByResourceGroupOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r QueryPacksListByResourceGroupOperationResponse) LoadMore(ctx context.Context) (resp QueryPacksListByResourceGroupOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// QueryPacksListByResourceGroup ... +func (c OperationalInsightsClient) QueryPacksListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (resp QueryPacksListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForQueryPacksListByResourceGroup(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueryPacksListByResourceGroup", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueryPacksListByResourceGroup", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForQueryPacksListByResourceGroup(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueryPacksListByResourceGroup", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// QueryPacksListByResourceGroupComplete retrieves all of the results into a single object +func (c OperationalInsightsClient) QueryPacksListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (QueryPacksListByResourceGroupCompleteResult, error) { + return c.QueryPacksListByResourceGroupCompleteMatchingPredicate(ctx, id, LogAnalyticsQueryPackOperationPredicate{}) +} + +// QueryPacksListByResourceGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c OperationalInsightsClient) QueryPacksListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate LogAnalyticsQueryPackOperationPredicate) (resp QueryPacksListByResourceGroupCompleteResult, err error) { + items := make([]LogAnalyticsQueryPack, 0) + + page, err := c.QueryPacksListByResourceGroup(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := QueryPacksListByResourceGroupCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForQueryPacksListByResourceGroup prepares the QueryPacksListByResourceGroup request. +func (c OperationalInsightsClient) preparerForQueryPacksListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.OperationalInsights/queryPacks", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForQueryPacksListByResourceGroupWithNextLink prepares the QueryPacksListByResourceGroup request with the given nextLink token. +func (c OperationalInsightsClient) preparerForQueryPacksListByResourceGroupWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForQueryPacksListByResourceGroup handles the response to the QueryPacksListByResourceGroup request. The method always +// closes the http.Response Body. +func (c OperationalInsightsClient) responderForQueryPacksListByResourceGroup(resp *http.Response) (result QueryPacksListByResourceGroupOperationResponse, err error) { + type page struct { + Values []LogAnalyticsQueryPack `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result QueryPacksListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForQueryPacksListByResourceGroupWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueryPacksListByResourceGroup", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueryPacksListByResourceGroup", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForQueryPacksListByResourceGroup(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueryPacksListByResourceGroup", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querypacksupdatetags_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querypacksupdatetags_autorest.go new file mode 100644 index 000000000000..c79573724951 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/method_querypacksupdatetags_autorest.go @@ -0,0 +1,68 @@ +package operationalinsights + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueryPacksUpdateTagsOperationResponse struct { + HttpResponse *http.Response + Model *LogAnalyticsQueryPack +} + +// QueryPacksUpdateTags ... +func (c OperationalInsightsClient) QueryPacksUpdateTags(ctx context.Context, id QueryPackId, input TagsResource) (result QueryPacksUpdateTagsOperationResponse, err error) { + req, err := c.preparerForQueryPacksUpdateTags(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueryPacksUpdateTags", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueryPacksUpdateTags", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForQueryPacksUpdateTags(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "operationalinsights.OperationalInsightsClient", "QueryPacksUpdateTags", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForQueryPacksUpdateTags prepares the QueryPacksUpdateTags request. +func (c OperationalInsightsClient) preparerForQueryPacksUpdateTags(ctx context.Context, id QueryPackId, input TagsResource) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForQueryPacksUpdateTags handles the response to the QueryPacksUpdateTags request. The method always +// closes the http.Response Body. +func (c OperationalInsightsClient) responderForQueryPacksUpdateTags(resp *http.Response) (result QueryPacksUpdateTagsOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypack.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypack.go new file mode 100644 index 000000000000..e57399848453 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypack.go @@ -0,0 +1,13 @@ +package operationalinsights + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LogAnalyticsQueryPack struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties LogAnalyticsQueryPackProperties `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypackproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypackproperties.go new file mode 100644 index 000000000000..1f1a23095fb3 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypackproperties.go @@ -0,0 +1,41 @@ +package operationalinsights + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LogAnalyticsQueryPackProperties struct { + ProvisioningState *string `json:"provisioningState,omitempty"` + QueryPackId *string `json:"queryPackId,omitempty"` + TimeCreated *string `json:"timeCreated,omitempty"` + TimeModified *string `json:"timeModified,omitempty"` +} + +func (o *LogAnalyticsQueryPackProperties) GetTimeCreatedAsTime() (*time.Time, error) { + if o.TimeCreated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.TimeCreated, "2006-01-02T15:04:05Z07:00") +} + +func (o *LogAnalyticsQueryPackProperties) SetTimeCreatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.TimeCreated = &formatted +} + +func (o *LogAnalyticsQueryPackProperties) GetTimeModifiedAsTime() (*time.Time, error) { + if o.TimeModified == nil { + return nil, nil + } + return dates.ParseAsFormat(o.TimeModified, "2006-01-02T15:04:05Z07:00") +} + +func (o *LogAnalyticsQueryPackProperties) SetTimeModifiedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.TimeModified = &formatted +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypackquery.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypackquery.go new file mode 100644 index 000000000000..287060b61cc1 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypackquery.go @@ -0,0 +1,16 @@ +package operationalinsights + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LogAnalyticsQueryPackQuery struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *LogAnalyticsQueryPackQueryProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypackqueryproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypackqueryproperties.go new file mode 100644 index 000000000000..879779960ca4 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypackqueryproperties.go @@ -0,0 +1,47 @@ +package operationalinsights + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LogAnalyticsQueryPackQueryProperties struct { + Author *string `json:"author,omitempty"` + Body string `json:"body"` + Description *string `json:"description,omitempty"` + DisplayName string `json:"displayName"` + Id *string `json:"id,omitempty"` + Properties *interface{} `json:"properties,omitempty"` + Related *LogAnalyticsQueryPackQueryPropertiesRelated `json:"related,omitempty"` + Tags *map[string][]string `json:"tags,omitempty"` + TimeCreated *string `json:"timeCreated,omitempty"` + TimeModified *string `json:"timeModified,omitempty"` +} + +func (o *LogAnalyticsQueryPackQueryProperties) GetTimeCreatedAsTime() (*time.Time, error) { + if o.TimeCreated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.TimeCreated, "2006-01-02T15:04:05Z07:00") +} + +func (o *LogAnalyticsQueryPackQueryProperties) SetTimeCreatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.TimeCreated = &formatted +} + +func (o *LogAnalyticsQueryPackQueryProperties) GetTimeModifiedAsTime() (*time.Time, error) { + if o.TimeModified == nil { + return nil, nil + } + return dates.ParseAsFormat(o.TimeModified, "2006-01-02T15:04:05Z07:00") +} + +func (o *LogAnalyticsQueryPackQueryProperties) SetTimeModifiedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.TimeModified = &formatted +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypackquerypropertiesrelated.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypackquerypropertiesrelated.go new file mode 100644 index 000000000000..af17f38c40bd --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypackquerypropertiesrelated.go @@ -0,0 +1,10 @@ +package operationalinsights + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LogAnalyticsQueryPackQueryPropertiesRelated struct { + Categories *[]string `json:"categories,omitempty"` + ResourceTypes *[]string `json:"resourceTypes,omitempty"` + Solutions *[]string `json:"solutions,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypackquerysearchproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypackquerysearchproperties.go new file mode 100644 index 000000000000..f801bd037f50 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypackquerysearchproperties.go @@ -0,0 +1,9 @@ +package operationalinsights + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LogAnalyticsQueryPackQuerySearchProperties struct { + Related *LogAnalyticsQueryPackQuerySearchPropertiesRelated `json:"related,omitempty"` + Tags *map[string][]string `json:"tags,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypackquerysearchpropertiesrelated.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypackquerysearchpropertiesrelated.go new file mode 100644 index 000000000000..77f06e6f257e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_loganalyticsquerypackquerysearchpropertiesrelated.go @@ -0,0 +1,10 @@ +package operationalinsights + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LogAnalyticsQueryPackQuerySearchPropertiesRelated struct { + Categories *[]string `json:"categories,omitempty"` + ResourceTypes *[]string `json:"resourceTypes,omitempty"` + Solutions *[]string `json:"solutions,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_tagsresource.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_tagsresource.go new file mode 100644 index 000000000000..a3a35998071c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/model_tagsresource.go @@ -0,0 +1,8 @@ +package operationalinsights + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagsResource struct { + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/predicates.go new file mode 100644 index 000000000000..510b201b5b1d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/predicates.go @@ -0,0 +1,52 @@ +package operationalinsights + +type LogAnalyticsQueryPackOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p LogAnalyticsQueryPackOperationPredicate) Matches(input LogAnalyticsQueryPack) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} + +type LogAnalyticsQueryPackQueryOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p LogAnalyticsQueryPackQueryOperationPredicate) Matches(input LogAnalyticsQueryPackQuery) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/version.go new file mode 100644 index 000000000000..c3778597984a --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights/version.go @@ -0,0 +1,12 @@ +package operationalinsights + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2019-09-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/operationalinsights/%s", defaultApiVersion) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 32c4ed43f2b7..a631ee845be1 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -230,6 +230,7 @@ github.com/hashicorp/go-azure-sdk/resource-manager/desktopvirtualization/2021-09 github.com/hashicorp/go-azure-sdk/resource-manager/iotcentral/2021-11-01-preview/apps github.com/hashicorp/go-azure-sdk/resource-manager/notificationhubs/2017-04-01/namespaces github.com/hashicorp/go-azure-sdk/resource-manager/notificationhubs/2017-04-01/notificationhubs +github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2019-09-01/operationalinsights github.com/hashicorp/go-azure-sdk/resource-manager/portal/2019-01-01-preview/dashboard github.com/hashicorp/go-azure-sdk/resource-manager/portal/2019-01-01-preview/tenantconfiguration github.com/hashicorp/go-azure-sdk/resource-manager/web/2016-06-01/connections diff --git a/website/docs/r/log_analytics_query_pack.html.markdown b/website/docs/r/log_analytics_query_pack.html.markdown new file mode 100644 index 000000000000..116fbe8fd528 --- /dev/null +++ b/website/docs/r/log_analytics_query_pack.html.markdown @@ -0,0 +1,63 @@ +--- +subcategory: "Log Analytics" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_log_analytics_query_pack" +description: |- + Manages a Log Analytics Query Pack. +--- + +# azurerm_log_analytics_query_pack + +Manages a Log Analytics Query Pack. + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "example-resources" + location = "West Europe" +} + +resource "azurerm_log_analytics_query_pack" "example" { + name = "example-laqp" + resource_group_name = azurerm_resource_group.example.name + location = azurerm_resource_group.example.location +} +``` + +## Arguments Reference + +The following arguments are supported: + +* `name` - (Required) The name which should be used for this Log Analytics Query Pack. Changing this forces a new resource to be created. + +* `location` - (Required) The Azure Region where the Log Analytics Query Pack should exist. Changing this forces a new resource to be created. + +* `resource_group_name` - (Required) The name of the Resource Group where the Log Analytics Query Pack should exist. Changing this forces a new resource to be created. + +* `tags` - (Optional) A mapping of tags which should be assigned to the Log Analytics Query Pack. + +--- + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `id` - The ID of the Log Analytics Query Pack. + +## 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 Log Analytics Query Pack. +* `read` - (Defaults to 5 minutes) Used when retrieving the Log Analytics Query Pack. +* `update` - (Defaults to 30 minutes) Used when updating the Log Analytics Query Pack. +* `delete` - (Defaults to 30 minutes) Used when deleting the Log Analytics Query Pack. + +## Import + +Log Analytics Query Packs can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_log_analytics_query_pack.example /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.OperationalInsights/queryPacks/queryPack1 +``` From bf8bc6579b00cec73ea020c4837e4633164901c7 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Mon, 27 Jun 2022 16:09:00 +0800 Subject: [PATCH 2/4] update code --- .../services/privatedns/parse/a_record.go | 75 ---------- .../privatedns/parse/a_record_test.go | 128 ------------------ .../services/privatedns/parse/aaaa_record.go | 75 ---------- .../privatedns/parse/aaaa_record_test.go | 128 ------------------ .../services/privatedns/parse/cname_record.go | 75 ---------- .../privatedns/parse/cname_record_test.go | 128 ------------------ .../services/privatedns/parse/mx_record.go | 75 ---------- .../privatedns/parse/mx_record_test.go | 128 ------------------ .../privatedns/parse/private_dns_zone.go | 69 ---------- .../privatedns/parse/private_dns_zone_test.go | 112 --------------- .../services/privatedns/parse/ptr_record.go | 75 ---------- .../privatedns/parse/ptr_record_test.go | 128 ------------------ .../services/privatedns/parse/srv_record.go | 75 ---------- .../privatedns/parse/srv_record_test.go | 128 ------------------ .../services/privatedns/parse/txt_record.go | 75 ---------- .../privatedns/parse/txt_record_test.go | 128 ------------------ .../privatedns/parse/virtual_network_link.go | 75 ---------- .../parse/virtual_network_link_test.go | 128 ------------------ .../privatedns/validate/a_record_id.go | 23 ---- .../privatedns/validate/a_record_id_test.go | 88 ------------ .../privatedns/validate/aaaa_record_id.go | 23 ---- .../validate/aaaa_record_id_test.go | 88 ------------ .../privatedns/validate/cname_record_id.go | 23 ---- .../validate/cname_record_id_test.go | 88 ------------ .../privatedns/validate/mx_record_id.go | 23 ---- .../privatedns/validate/mx_record_id_test.go | 88 ------------ .../validate/private_dns_zone_id.go | 23 ---- .../validate/private_dns_zone_id_test.go | 76 ----------- .../privatedns/validate/ptr_record_id.go | 23 ---- .../privatedns/validate/ptr_record_id_test.go | 88 ------------ .../privatedns/validate/srv_record_id.go | 23 ---- .../privatedns/validate/srv_record_id_test.go | 88 ------------ .../privatedns/validate/txt_record_id.go | 23 ---- .../privatedns/validate/txt_record_id_test.go | 88 ------------ .../validate/virtual_network_link_id.go | 23 ---- .../validate/virtual_network_link_id_test.go | 88 ------------ 36 files changed, 2792 deletions(-) delete mode 100644 internal/services/privatedns/parse/a_record.go delete mode 100644 internal/services/privatedns/parse/a_record_test.go delete mode 100644 internal/services/privatedns/parse/aaaa_record.go delete mode 100644 internal/services/privatedns/parse/aaaa_record_test.go delete mode 100644 internal/services/privatedns/parse/cname_record.go delete mode 100644 internal/services/privatedns/parse/cname_record_test.go delete mode 100644 internal/services/privatedns/parse/mx_record.go delete mode 100644 internal/services/privatedns/parse/mx_record_test.go delete mode 100644 internal/services/privatedns/parse/private_dns_zone.go delete mode 100644 internal/services/privatedns/parse/private_dns_zone_test.go delete mode 100644 internal/services/privatedns/parse/ptr_record.go delete mode 100644 internal/services/privatedns/parse/ptr_record_test.go delete mode 100644 internal/services/privatedns/parse/srv_record.go delete mode 100644 internal/services/privatedns/parse/srv_record_test.go delete mode 100644 internal/services/privatedns/parse/txt_record.go delete mode 100644 internal/services/privatedns/parse/txt_record_test.go delete mode 100644 internal/services/privatedns/parse/virtual_network_link.go delete mode 100644 internal/services/privatedns/parse/virtual_network_link_test.go delete mode 100644 internal/services/privatedns/validate/a_record_id.go delete mode 100644 internal/services/privatedns/validate/a_record_id_test.go delete mode 100644 internal/services/privatedns/validate/aaaa_record_id.go delete mode 100644 internal/services/privatedns/validate/aaaa_record_id_test.go delete mode 100644 internal/services/privatedns/validate/cname_record_id.go delete mode 100644 internal/services/privatedns/validate/cname_record_id_test.go delete mode 100644 internal/services/privatedns/validate/mx_record_id.go delete mode 100644 internal/services/privatedns/validate/mx_record_id_test.go delete mode 100644 internal/services/privatedns/validate/private_dns_zone_id.go delete mode 100644 internal/services/privatedns/validate/private_dns_zone_id_test.go delete mode 100644 internal/services/privatedns/validate/ptr_record_id.go delete mode 100644 internal/services/privatedns/validate/ptr_record_id_test.go delete mode 100644 internal/services/privatedns/validate/srv_record_id.go delete mode 100644 internal/services/privatedns/validate/srv_record_id_test.go delete mode 100644 internal/services/privatedns/validate/txt_record_id.go delete mode 100644 internal/services/privatedns/validate/txt_record_id_test.go delete mode 100644 internal/services/privatedns/validate/virtual_network_link_id.go delete mode 100644 internal/services/privatedns/validate/virtual_network_link_id_test.go diff --git a/internal/services/privatedns/parse/a_record.go b/internal/services/privatedns/parse/a_record.go deleted file mode 100644 index 1ff34aa6ccba..000000000000 --- a/internal/services/privatedns/parse/a_record.go +++ /dev/null @@ -1,75 +0,0 @@ -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 ARecordId struct { - SubscriptionId string - ResourceGroup string - PrivateDnsZoneName string - AName string -} - -func NewARecordID(subscriptionId, resourceGroup, privateDnsZoneName, aName string) ARecordId { - return ARecordId{ - SubscriptionId: subscriptionId, - ResourceGroup: resourceGroup, - PrivateDnsZoneName: privateDnsZoneName, - AName: aName, - } -} - -func (id ARecordId) String() string { - segments := []string{ - fmt.Sprintf("A Name %q", id.AName), - fmt.Sprintf("Private Dns Zone Name %q", id.PrivateDnsZoneName), - fmt.Sprintf("Resource Group %q", id.ResourceGroup), - } - segmentsStr := strings.Join(segments, " / ") - return fmt.Sprintf("%s: (%s)", "A Record", segmentsStr) -} - -func (id ARecordId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/privateDnsZones/%s/A/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.PrivateDnsZoneName, id.AName) -} - -// ARecordID parses a ARecord ID into an ARecordId struct -func ARecordID(input string) (*ARecordId, error) { - id, err := resourceids.ParseAzureResourceID(input) - if err != nil { - return nil, err - } - - resourceId := ARecordId{ - 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.PrivateDnsZoneName, err = id.PopSegment("privateDnsZones"); err != nil { - return nil, err - } - if resourceId.AName, err = id.PopSegment("A"); err != nil { - return nil, err - } - - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err - } - - return &resourceId, nil -} diff --git a/internal/services/privatedns/parse/a_record_test.go b/internal/services/privatedns/parse/a_record_test.go deleted file mode 100644 index 4077882d24ab..000000000000 --- a/internal/services/privatedns/parse/a_record_test.go +++ /dev/null @@ -1,128 +0,0 @@ -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 = ARecordId{} - -func TestARecordIDFormatter(t *testing.T) { - actual := NewARecordID("12345678-1234-9876-4563-123456789012", "resGroup1", "privateDnsZone1", "eh1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/A/eh1" - if actual != expected { - t.Fatalf("Expected %q but got %q", expected, actual) - } -} - -func TestARecordID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *ARecordId - }{ - - { - // 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 PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", - Error: true, - }, - - { - // missing value for PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", - Error: true, - }, - - { - // missing AName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", - Error: true, - }, - - { - // missing value for AName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/A/", - Error: true, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/A/eh1", - Expected: &ARecordId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroup: "resGroup1", - PrivateDnsZoneName: "privateDnsZone1", - AName: "eh1", - }, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/A/EH1", - Error: true, - }, - } - - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ARecordID(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.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { - t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) - } - if actual.AName != v.Expected.AName { - t.Fatalf("Expected %q but got %q for AName", v.Expected.AName, actual.AName) - } - } -} diff --git a/internal/services/privatedns/parse/aaaa_record.go b/internal/services/privatedns/parse/aaaa_record.go deleted file mode 100644 index c44c0d268b87..000000000000 --- a/internal/services/privatedns/parse/aaaa_record.go +++ /dev/null @@ -1,75 +0,0 @@ -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 AaaaRecordId struct { - SubscriptionId string - ResourceGroup string - PrivateDnsZoneName string - AAAAName string -} - -func NewAaaaRecordID(subscriptionId, resourceGroup, privateDnsZoneName, aAAAName string) AaaaRecordId { - return AaaaRecordId{ - SubscriptionId: subscriptionId, - ResourceGroup: resourceGroup, - PrivateDnsZoneName: privateDnsZoneName, - AAAAName: aAAAName, - } -} - -func (id AaaaRecordId) String() string { - segments := []string{ - fmt.Sprintf("A A A A Name %q", id.AAAAName), - fmt.Sprintf("Private Dns Zone Name %q", id.PrivateDnsZoneName), - fmt.Sprintf("Resource Group %q", id.ResourceGroup), - } - segmentsStr := strings.Join(segments, " / ") - return fmt.Sprintf("%s: (%s)", "Aaaa Record", segmentsStr) -} - -func (id AaaaRecordId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/privateDnsZones/%s/AAAA/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.PrivateDnsZoneName, id.AAAAName) -} - -// AaaaRecordID parses a AaaaRecord ID into an AaaaRecordId struct -func AaaaRecordID(input string) (*AaaaRecordId, error) { - id, err := resourceids.ParseAzureResourceID(input) - if err != nil { - return nil, err - } - - resourceId := AaaaRecordId{ - 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.PrivateDnsZoneName, err = id.PopSegment("privateDnsZones"); err != nil { - return nil, err - } - if resourceId.AAAAName, err = id.PopSegment("AAAA"); err != nil { - return nil, err - } - - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err - } - - return &resourceId, nil -} diff --git a/internal/services/privatedns/parse/aaaa_record_test.go b/internal/services/privatedns/parse/aaaa_record_test.go deleted file mode 100644 index 3d61bf94feac..000000000000 --- a/internal/services/privatedns/parse/aaaa_record_test.go +++ /dev/null @@ -1,128 +0,0 @@ -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 = AaaaRecordId{} - -func TestAaaaRecordIDFormatter(t *testing.T) { - actual := NewAaaaRecordID("12345678-1234-9876-4563-123456789012", "resGroup1", "privateDnsZone1", "eheh1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/AAAA/eheh1" - if actual != expected { - t.Fatalf("Expected %q but got %q", expected, actual) - } -} - -func TestAaaaRecordID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *AaaaRecordId - }{ - - { - // 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 PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", - Error: true, - }, - - { - // missing value for PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", - Error: true, - }, - - { - // missing AAAAName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", - Error: true, - }, - - { - // missing value for AAAAName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/AAAA/", - Error: true, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/AAAA/eheh1", - Expected: &AaaaRecordId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroup: "resGroup1", - PrivateDnsZoneName: "privateDnsZone1", - AAAAName: "eheh1", - }, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/AAAA/EHEH1", - Error: true, - }, - } - - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := AaaaRecordID(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.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { - t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) - } - if actual.AAAAName != v.Expected.AAAAName { - t.Fatalf("Expected %q but got %q for AAAAName", v.Expected.AAAAName, actual.AAAAName) - } - } -} diff --git a/internal/services/privatedns/parse/cname_record.go b/internal/services/privatedns/parse/cname_record.go deleted file mode 100644 index 52de00de2a71..000000000000 --- a/internal/services/privatedns/parse/cname_record.go +++ /dev/null @@ -1,75 +0,0 @@ -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 CnameRecordId struct { - SubscriptionId string - ResourceGroup string - PrivateDnsZoneName string - CNAMEName string -} - -func NewCnameRecordID(subscriptionId, resourceGroup, privateDnsZoneName, cNAMEName string) CnameRecordId { - return CnameRecordId{ - SubscriptionId: subscriptionId, - ResourceGroup: resourceGroup, - PrivateDnsZoneName: privateDnsZoneName, - CNAMEName: cNAMEName, - } -} - -func (id CnameRecordId) String() string { - segments := []string{ - fmt.Sprintf("C N A M E Name %q", id.CNAMEName), - fmt.Sprintf("Private Dns Zone Name %q", id.PrivateDnsZoneName), - fmt.Sprintf("Resource Group %q", id.ResourceGroup), - } - segmentsStr := strings.Join(segments, " / ") - return fmt.Sprintf("%s: (%s)", "Cname Record", segmentsStr) -} - -func (id CnameRecordId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/privateDnsZones/%s/CNAME/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.PrivateDnsZoneName, id.CNAMEName) -} - -// CnameRecordID parses a CnameRecord ID into an CnameRecordId struct -func CnameRecordID(input string) (*CnameRecordId, error) { - id, err := resourceids.ParseAzureResourceID(input) - if err != nil { - return nil, err - } - - resourceId := CnameRecordId{ - 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.PrivateDnsZoneName, err = id.PopSegment("privateDnsZones"); err != nil { - return nil, err - } - if resourceId.CNAMEName, err = id.PopSegment("CNAME"); err != nil { - return nil, err - } - - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err - } - - return &resourceId, nil -} diff --git a/internal/services/privatedns/parse/cname_record_test.go b/internal/services/privatedns/parse/cname_record_test.go deleted file mode 100644 index 5d18f58e25a2..000000000000 --- a/internal/services/privatedns/parse/cname_record_test.go +++ /dev/null @@ -1,128 +0,0 @@ -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 = CnameRecordId{} - -func TestCnameRecordIDFormatter(t *testing.T) { - actual := NewCnameRecordID("12345678-1234-9876-4563-123456789012", "resGroup1", "privateDnsZone1", "name1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/CNAME/name1" - if actual != expected { - t.Fatalf("Expected %q but got %q", expected, actual) - } -} - -func TestCnameRecordID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *CnameRecordId - }{ - - { - // 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 PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", - Error: true, - }, - - { - // missing value for PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", - Error: true, - }, - - { - // missing CNAMEName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", - Error: true, - }, - - { - // missing value for CNAMEName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/CNAME/", - Error: true, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/CNAME/name1", - Expected: &CnameRecordId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroup: "resGroup1", - PrivateDnsZoneName: "privateDnsZone1", - CNAMEName: "name1", - }, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/CNAME/NAME1", - Error: true, - }, - } - - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := CnameRecordID(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.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { - t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) - } - if actual.CNAMEName != v.Expected.CNAMEName { - t.Fatalf("Expected %q but got %q for CNAMEName", v.Expected.CNAMEName, actual.CNAMEName) - } - } -} diff --git a/internal/services/privatedns/parse/mx_record.go b/internal/services/privatedns/parse/mx_record.go deleted file mode 100644 index b753efdf2bef..000000000000 --- a/internal/services/privatedns/parse/mx_record.go +++ /dev/null @@ -1,75 +0,0 @@ -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 MxRecordId struct { - SubscriptionId string - ResourceGroup string - PrivateDnsZoneName string - MXName string -} - -func NewMxRecordID(subscriptionId, resourceGroup, privateDnsZoneName, mXName string) MxRecordId { - return MxRecordId{ - SubscriptionId: subscriptionId, - ResourceGroup: resourceGroup, - PrivateDnsZoneName: privateDnsZoneName, - MXName: mXName, - } -} - -func (id MxRecordId) String() string { - segments := []string{ - fmt.Sprintf("M X Name %q", id.MXName), - fmt.Sprintf("Private Dns Zone Name %q", id.PrivateDnsZoneName), - fmt.Sprintf("Resource Group %q", id.ResourceGroup), - } - segmentsStr := strings.Join(segments, " / ") - return fmt.Sprintf("%s: (%s)", "Mx Record", segmentsStr) -} - -func (id MxRecordId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/privateDnsZones/%s/MX/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.PrivateDnsZoneName, id.MXName) -} - -// MxRecordID parses a MxRecord ID into an MxRecordId struct -func MxRecordID(input string) (*MxRecordId, error) { - id, err := resourceids.ParseAzureResourceID(input) - if err != nil { - return nil, err - } - - resourceId := MxRecordId{ - 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.PrivateDnsZoneName, err = id.PopSegment("privateDnsZones"); err != nil { - return nil, err - } - if resourceId.MXName, err = id.PopSegment("MX"); err != nil { - return nil, err - } - - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err - } - - return &resourceId, nil -} diff --git a/internal/services/privatedns/parse/mx_record_test.go b/internal/services/privatedns/parse/mx_record_test.go deleted file mode 100644 index 3bd9befb8250..000000000000 --- a/internal/services/privatedns/parse/mx_record_test.go +++ /dev/null @@ -1,128 +0,0 @@ -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 = MxRecordId{} - -func TestMxRecordIDFormatter(t *testing.T) { - actual := NewMxRecordID("12345678-1234-9876-4563-123456789012", "resGroup1", "privateDnsZone1", "mx1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/MX/mx1" - if actual != expected { - t.Fatalf("Expected %q but got %q", expected, actual) - } -} - -func TestMxRecordID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *MxRecordId - }{ - - { - // 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 PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", - Error: true, - }, - - { - // missing value for PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", - Error: true, - }, - - { - // missing MXName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", - Error: true, - }, - - { - // missing value for MXName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/MX/", - Error: true, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/MX/mx1", - Expected: &MxRecordId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroup: "resGroup1", - PrivateDnsZoneName: "privateDnsZone1", - MXName: "mx1", - }, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/MX/MX1", - Error: true, - }, - } - - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := MxRecordID(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.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { - t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) - } - if actual.MXName != v.Expected.MXName { - t.Fatalf("Expected %q but got %q for MXName", v.Expected.MXName, actual.MXName) - } - } -} diff --git a/internal/services/privatedns/parse/private_dns_zone.go b/internal/services/privatedns/parse/private_dns_zone.go deleted file mode 100644 index 7ed4f6f732b6..000000000000 --- a/internal/services/privatedns/parse/private_dns_zone.go +++ /dev/null @@ -1,69 +0,0 @@ -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 PrivateDnsZoneId struct { - SubscriptionId string - ResourceGroup string - Name string -} - -func NewPrivateDnsZoneID(subscriptionId, resourceGroup, name string) PrivateDnsZoneId { - return PrivateDnsZoneId{ - SubscriptionId: subscriptionId, - ResourceGroup: resourceGroup, - Name: name, - } -} - -func (id PrivateDnsZoneId) String() string { - segments := []string{ - fmt.Sprintf("Name %q", id.Name), - fmt.Sprintf("Resource Group %q", id.ResourceGroup), - } - segmentsStr := strings.Join(segments, " / ") - return fmt.Sprintf("%s: (%s)", "Private Dns Zone", segmentsStr) -} - -func (id PrivateDnsZoneId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/privateDnsZones/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.Name) -} - -// PrivateDnsZoneID parses a PrivateDnsZone ID into an PrivateDnsZoneId struct -func PrivateDnsZoneID(input string) (*PrivateDnsZoneId, error) { - id, err := resourceids.ParseAzureResourceID(input) - if err != nil { - return nil, err - } - - resourceId := PrivateDnsZoneId{ - 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.Name, err = id.PopSegment("privateDnsZones"); err != nil { - return nil, err - } - - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err - } - - return &resourceId, nil -} diff --git a/internal/services/privatedns/parse/private_dns_zone_test.go b/internal/services/privatedns/parse/private_dns_zone_test.go deleted file mode 100644 index 6edb3569ca4c..000000000000 --- a/internal/services/privatedns/parse/private_dns_zone_test.go +++ /dev/null @@ -1,112 +0,0 @@ -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 = PrivateDnsZoneId{} - -func TestPrivateDnsZoneIDFormatter(t *testing.T) { - actual := NewPrivateDnsZoneID("12345678-1234-9876-4563-123456789012", "resGroup1", "privateDnsZone1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1" - if actual != expected { - t.Fatalf("Expected %q but got %q", expected, actual) - } -} - -func TestPrivateDnsZoneID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *PrivateDnsZoneId - }{ - - { - // 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 Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", - Error: true, - }, - - { - // missing value for Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", - Error: true, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1", - Expected: &PrivateDnsZoneId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroup: "resGroup1", - Name: "privateDnsZone1", - }, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1", - Error: true, - }, - } - - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := PrivateDnsZoneID(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.Name != v.Expected.Name { - t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) - } - } -} diff --git a/internal/services/privatedns/parse/ptr_record.go b/internal/services/privatedns/parse/ptr_record.go deleted file mode 100644 index c665609f92f5..000000000000 --- a/internal/services/privatedns/parse/ptr_record.go +++ /dev/null @@ -1,75 +0,0 @@ -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 PtrRecordId struct { - SubscriptionId string - ResourceGroup string - PrivateDnsZoneName string - PTRName string -} - -func NewPtrRecordID(subscriptionId, resourceGroup, privateDnsZoneName, pTRName string) PtrRecordId { - return PtrRecordId{ - SubscriptionId: subscriptionId, - ResourceGroup: resourceGroup, - PrivateDnsZoneName: privateDnsZoneName, - PTRName: pTRName, - } -} - -func (id PtrRecordId) String() string { - segments := []string{ - fmt.Sprintf("P T R Name %q", id.PTRName), - fmt.Sprintf("Private Dns Zone Name %q", id.PrivateDnsZoneName), - fmt.Sprintf("Resource Group %q", id.ResourceGroup), - } - segmentsStr := strings.Join(segments, " / ") - return fmt.Sprintf("%s: (%s)", "Ptr Record", segmentsStr) -} - -func (id PtrRecordId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/privateDnsZones/%s/PTR/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.PrivateDnsZoneName, id.PTRName) -} - -// PtrRecordID parses a PtrRecord ID into an PtrRecordId struct -func PtrRecordID(input string) (*PtrRecordId, error) { - id, err := resourceids.ParseAzureResourceID(input) - if err != nil { - return nil, err - } - - resourceId := PtrRecordId{ - 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.PrivateDnsZoneName, err = id.PopSegment("privateDnsZones"); err != nil { - return nil, err - } - if resourceId.PTRName, err = id.PopSegment("PTR"); err != nil { - return nil, err - } - - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err - } - - return &resourceId, nil -} diff --git a/internal/services/privatedns/parse/ptr_record_test.go b/internal/services/privatedns/parse/ptr_record_test.go deleted file mode 100644 index b16c62f84ae2..000000000000 --- a/internal/services/privatedns/parse/ptr_record_test.go +++ /dev/null @@ -1,128 +0,0 @@ -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 = PtrRecordId{} - -func TestPtrRecordIDFormatter(t *testing.T) { - actual := NewPtrRecordID("12345678-1234-9876-4563-123456789012", "resGroup1", "privateDnsZone1", "ptr1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/PTR/ptr1" - if actual != expected { - t.Fatalf("Expected %q but got %q", expected, actual) - } -} - -func TestPtrRecordID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *PtrRecordId - }{ - - { - // 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 PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", - Error: true, - }, - - { - // missing value for PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", - Error: true, - }, - - { - // missing PTRName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", - Error: true, - }, - - { - // missing value for PTRName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/PTR/", - Error: true, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/PTR/ptr1", - Expected: &PtrRecordId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroup: "resGroup1", - PrivateDnsZoneName: "privateDnsZone1", - PTRName: "ptr1", - }, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/PTR/PTR1", - Error: true, - }, - } - - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := PtrRecordID(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.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { - t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) - } - if actual.PTRName != v.Expected.PTRName { - t.Fatalf("Expected %q but got %q for PTRName", v.Expected.PTRName, actual.PTRName) - } - } -} diff --git a/internal/services/privatedns/parse/srv_record.go b/internal/services/privatedns/parse/srv_record.go deleted file mode 100644 index 9dffad560e73..000000000000 --- a/internal/services/privatedns/parse/srv_record.go +++ /dev/null @@ -1,75 +0,0 @@ -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 SrvRecordId struct { - SubscriptionId string - ResourceGroup string - PrivateDnsZoneName string - SRVName string -} - -func NewSrvRecordID(subscriptionId, resourceGroup, privateDnsZoneName, sRVName string) SrvRecordId { - return SrvRecordId{ - SubscriptionId: subscriptionId, - ResourceGroup: resourceGroup, - PrivateDnsZoneName: privateDnsZoneName, - SRVName: sRVName, - } -} - -func (id SrvRecordId) String() string { - segments := []string{ - fmt.Sprintf("S R V Name %q", id.SRVName), - fmt.Sprintf("Private Dns Zone Name %q", id.PrivateDnsZoneName), - fmt.Sprintf("Resource Group %q", id.ResourceGroup), - } - segmentsStr := strings.Join(segments, " / ") - return fmt.Sprintf("%s: (%s)", "Srv Record", segmentsStr) -} - -func (id SrvRecordId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/privateDnsZones/%s/SRV/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.PrivateDnsZoneName, id.SRVName) -} - -// SrvRecordID parses a SrvRecord ID into an SrvRecordId struct -func SrvRecordID(input string) (*SrvRecordId, error) { - id, err := resourceids.ParseAzureResourceID(input) - if err != nil { - return nil, err - } - - resourceId := SrvRecordId{ - 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.PrivateDnsZoneName, err = id.PopSegment("privateDnsZones"); err != nil { - return nil, err - } - if resourceId.SRVName, err = id.PopSegment("SRV"); err != nil { - return nil, err - } - - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err - } - - return &resourceId, nil -} diff --git a/internal/services/privatedns/parse/srv_record_test.go b/internal/services/privatedns/parse/srv_record_test.go deleted file mode 100644 index 2fceda33a896..000000000000 --- a/internal/services/privatedns/parse/srv_record_test.go +++ /dev/null @@ -1,128 +0,0 @@ -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 = SrvRecordId{} - -func TestSrvRecordIDFormatter(t *testing.T) { - actual := NewSrvRecordID("12345678-1234-9876-4563-123456789012", "resGroup1", "privateDnsZone1", "srv1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/SRV/srv1" - if actual != expected { - t.Fatalf("Expected %q but got %q", expected, actual) - } -} - -func TestSrvRecordID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *SrvRecordId - }{ - - { - // 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 PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", - Error: true, - }, - - { - // missing value for PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", - Error: true, - }, - - { - // missing SRVName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", - Error: true, - }, - - { - // missing value for SRVName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/SRV/", - Error: true, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/SRV/srv1", - Expected: &SrvRecordId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroup: "resGroup1", - PrivateDnsZoneName: "privateDnsZone1", - SRVName: "srv1", - }, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/SRV/SRV1", - Error: true, - }, - } - - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := SrvRecordID(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.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { - t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) - } - if actual.SRVName != v.Expected.SRVName { - t.Fatalf("Expected %q but got %q for SRVName", v.Expected.SRVName, actual.SRVName) - } - } -} diff --git a/internal/services/privatedns/parse/txt_record.go b/internal/services/privatedns/parse/txt_record.go deleted file mode 100644 index 3eb8a1ba999a..000000000000 --- a/internal/services/privatedns/parse/txt_record.go +++ /dev/null @@ -1,75 +0,0 @@ -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 TxtRecordId struct { - SubscriptionId string - ResourceGroup string - PrivateDnsZoneName string - TXTName string -} - -func NewTxtRecordID(subscriptionId, resourceGroup, privateDnsZoneName, tXTName string) TxtRecordId { - return TxtRecordId{ - SubscriptionId: subscriptionId, - ResourceGroup: resourceGroup, - PrivateDnsZoneName: privateDnsZoneName, - TXTName: tXTName, - } -} - -func (id TxtRecordId) String() string { - segments := []string{ - fmt.Sprintf("T X T Name %q", id.TXTName), - fmt.Sprintf("Private Dns Zone Name %q", id.PrivateDnsZoneName), - fmt.Sprintf("Resource Group %q", id.ResourceGroup), - } - segmentsStr := strings.Join(segments, " / ") - return fmt.Sprintf("%s: (%s)", "Txt Record", segmentsStr) -} - -func (id TxtRecordId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/privateDnsZones/%s/TXT/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.PrivateDnsZoneName, id.TXTName) -} - -// TxtRecordID parses a TxtRecord ID into an TxtRecordId struct -func TxtRecordID(input string) (*TxtRecordId, error) { - id, err := resourceids.ParseAzureResourceID(input) - if err != nil { - return nil, err - } - - resourceId := TxtRecordId{ - 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.PrivateDnsZoneName, err = id.PopSegment("privateDnsZones"); err != nil { - return nil, err - } - if resourceId.TXTName, err = id.PopSegment("TXT"); err != nil { - return nil, err - } - - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err - } - - return &resourceId, nil -} diff --git a/internal/services/privatedns/parse/txt_record_test.go b/internal/services/privatedns/parse/txt_record_test.go deleted file mode 100644 index 4947041f9006..000000000000 --- a/internal/services/privatedns/parse/txt_record_test.go +++ /dev/null @@ -1,128 +0,0 @@ -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 = TxtRecordId{} - -func TestTxtRecordIDFormatter(t *testing.T) { - actual := NewTxtRecordID("12345678-1234-9876-4563-123456789012", "resGroup1", "privateDnsZone1", "txt1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/TXT/txt1" - if actual != expected { - t.Fatalf("Expected %q but got %q", expected, actual) - } -} - -func TestTxtRecordID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *TxtRecordId - }{ - - { - // 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 PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", - Error: true, - }, - - { - // missing value for PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", - Error: true, - }, - - { - // missing TXTName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", - Error: true, - }, - - { - // missing value for TXTName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/TXT/", - Error: true, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/TXT/txt1", - Expected: &TxtRecordId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroup: "resGroup1", - PrivateDnsZoneName: "privateDnsZone1", - TXTName: "txt1", - }, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/TXT/TXT1", - Error: true, - }, - } - - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := TxtRecordID(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.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { - t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) - } - if actual.TXTName != v.Expected.TXTName { - t.Fatalf("Expected %q but got %q for TXTName", v.Expected.TXTName, actual.TXTName) - } - } -} diff --git a/internal/services/privatedns/parse/virtual_network_link.go b/internal/services/privatedns/parse/virtual_network_link.go deleted file mode 100644 index 7ca1c96fdb84..000000000000 --- a/internal/services/privatedns/parse/virtual_network_link.go +++ /dev/null @@ -1,75 +0,0 @@ -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 VirtualNetworkLinkId struct { - SubscriptionId string - ResourceGroup string - PrivateDnsZoneName string - Name string -} - -func NewVirtualNetworkLinkID(subscriptionId, resourceGroup, privateDnsZoneName, name string) VirtualNetworkLinkId { - return VirtualNetworkLinkId{ - SubscriptionId: subscriptionId, - ResourceGroup: resourceGroup, - PrivateDnsZoneName: privateDnsZoneName, - Name: name, - } -} - -func (id VirtualNetworkLinkId) String() string { - segments := []string{ - fmt.Sprintf("Name %q", id.Name), - fmt.Sprintf("Private Dns Zone Name %q", id.PrivateDnsZoneName), - fmt.Sprintf("Resource Group %q", id.ResourceGroup), - } - segmentsStr := strings.Join(segments, " / ") - return fmt.Sprintf("%s: (%s)", "Virtual Network Link", segmentsStr) -} - -func (id VirtualNetworkLinkId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/privateDnsZones/%s/virtualNetworkLinks/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.PrivateDnsZoneName, id.Name) -} - -// VirtualNetworkLinkID parses a VirtualNetworkLink ID into an VirtualNetworkLinkId struct -func VirtualNetworkLinkID(input string) (*VirtualNetworkLinkId, error) { - id, err := resourceids.ParseAzureResourceID(input) - if err != nil { - return nil, err - } - - resourceId := VirtualNetworkLinkId{ - 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.PrivateDnsZoneName, err = id.PopSegment("privateDnsZones"); err != nil { - return nil, err - } - if resourceId.Name, err = id.PopSegment("virtualNetworkLinks"); err != nil { - return nil, err - } - - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err - } - - return &resourceId, nil -} diff --git a/internal/services/privatedns/parse/virtual_network_link_test.go b/internal/services/privatedns/parse/virtual_network_link_test.go deleted file mode 100644 index 1f45b56b1b67..000000000000 --- a/internal/services/privatedns/parse/virtual_network_link_test.go +++ /dev/null @@ -1,128 +0,0 @@ -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 = VirtualNetworkLinkId{} - -func TestVirtualNetworkLinkIDFormatter(t *testing.T) { - actual := NewVirtualNetworkLinkID("12345678-1234-9876-4563-123456789012", "resGroup1", "privateDnsZone1", "virtualNetworkLink1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/virtualNetworkLinks/virtualNetworkLink1" - if actual != expected { - t.Fatalf("Expected %q but got %q", expected, actual) - } -} - -func TestVirtualNetworkLinkID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *VirtualNetworkLinkId - }{ - - { - // 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 PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", - Error: true, - }, - - { - // missing value for PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", - Error: true, - }, - - { - // missing Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", - Error: true, - }, - - { - // missing value for Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/virtualNetworkLinks/", - Error: true, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/virtualNetworkLinks/virtualNetworkLink1", - Expected: &VirtualNetworkLinkId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroup: "resGroup1", - PrivateDnsZoneName: "privateDnsZone1", - Name: "virtualNetworkLink1", - }, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/VIRTUALNETWORKLINKS/VIRTUALNETWORKLINK1", - Error: true, - }, - } - - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := VirtualNetworkLinkID(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.PrivateDnsZoneName != v.Expected.PrivateDnsZoneName { - t.Fatalf("Expected %q but got %q for PrivateDnsZoneName", v.Expected.PrivateDnsZoneName, actual.PrivateDnsZoneName) - } - if actual.Name != v.Expected.Name { - t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) - } - } -} diff --git a/internal/services/privatedns/validate/a_record_id.go b/internal/services/privatedns/validate/a_record_id.go deleted file mode 100644 index 82a9bc624088..000000000000 --- a/internal/services/privatedns/validate/a_record_id.go +++ /dev/null @@ -1,23 +0,0 @@ -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/privatedns/parse" -) - -func ARecordID(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.ARecordID(v); err != nil { - errors = append(errors, err) - } - - return -} diff --git a/internal/services/privatedns/validate/a_record_id_test.go b/internal/services/privatedns/validate/a_record_id_test.go deleted file mode 100644 index 137de55ed200..000000000000 --- a/internal/services/privatedns/validate/a_record_id_test.go +++ /dev/null @@ -1,88 +0,0 @@ -package validate - -// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten - -import "testing" - -func TestARecordID(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 PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", - Valid: false, - }, - - { - // missing value for PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", - Valid: false, - }, - - { - // missing AName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", - Valid: false, - }, - - { - // missing value for AName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/A/", - Valid: false, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/A/eh1", - Valid: true, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/A/EH1", - Valid: false, - }, - } - for _, tc := range cases { - t.Logf("[DEBUG] Testing Value %s", tc.Input) - _, errors := ARecordID(tc.Input, "test") - valid := len(errors) == 0 - - if tc.Valid != valid { - t.Fatalf("Expected %t but got %t", tc.Valid, valid) - } - } -} diff --git a/internal/services/privatedns/validate/aaaa_record_id.go b/internal/services/privatedns/validate/aaaa_record_id.go deleted file mode 100644 index 4a793181f711..000000000000 --- a/internal/services/privatedns/validate/aaaa_record_id.go +++ /dev/null @@ -1,23 +0,0 @@ -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/privatedns/parse" -) - -func AaaaRecordID(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.AaaaRecordID(v); err != nil { - errors = append(errors, err) - } - - return -} diff --git a/internal/services/privatedns/validate/aaaa_record_id_test.go b/internal/services/privatedns/validate/aaaa_record_id_test.go deleted file mode 100644 index 722ad2db77dd..000000000000 --- a/internal/services/privatedns/validate/aaaa_record_id_test.go +++ /dev/null @@ -1,88 +0,0 @@ -package validate - -// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten - -import "testing" - -func TestAaaaRecordID(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 PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", - Valid: false, - }, - - { - // missing value for PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", - Valid: false, - }, - - { - // missing AAAAName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", - Valid: false, - }, - - { - // missing value for AAAAName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/AAAA/", - Valid: false, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/AAAA/eheh1", - Valid: true, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/AAAA/EHEH1", - Valid: false, - }, - } - for _, tc := range cases { - t.Logf("[DEBUG] Testing Value %s", tc.Input) - _, errors := AaaaRecordID(tc.Input, "test") - valid := len(errors) == 0 - - if tc.Valid != valid { - t.Fatalf("Expected %t but got %t", tc.Valid, valid) - } - } -} diff --git a/internal/services/privatedns/validate/cname_record_id.go b/internal/services/privatedns/validate/cname_record_id.go deleted file mode 100644 index e7ba85b94910..000000000000 --- a/internal/services/privatedns/validate/cname_record_id.go +++ /dev/null @@ -1,23 +0,0 @@ -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/privatedns/parse" -) - -func CnameRecordID(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.CnameRecordID(v); err != nil { - errors = append(errors, err) - } - - return -} diff --git a/internal/services/privatedns/validate/cname_record_id_test.go b/internal/services/privatedns/validate/cname_record_id_test.go deleted file mode 100644 index 0a36d0a361f7..000000000000 --- a/internal/services/privatedns/validate/cname_record_id_test.go +++ /dev/null @@ -1,88 +0,0 @@ -package validate - -// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten - -import "testing" - -func TestCnameRecordID(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 PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", - Valid: false, - }, - - { - // missing value for PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", - Valid: false, - }, - - { - // missing CNAMEName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", - Valid: false, - }, - - { - // missing value for CNAMEName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/CNAME/", - Valid: false, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/CNAME/name1", - Valid: true, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/CNAME/NAME1", - Valid: false, - }, - } - for _, tc := range cases { - t.Logf("[DEBUG] Testing Value %s", tc.Input) - _, errors := CnameRecordID(tc.Input, "test") - valid := len(errors) == 0 - - if tc.Valid != valid { - t.Fatalf("Expected %t but got %t", tc.Valid, valid) - } - } -} diff --git a/internal/services/privatedns/validate/mx_record_id.go b/internal/services/privatedns/validate/mx_record_id.go deleted file mode 100644 index 101ee7ae365b..000000000000 --- a/internal/services/privatedns/validate/mx_record_id.go +++ /dev/null @@ -1,23 +0,0 @@ -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/privatedns/parse" -) - -func MxRecordID(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.MxRecordID(v); err != nil { - errors = append(errors, err) - } - - return -} diff --git a/internal/services/privatedns/validate/mx_record_id_test.go b/internal/services/privatedns/validate/mx_record_id_test.go deleted file mode 100644 index 3856df0dd637..000000000000 --- a/internal/services/privatedns/validate/mx_record_id_test.go +++ /dev/null @@ -1,88 +0,0 @@ -package validate - -// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten - -import "testing" - -func TestMxRecordID(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 PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", - Valid: false, - }, - - { - // missing value for PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", - Valid: false, - }, - - { - // missing MXName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", - Valid: false, - }, - - { - // missing value for MXName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/MX/", - Valid: false, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/MX/mx1", - Valid: true, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/MX/MX1", - Valid: false, - }, - } - for _, tc := range cases { - t.Logf("[DEBUG] Testing Value %s", tc.Input) - _, errors := MxRecordID(tc.Input, "test") - valid := len(errors) == 0 - - if tc.Valid != valid { - t.Fatalf("Expected %t but got %t", tc.Valid, valid) - } - } -} diff --git a/internal/services/privatedns/validate/private_dns_zone_id.go b/internal/services/privatedns/validate/private_dns_zone_id.go deleted file mode 100644 index fc812dc9d7bb..000000000000 --- a/internal/services/privatedns/validate/private_dns_zone_id.go +++ /dev/null @@ -1,23 +0,0 @@ -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/privatedns/parse" -) - -func PrivateDnsZoneID(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.PrivateDnsZoneID(v); err != nil { - errors = append(errors, err) - } - - return -} diff --git a/internal/services/privatedns/validate/private_dns_zone_id_test.go b/internal/services/privatedns/validate/private_dns_zone_id_test.go deleted file mode 100644 index 273feaa285b2..000000000000 --- a/internal/services/privatedns/validate/private_dns_zone_id_test.go +++ /dev/null @@ -1,76 +0,0 @@ -package validate - -// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten - -import "testing" - -func TestPrivateDnsZoneID(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 Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", - Valid: false, - }, - - { - // missing value for Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", - Valid: false, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1", - Valid: true, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1", - Valid: false, - }, - } - for _, tc := range cases { - t.Logf("[DEBUG] Testing Value %s", tc.Input) - _, errors := PrivateDnsZoneID(tc.Input, "test") - valid := len(errors) == 0 - - if tc.Valid != valid { - t.Fatalf("Expected %t but got %t", tc.Valid, valid) - } - } -} diff --git a/internal/services/privatedns/validate/ptr_record_id.go b/internal/services/privatedns/validate/ptr_record_id.go deleted file mode 100644 index b135102f829b..000000000000 --- a/internal/services/privatedns/validate/ptr_record_id.go +++ /dev/null @@ -1,23 +0,0 @@ -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/privatedns/parse" -) - -func PtrRecordID(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.PtrRecordID(v); err != nil { - errors = append(errors, err) - } - - return -} diff --git a/internal/services/privatedns/validate/ptr_record_id_test.go b/internal/services/privatedns/validate/ptr_record_id_test.go deleted file mode 100644 index 8170964a3ba4..000000000000 --- a/internal/services/privatedns/validate/ptr_record_id_test.go +++ /dev/null @@ -1,88 +0,0 @@ -package validate - -// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten - -import "testing" - -func TestPtrRecordID(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 PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", - Valid: false, - }, - - { - // missing value for PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", - Valid: false, - }, - - { - // missing PTRName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", - Valid: false, - }, - - { - // missing value for PTRName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/PTR/", - Valid: false, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/PTR/ptr1", - Valid: true, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/PTR/PTR1", - Valid: false, - }, - } - for _, tc := range cases { - t.Logf("[DEBUG] Testing Value %s", tc.Input) - _, errors := PtrRecordID(tc.Input, "test") - valid := len(errors) == 0 - - if tc.Valid != valid { - t.Fatalf("Expected %t but got %t", tc.Valid, valid) - } - } -} diff --git a/internal/services/privatedns/validate/srv_record_id.go b/internal/services/privatedns/validate/srv_record_id.go deleted file mode 100644 index 0ee85e416de3..000000000000 --- a/internal/services/privatedns/validate/srv_record_id.go +++ /dev/null @@ -1,23 +0,0 @@ -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/privatedns/parse" -) - -func SrvRecordID(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.SrvRecordID(v); err != nil { - errors = append(errors, err) - } - - return -} diff --git a/internal/services/privatedns/validate/srv_record_id_test.go b/internal/services/privatedns/validate/srv_record_id_test.go deleted file mode 100644 index cc109ab8cf5b..000000000000 --- a/internal/services/privatedns/validate/srv_record_id_test.go +++ /dev/null @@ -1,88 +0,0 @@ -package validate - -// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten - -import "testing" - -func TestSrvRecordID(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 PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", - Valid: false, - }, - - { - // missing value for PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", - Valid: false, - }, - - { - // missing SRVName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", - Valid: false, - }, - - { - // missing value for SRVName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/SRV/", - Valid: false, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/SRV/srv1", - Valid: true, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/SRV/SRV1", - Valid: false, - }, - } - for _, tc := range cases { - t.Logf("[DEBUG] Testing Value %s", tc.Input) - _, errors := SrvRecordID(tc.Input, "test") - valid := len(errors) == 0 - - if tc.Valid != valid { - t.Fatalf("Expected %t but got %t", tc.Valid, valid) - } - } -} diff --git a/internal/services/privatedns/validate/txt_record_id.go b/internal/services/privatedns/validate/txt_record_id.go deleted file mode 100644 index 8e9b0c9dfcfb..000000000000 --- a/internal/services/privatedns/validate/txt_record_id.go +++ /dev/null @@ -1,23 +0,0 @@ -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/privatedns/parse" -) - -func TxtRecordID(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.TxtRecordID(v); err != nil { - errors = append(errors, err) - } - - return -} diff --git a/internal/services/privatedns/validate/txt_record_id_test.go b/internal/services/privatedns/validate/txt_record_id_test.go deleted file mode 100644 index 390bbcc051f3..000000000000 --- a/internal/services/privatedns/validate/txt_record_id_test.go +++ /dev/null @@ -1,88 +0,0 @@ -package validate - -// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten - -import "testing" - -func TestTxtRecordID(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 PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", - Valid: false, - }, - - { - // missing value for PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", - Valid: false, - }, - - { - // missing TXTName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", - Valid: false, - }, - - { - // missing value for TXTName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/TXT/", - Valid: false, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/TXT/txt1", - Valid: true, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/TXT/TXT1", - Valid: false, - }, - } - for _, tc := range cases { - t.Logf("[DEBUG] Testing Value %s", tc.Input) - _, errors := TxtRecordID(tc.Input, "test") - valid := len(errors) == 0 - - if tc.Valid != valid { - t.Fatalf("Expected %t but got %t", tc.Valid, valid) - } - } -} diff --git a/internal/services/privatedns/validate/virtual_network_link_id.go b/internal/services/privatedns/validate/virtual_network_link_id.go deleted file mode 100644 index f538ea86ef15..000000000000 --- a/internal/services/privatedns/validate/virtual_network_link_id.go +++ /dev/null @@ -1,23 +0,0 @@ -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/privatedns/parse" -) - -func VirtualNetworkLinkID(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.VirtualNetworkLinkID(v); err != nil { - errors = append(errors, err) - } - - return -} diff --git a/internal/services/privatedns/validate/virtual_network_link_id_test.go b/internal/services/privatedns/validate/virtual_network_link_id_test.go deleted file mode 100644 index ad87350b81b8..000000000000 --- a/internal/services/privatedns/validate/virtual_network_link_id_test.go +++ /dev/null @@ -1,88 +0,0 @@ -package validate - -// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten - -import "testing" - -func TestVirtualNetworkLinkID(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 PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/", - Valid: false, - }, - - { - // missing value for PrivateDnsZoneName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/", - Valid: false, - }, - - { - // missing Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/", - Valid: false, - }, - - { - // missing value for Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/virtualNetworkLinks/", - Valid: false, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/privateDnsZones/privateDnsZone1/virtualNetworkLinks/virtualNetworkLink1", - Valid: true, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.NETWORK/PRIVATEDNSZONES/PRIVATEDNSZONE1/VIRTUALNETWORKLINKS/VIRTUALNETWORKLINK1", - Valid: false, - }, - } - for _, tc := range cases { - t.Logf("[DEBUG] Testing Value %s", tc.Input) - _, errors := VirtualNetworkLinkID(tc.Input, "test") - valid := len(errors) == 0 - - if tc.Valid != valid { - t.Fatalf("Expected %t but got %t", tc.Valid, valid) - } - } -} From 49c36bcaf6fcb75277d348023538a6298d5e6343 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Wed, 20 Jul 2022 14:21:23 +0800 Subject: [PATCH 3/4] update code --- .../log_analytics_query_pack_resource.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/internal/services/loganalytics/log_analytics_query_pack_resource.go b/internal/services/loganalytics/log_analytics_query_pack_resource.go index faeb9628b672..31cae69a391f 100644 --- a/internal/services/loganalytics/log_analytics_query_pack_resource.go +++ b/internal/services/loganalytics/log_analytics_query_pack_resource.go @@ -3,6 +3,7 @@ package loganalytics import ( "context" "fmt" + "net/http" "time" "github.com/hashicorp/go-azure-helpers/lang/response" @@ -88,8 +89,11 @@ func (r LogAnalyticsQueryPackResource) Create() sdk.ResourceFunc { Tags: &model.Tags, } - if _, err := client.QueryPacksCreateOrUpdate(ctx, id, *properties); err != nil { - return fmt.Errorf("creating %s: %+v", id, err) + if resp, err := client.QueryPacksCreateOrUpdate(ctx, id, *properties); err != nil { + // update check logic once the issue https://github.com/Azure/azure-rest-api-specs/issues/19603 is fixed + if !response.WasStatusCode(resp.HttpResponse, http.StatusCreated) { + return fmt.Errorf("creating %s: %+v", id, err) + } } metadata.SetID(id) @@ -128,8 +132,11 @@ func (r LogAnalyticsQueryPackResource) Update() sdk.ResourceFunc { properties.Tags = &model.Tags } - if _, err := client.QueryPacksCreateOrUpdate(ctx, *id, *properties); err != nil { - return fmt.Errorf("updating %s: %+v", *id, err) + if resp, err := client.QueryPacksCreateOrUpdate(ctx, *id, *properties); err != nil { + // update check logic once the issue https://github.com/Azure/azure-rest-api-specs/issues/19603 is fixed + if !response.WasStatusCode(resp.HttpResponse, http.StatusCreated) { + return fmt.Errorf("updating %s: %+v", *id, err) + } } return nil From 7668e6ae4947044df61d3a1be4acbfdb5068aaee Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Wed, 20 Jul 2022 16:05:56 +0800 Subject: [PATCH 4/4] update code --- .../2022-04-01/applicationinsights/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/applicationinsights/2022-04-01/applicationinsights/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/applicationinsights/2022-04-01/applicationinsights/README.md index e67de93e11a0..8080cc0ccaf5 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/applicationinsights/2022-04-01/applicationinsights/README.md +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/applicationinsights/2022-04-01/applicationinsights/README.md @@ -77,7 +77,7 @@ if model := read.Model; model != nil { ```go ctx := context.TODO() -id := applicationinsights.NewResourceGroupID() +id := applicationinsights.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") // alternatively `client.WorkbooksListByResourceGroup(ctx, id, applicationinsights.DefaultWorkbooksListByResourceGroupOperationOptions())` can be used to do batched pagination items, err := client.WorkbooksListByResourceGroupComplete(ctx, id, applicationinsights.DefaultWorkbooksListByResourceGroupOperationOptions()) @@ -94,7 +94,7 @@ for _, item := range items { ```go ctx := context.TODO() -id := applicationinsights.NewSubscriptionID() +id := applicationinsights.NewSubscriptionID("12345678-1234-9876-4563-123456789012") // alternatively `client.WorkbooksListBySubscription(ctx, id, applicationinsights.DefaultWorkbooksListBySubscriptionOperationOptions())` can be used to do batched pagination items, err := client.WorkbooksListBySubscriptionComplete(ctx, id, applicationinsights.DefaultWorkbooksListBySubscriptionOperationOptions())