diff --git a/.github/labeler-issue-triage.yml b/.github/labeler-issue-triage.yml index b0211680500d..3433684b4054 100644 --- a/.github/labeler-issue-triage.yml +++ b/.github/labeler-issue-triage.yml @@ -129,7 +129,7 @@ service/domain-services: - '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_active_directory_domain_service((.|\n)*)###' service/dynatrace: - - '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_dynatrace_monitor((.|\n)*)###' + - '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_dynatrace_((.|\n)*)###' service/elastic: - '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_elastic_cloud_elasticsearch((.|\n)*)###' diff --git a/internal/services/dynatrace/client/client.go b/internal/services/dynatrace/client/client.go index 6bab7528757f..027e89cedb65 100644 --- a/internal/services/dynatrace/client/client.go +++ b/internal/services/dynatrace/client/client.go @@ -7,11 +7,13 @@ import ( "fmt" "github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/monitors" + "github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules" "github.com/hashicorp/terraform-provider-azurerm/internal/common" ) type Client struct { *monitors.MonitorsClient + *tagrules.TagRulesClient } func NewClient(o *common.ClientOptions) (*Client, error) { @@ -21,7 +23,14 @@ func NewClient(o *common.ClientOptions) (*Client, error) { } o.Configure(monitorClient.Client, o.Authorizers.ResourceManager) + tagruleClient, err := tagrules.NewTagRulesClientWithBaseURI(o.Environment.ResourceManager) + if err != nil { + return nil, fmt.Errorf("building Dynatrace TagRule client: %+v", err) + } + o.Configure(tagruleClient.Client, o.Authorizers.ResourceManager) + return &Client{ MonitorsClient: monitorClient, + TagRulesClient: tagruleClient, }, nil } diff --git a/internal/services/dynatrace/dynatrace_tag_rules_resource.go b/internal/services/dynatrace/dynatrace_tag_rules_resource.go new file mode 100644 index 000000000000..777c44b718fb --- /dev/null +++ b/internal/services/dynatrace/dynatrace_tag_rules_resource.go @@ -0,0 +1,287 @@ +package dynatrace + +import ( + "context" + "fmt" + "time" + + "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/monitors" + "github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "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" +) + +type TagRulesResource struct{} + +type TagRulesResourceModel struct { + Name string `tfschema:"name"` + Monitor string `tfschema:"monitor_id"` + LogRules []LogRule `tfschema:"log_rule"` + MetricRules []MetricRule `tfschema:"metric_rule"` +} + +type MetricRule struct { + FilteringTags []FilteringTag `tfschema:"filtering_tag"` +} + +type LogRule struct { + FilteringTags []FilteringTag `tfschema:"filtering_tag"` + SendAadLogs bool `tfschema:"send_azure_active_directory_logs_enabled"` + SendActivityLogs bool `tfschema:"send_activity_logs_enabled"` + SendSubscriptionLogs bool `tfschema:"send_subscription_logs_enabled"` +} + +type FilteringTag struct { + Name string `tfschema:"name"` + Value string `tfschema:"value"` + Action string `tfschema:"action"` +} + +func (r TagRulesResource) Arguments() map[string]*schema.Schema { + return map[string]*schema.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "monitor_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: monitors.ValidateMonitorID, + }, + + "log_rule": { + Type: pluginsdk.TypeList, + Optional: true, + ForceNew: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*schema.Schema{ + "send_azure_active_directory_logs_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + ForceNew: true, + Default: false, + }, + + "send_activity_logs_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + ForceNew: true, + Default: false, + }, + + "send_subscription_logs_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + ForceNew: true, + Default: false, + }, + + "filtering_tag": { + Type: pluginsdk.TypeList, + Required: true, + ForceNew: true, + MinItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*schema.Schema{ + "action": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{ + "Include", + "Exclude", + }, false), + }, + + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "value": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + }, + }, + }, + }, + }, + }, + + "metric_rule": { + Type: pluginsdk.TypeList, + Optional: true, + ForceNew: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*schema.Schema{ + "filtering_tag": { + Type: pluginsdk.TypeList, + Required: true, + ForceNew: true, + MinItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*schema.Schema{ + "action": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{ + "Include", + "Exclude", + }, false), + }, + + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "value": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + }, + }, + }, + }, + }, + }, + } +} + +func (r TagRulesResource) Attributes() map[string]*schema.Schema { + return map[string]*schema.Schema{} +} + +func (r TagRulesResource) ModelObject() interface{} { + return &TagRulesResourceModel{} +} + +func (r TagRulesResource) ResourceType() string { + return "azurerm_dynatrace_tag_rules" +} + +func (r TagRulesResource) Create() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.Dynatrace.TagRulesClient + subscriptionId := metadata.Client.Account.SubscriptionId + + var model TagRulesResourceModel + if err := metadata.Decode(&model); err != nil { + return err + } + + monitorsId, err := monitors.ParseMonitorID(model.Monitor) + id := tagrules.NewTagRuleID(subscriptionId, monitorsId.ResourceGroupName, monitorsId.MonitorName, model.Name) + if err != nil { + return err + } + + existing, err := client.Get(ctx, id) + if err != nil && !response.WasNotFound(existing.HttpResponse) { + return fmt.Errorf("checking for presence of existing %s: %+v", id, err) + } + + if !response.WasNotFound(existing.HttpResponse) { + return metadata.ResourceRequiresImport(r.ResourceType(), id) + } + + tagRulesProps := tagrules.MonitoringTagRulesProperties{ + LogRules: ExpandLogRule(model.LogRules), + MetricRules: ExpandMetricRules(model.MetricRules), + } + tagRules := tagrules.TagRule{ + Name: &model.Name, + Properties: tagRulesProps, + } + + if _, err := client.CreateOrUpdate(ctx, id, tagRules); err != nil { + return fmt.Errorf("creating %s: %+v", id, err) + } + + metadata.SetID(id) + + return nil + }, + } +} + +func (r TagRulesResource) Read() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 5 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.Dynatrace.TagRulesClient + id, err := tagrules.ParseTagRuleID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + resp, err := client.Get(ctx, *id) + if err != nil { + if response.WasNotFound(resp.HttpResponse) { + return metadata.MarkAsGone(id) + } + return fmt.Errorf("reading %s: %+v", id, err) + } + if model := resp.Model; model != nil { + props := model.Properties + monitorId := monitors.NewMonitorID(id.SubscriptionId, id.ResourceGroupName, id.MonitorName) + + state := TagRulesResourceModel{ + Name: id.TagRuleName, + Monitor: monitorId.ID(), + LogRules: FlattenLogRules(props.LogRules), + MetricRules: FlattenMetricRules(props.MetricRules), + } + + return metadata.Encode(&state) + } + + return nil + }, + } +} + +func (r TagRulesResource) Delete() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.Dynatrace.TagRulesClient + id, err := tagrules.ParseTagRuleID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + metadata.Logger.Infof("deleting %s", *id) + + if _, err := client.Delete(ctx, *id); err != nil { + return fmt.Errorf("deleting %s: %+v", *id, err) + } + return nil + }, + } +} + +func (r TagRulesResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { + return tagrules.ValidateTagRuleID +} diff --git a/internal/services/dynatrace/dynatrace_tag_rules_resource_test.go b/internal/services/dynatrace/dynatrace_tag_rules_resource_test.go new file mode 100644 index 000000000000..ed2c982ca8c0 --- /dev/null +++ b/internal/services/dynatrace/dynatrace_tag_rules_resource_test.go @@ -0,0 +1,167 @@ +package dynatrace_test + +import ( + "context" + "fmt" + "os" + "testing" + + "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules" + "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" +) + +type TagRulesResource struct { + dynatraceInfo dynatraceInfo +} + +func NewTagRulesResource() TagRulesResource { + return TagRulesResource{ + dynatraceInfo: dynatraceInfo{ + UserCountry: os.Getenv("DYNATRACE_USER_COUNTRY"), + UserEmail: os.Getenv("DYNATRACE_USER_EMAIL"), + UserFirstName: os.Getenv("DYNATRACE_USER_FIRST_NAME"), + UserLastName: os.Getenv("DYNATRACE_USER_LAST_NAME"), + UserPhoneNumber: os.Getenv("DYNATRACE_USER_PHONE_NUMBER"), + }, + } +} + +func TestAccDynatraceTagRules_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_dynatrace_tag_rules", "test") + r := NewTagRulesResource() + r.preCheck(t) + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccDynatraceTagRules_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_dynatrace_tag_rules", "test") + r := NewTagRulesResource() + r.preCheck(t) + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccDynatraceTagRules_requiresImport(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_dynatrace_tag_rules", "test") + r := NewTagRulesResource() + r.preCheck(t) + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.RequiresImportErrorStep(r.requiresImport), + }) +} + +func (r TagRulesResource) preCheck(t *testing.T) { + if r.dynatraceInfo.UserCountry == "" { + t.Skipf("DYNATRACE_USER_COUNTRY must be set for acceptance tests") + } + if r.dynatraceInfo.UserEmail == "" { + t.Skipf("DYNATRACE_USER_EMAIL must be set for acceptance tests") + } + if r.dynatraceInfo.UserFirstName == "" { + t.Skipf("DYNATRACE_USER_FIRST_NAME must be set for acceptance tests") + } + if r.dynatraceInfo.UserLastName == "" { + t.Skipf("DYNATRACE_USER_LAST_NAME must be set for acceptance tests") + } + if r.dynatraceInfo.UserPhoneNumber == "" { + t.Skipf("DYNATRACE_USER_PHONE_NUMBER must be set for acceptance tests") + } +} + +func (r TagRulesResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + id, err := tagrules.ParseTagRuleID(state.ID) + if err != nil { + return nil, err + } + + resp, err := client.Dynatrace.TagRulesClient.Get(ctx, *id) + if err != nil { + if response.WasNotFound(resp.HttpResponse) { + return pointer.To(false), nil + } + return nil, fmt.Errorf("retrieving %s: %+v", *id, err) + } + return pointer.To(true), nil +} + +func (r TagRulesResource) basic(data acceptance.TestData) string { + return fmt.Sprintf(` +%[1]s + +resource "azurerm_dynatrace_tag_rules" "test" { + name = "acctesttagrules%d" + monitor_id = azurerm_dynatrace_monitor.test.id +} +`, MonitorsResource{}.basic(data), data.RandomInteger) +} + +func (r TagRulesResource) complete(data acceptance.TestData) string { + return fmt.Sprintf(` +%[1]s + +resource "azurerm_dynatrace_tag_rules" "test" { + name = "acctesttagrules%d" + monitor_id = azurerm_dynatrace_monitor.test.id + + log_rule { + filtering_tag { + name = "Environment" + value = "Prod" + action = "Include" + } + send_azure_active_directory_logs_enabled = true + send_activity_logs_enabled = true + send_subscription_logs_enabled = true + } + + metric_rule { + filtering_tag { + name = "Environment" + value = "Prod" + action = "Include" + } + } +} +`, MonitorsResource{}.basic(data), data.RandomInteger) +} + +func (r TagRulesResource) requiresImport(data acceptance.TestData) string { + template := r.basic(data) + return fmt.Sprintf(` +%s + +resource "azurerm_dynatrace_tag_rules" "import" { + name = azurerm_dynatrace_tag_rules.test.name + monitor_id = azurerm_dynatrace_tag_rules.test.monitor_id +} +`, template) +} diff --git a/internal/services/dynatrace/helper.go b/internal/services/dynatrace/helper.go index 951ec681e0fd..8b8ba5e6a310 100644 --- a/internal/services/dynatrace/helper.go +++ b/internal/services/dynatrace/helper.go @@ -6,6 +6,7 @@ package dynatrace import ( "github.com/hashicorp/go-azure-helpers/lang/pointer" "github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/monitors" + "github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules" ) func ExpandDynatracePlanData(input []PlanData) *monitors.PlanData { @@ -88,3 +89,142 @@ func FlattenDynatraceUserInfo(input []interface{}) []UserInfo { }, } } + +func FlattenLogRules(input *tagrules.LogRules) []LogRule { + if input == nil { + return []LogRule{} + } + + var logRule LogRule + var sendAadLogs bool + var sendActivityLogs bool + var sendSubscriptionLogs bool + + if input.FilteringTags != nil { + filteringTags := FlattenFilteringTags(input.FilteringTags) + logRule.FilteringTags = filteringTags + } + + if input.SendActivityLogs != nil { + if pointer.From(input.SendActivityLogs) == tagrules.SendActivityLogsStatusEnabled { + sendActivityLogs = true + } else { + sendActivityLogs = false + } + logRule.SendActivityLogs = sendActivityLogs + } + + if input.SendAadLogs != nil { + if pointer.From(input.SendAadLogs) == tagrules.SendAadLogsStatusEnabled { + sendAadLogs = true + } else { + sendAadLogs = false + } + logRule.SendAadLogs = sendAadLogs + } + + if input.SendSubscriptionLogs != nil { + if pointer.From(input.SendSubscriptionLogs) == tagrules.SendSubscriptionLogsStatusEnabled { + sendSubscriptionLogs = true + } else { + sendSubscriptionLogs = false + } + logRule.SendSubscriptionLogs = sendSubscriptionLogs + } + + return []LogRule{logRule} +} + +func FlattenFilteringTags(input *[]tagrules.FilteringTag) []FilteringTag { + if input == nil || len(*input) == 0 { + return []FilteringTag{} + } + + tags := pointer.From(input)[0] + + return []FilteringTag{ + { + Name: pointer.From(tags.Name), + Value: pointer.From(tags.Value), + Action: string(pointer.From(tags.Action)), + }, + } +} + +func FlattenMetricRules(input *tagrules.MetricRules) []MetricRule { + if input == nil { + return []MetricRule{} + } + + filteringTags := make([]FilteringTag, 0) + + if input.FilteringTags != nil { + filteringTags = FlattenFilteringTags(input.FilteringTags) + } + + return []MetricRule{ + { + FilteringTags: filteringTags, + }, + } +} + +func ExpandMetricRules(input []MetricRule) *tagrules.MetricRules { + if len(input) == 0 { + return nil + } + v := input[0] + + return &tagrules.MetricRules{ + FilteringTags: ExpandFilteringTag(v.FilteringTags), + } +} + +func ExpandLogRule(input []LogRule) *tagrules.LogRules { + if len(input) == 0 { + return nil + } + v := input[0] + var sendAadLogs tagrules.SendAadLogsStatus + var sendActivityLogs tagrules.SendActivityLogsStatus + var sendSubscriptionLogs tagrules.SendSubscriptionLogsStatus + + if v.SendAadLogs { + sendAadLogs = tagrules.SendAadLogsStatusEnabled + } else { + sendAadLogs = tagrules.SendAadLogsStatusDisabled + } + if v.SendActivityLogs { + sendActivityLogs = tagrules.SendActivityLogsStatusEnabled + } else { + sendActivityLogs = tagrules.SendActivityLogsStatusDisabled + } + if v.SendSubscriptionLogs { + sendSubscriptionLogs = tagrules.SendSubscriptionLogsStatusEnabled + } else { + sendSubscriptionLogs = tagrules.SendSubscriptionLogsStatusDisabled + } + + return &tagrules.LogRules{ + FilteringTags: ExpandFilteringTag(v.FilteringTags), + SendAadLogs: pointer.To(sendAadLogs), + SendActivityLogs: pointer.To(sendActivityLogs), + SendSubscriptionLogs: pointer.To(sendSubscriptionLogs), + } +} + +func ExpandFilteringTag(input []FilteringTag) *[]tagrules.FilteringTag { + if len(input) == 0 { + return nil + } + v := input[0] + action := tagrules.TagAction(v.Action) + + return &[]tagrules.FilteringTag{ + { + Action: pointer.To(action), + Name: pointer.To(v.Name), + Value: pointer.To(v.Value), + }, + } +} diff --git a/internal/services/dynatrace/registration.go b/internal/services/dynatrace/registration.go index 001d19bbde01..6276cc411f0b 100644 --- a/internal/services/dynatrace/registration.go +++ b/internal/services/dynatrace/registration.go @@ -24,6 +24,7 @@ func (r Registration) DataSources() []sdk.DataSource { func (r Registration) Resources() []sdk.Resource { return []sdk.Resource{ MonitorsResource{}, + TagRulesResource{}, } } diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/README.md new file mode 100644 index 000000000000..790313121994 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules` Documentation + +The `tagrules` SDK allows for interaction with Azure Resource Manager `dynatrace` (API Version `2023-04-27`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules" +``` + + +### Client Initialization + +```go +client := tagrules.NewTagRulesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `TagRulesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := tagrules.NewTagRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName", "tagRuleName") + +payload := tagrules.TagRule{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `TagRulesClient.Delete` + +```go +ctx := context.TODO() +id := tagrules.NewTagRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName", "tagRuleName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `TagRulesClient.Get` + +```go +ctx := context.TODO() +id := tagrules.NewTagRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName", "tagRuleName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagRulesClient.List` + +```go +ctx := context.TODO() +id := tagrules.NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/client.go new file mode 100644 index 000000000000..1353e3786ef5 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/client.go @@ -0,0 +1,26 @@ +package tagrules + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagRulesClient struct { + Client *resourcemanager.Client +} + +func NewTagRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*TagRulesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "tagrules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating TagRulesClient: %+v", err) + } + + return &TagRulesClient{ + Client: client, + }, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/constants.go new file mode 100644 index 000000000000..1e2093fafd75 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/constants.go @@ -0,0 +1,277 @@ +package tagrules + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "notspecified": ProvisioningStateNotSpecified, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} + +type SendAadLogsStatus string + +const ( + SendAadLogsStatusDisabled SendAadLogsStatus = "Disabled" + SendAadLogsStatusEnabled SendAadLogsStatus = "Enabled" +) + +func PossibleValuesForSendAadLogsStatus() []string { + return []string{ + string(SendAadLogsStatusDisabled), + string(SendAadLogsStatusEnabled), + } +} + +func (s *SendAadLogsStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSendAadLogsStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSendAadLogsStatus(input string) (*SendAadLogsStatus, error) { + vals := map[string]SendAadLogsStatus{ + "disabled": SendAadLogsStatusDisabled, + "enabled": SendAadLogsStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SendAadLogsStatus(input) + return &out, nil +} + +type SendActivityLogsStatus string + +const ( + SendActivityLogsStatusDisabled SendActivityLogsStatus = "Disabled" + SendActivityLogsStatusEnabled SendActivityLogsStatus = "Enabled" +) + +func PossibleValuesForSendActivityLogsStatus() []string { + return []string{ + string(SendActivityLogsStatusDisabled), + string(SendActivityLogsStatusEnabled), + } +} + +func (s *SendActivityLogsStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSendActivityLogsStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSendActivityLogsStatus(input string) (*SendActivityLogsStatus, error) { + vals := map[string]SendActivityLogsStatus{ + "disabled": SendActivityLogsStatusDisabled, + "enabled": SendActivityLogsStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SendActivityLogsStatus(input) + return &out, nil +} + +type SendSubscriptionLogsStatus string + +const ( + SendSubscriptionLogsStatusDisabled SendSubscriptionLogsStatus = "Disabled" + SendSubscriptionLogsStatusEnabled SendSubscriptionLogsStatus = "Enabled" +) + +func PossibleValuesForSendSubscriptionLogsStatus() []string { + return []string{ + string(SendSubscriptionLogsStatusDisabled), + string(SendSubscriptionLogsStatusEnabled), + } +} + +func (s *SendSubscriptionLogsStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSendSubscriptionLogsStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSendSubscriptionLogsStatus(input string) (*SendSubscriptionLogsStatus, error) { + vals := map[string]SendSubscriptionLogsStatus{ + "disabled": SendSubscriptionLogsStatusDisabled, + "enabled": SendSubscriptionLogsStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SendSubscriptionLogsStatus(input) + return &out, nil +} + +type SendingMetricsStatus string + +const ( + SendingMetricsStatusDisabled SendingMetricsStatus = "Disabled" + SendingMetricsStatusEnabled SendingMetricsStatus = "Enabled" +) + +func PossibleValuesForSendingMetricsStatus() []string { + return []string{ + string(SendingMetricsStatusDisabled), + string(SendingMetricsStatusEnabled), + } +} + +func (s *SendingMetricsStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSendingMetricsStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSendingMetricsStatus(input string) (*SendingMetricsStatus, error) { + vals := map[string]SendingMetricsStatus{ + "disabled": SendingMetricsStatusDisabled, + "enabled": SendingMetricsStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SendingMetricsStatus(input) + return &out, nil +} + +type TagAction string + +const ( + TagActionExclude TagAction = "Exclude" + TagActionInclude TagAction = "Include" +) + +func PossibleValuesForTagAction() []string { + return []string{ + string(TagActionExclude), + string(TagActionInclude), + } +} + +func (s *TagAction) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTagAction(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTagAction(input string) (*TagAction, error) { + vals := map[string]TagAction{ + "exclude": TagActionExclude, + "include": TagActionInclude, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TagAction(input) + return &out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/id_monitor.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/id_monitor.go new file mode 100644 index 000000000000..c618d4635067 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/id_monitor.go @@ -0,0 +1,130 @@ +package tagrules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MonitorId{}) +} + +var _ resourceids.ResourceId = &MonitorId{} + +// MonitorId is a struct representing the Resource ID for a Monitor +type MonitorId struct { + SubscriptionId string + ResourceGroupName string + MonitorName string +} + +// NewMonitorID returns a new MonitorId struct +func NewMonitorID(subscriptionId string, resourceGroupName string, monitorName string) MonitorId { + return MonitorId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MonitorName: monitorName, + } +} + +// ParseMonitorID parses 'input' into a MonitorId +func ParseMonitorID(input string) (*MonitorId, error) { + parser := resourceids.NewParserFromResourceIdType(&MonitorId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MonitorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMonitorIDInsensitively parses 'input' case-insensitively into a MonitorId +// note: this method should only be used for API response data and not user input +func ParseMonitorIDInsensitively(input string) (*MonitorId, error) { + parser := resourceids.NewParserFromResourceIdType(&MonitorId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MonitorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MonitorId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.MonitorName, ok = input.Parsed["monitorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "monitorName", input) + } + + return nil +} + +// ValidateMonitorID checks that 'input' can be parsed as a Monitor ID +func ValidateMonitorID(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 := ParseMonitorID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Monitor ID +func (id MonitorId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Dynatrace.Observability/monitors/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MonitorName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Monitor ID +func (id MonitorId) 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("staticDynatraceObservability", "Dynatrace.Observability", "Dynatrace.Observability"), + resourceids.StaticSegment("staticMonitors", "monitors", "monitors"), + resourceids.UserSpecifiedSegment("monitorName", "monitorName"), + } +} + +// String returns a human-readable description of this Monitor ID +func (id MonitorId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Monitor Name: %q", id.MonitorName), + } + return fmt.Sprintf("Monitor (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/id_tagrule.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/id_tagrule.go new file mode 100644 index 000000000000..4f63d64c60c5 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/id_tagrule.go @@ -0,0 +1,139 @@ +package tagrules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TagRuleId{}) +} + +var _ resourceids.ResourceId = &TagRuleId{} + +// TagRuleId is a struct representing the Resource ID for a Tag Rule +type TagRuleId struct { + SubscriptionId string + ResourceGroupName string + MonitorName string + TagRuleName string +} + +// NewTagRuleID returns a new TagRuleId struct +func NewTagRuleID(subscriptionId string, resourceGroupName string, monitorName string, tagRuleName string) TagRuleId { + return TagRuleId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MonitorName: monitorName, + TagRuleName: tagRuleName, + } +} + +// ParseTagRuleID parses 'input' into a TagRuleId +func ParseTagRuleID(input string) (*TagRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagRuleId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagRuleId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTagRuleIDInsensitively parses 'input' case-insensitively into a TagRuleId +// note: this method should only be used for API response data and not user input +func ParseTagRuleIDInsensitively(input string) (*TagRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagRuleId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagRuleId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TagRuleId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.MonitorName, ok = input.Parsed["monitorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "monitorName", input) + } + + if id.TagRuleName, ok = input.Parsed["tagRuleName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tagRuleName", input) + } + + return nil +} + +// ValidateTagRuleID checks that 'input' can be parsed as a Tag Rule ID +func ValidateTagRuleID(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 := ParseTagRuleID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Tag Rule ID +func (id TagRuleId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Dynatrace.Observability/monitors/%s/tagRules/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MonitorName, id.TagRuleName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Tag Rule ID +func (id TagRuleId) 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("staticDynatraceObservability", "Dynatrace.Observability", "Dynatrace.Observability"), + resourceids.StaticSegment("staticMonitors", "monitors", "monitors"), + resourceids.UserSpecifiedSegment("monitorName", "monitorName"), + resourceids.StaticSegment("staticTagRules", "tagRules", "tagRules"), + resourceids.UserSpecifiedSegment("tagRuleName", "tagRuleName"), + } +} + +// String returns a human-readable description of this Tag Rule ID +func (id TagRuleId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Monitor Name: %q", id.MonitorName), + fmt.Sprintf("Tag Rule Name: %q", id.TagRuleName), + } + return fmt.Sprintf("Tag Rule (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/method_createorupdate.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/method_createorupdate.go new file mode 100644 index 000000000000..e8d30dad8926 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/method_createorupdate.go @@ -0,0 +1,75 @@ +package tagrules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *TagRule +} + +// CreateOrUpdate ... +func (c TagRulesClient) CreateOrUpdate(ctx context.Context, id TagRuleId, input TagRule) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c TagRulesClient) CreateOrUpdateThenPoll(ctx context.Context, id TagRuleId, input TagRule) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/method_delete.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/method_delete.go new file mode 100644 index 000000000000..4161493d1b97 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/method_delete.go @@ -0,0 +1,71 @@ +package tagrules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c TagRulesClient) Delete(ctx context.Context, id TagRuleId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c TagRulesClient) DeleteThenPoll(ctx context.Context, id TagRuleId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/method_get.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/method_get.go new file mode 100644 index 000000000000..1e082f6ccfad --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/method_get.go @@ -0,0 +1,53 @@ +package tagrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TagRule +} + +// Get ... +func (c TagRulesClient) Get(ctx context.Context, id TagRuleId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model TagRule + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/method_list.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/method_list.go new file mode 100644 index 000000000000..6c952d3f97ee --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/method_list.go @@ -0,0 +1,105 @@ +package tagrules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]TagRule +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []TagRule +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c TagRulesClient) List(ctx context.Context, id MonitorId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/tagRules", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]TagRule `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c TagRulesClient) ListComplete(ctx context.Context, id MonitorId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, TagRuleOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c TagRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id MonitorId, predicate TagRuleOperationPredicate) (result ListCompleteResult, err error) { + items := make([]TagRule, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/model_filteringtag.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/model_filteringtag.go new file mode 100644 index 000000000000..13b1c7f0b877 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/model_filteringtag.go @@ -0,0 +1,10 @@ +package tagrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FilteringTag struct { + Action *TagAction `json:"action,omitempty"` + Name *string `json:"name,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/model_logrules.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/model_logrules.go new file mode 100644 index 000000000000..1bd42a848b5b --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/model_logrules.go @@ -0,0 +1,11 @@ +package tagrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LogRules struct { + FilteringTags *[]FilteringTag `json:"filteringTags,omitempty"` + SendAadLogs *SendAadLogsStatus `json:"sendAadLogs,omitempty"` + SendActivityLogs *SendActivityLogsStatus `json:"sendActivityLogs,omitempty"` + SendSubscriptionLogs *SendSubscriptionLogsStatus `json:"sendSubscriptionLogs,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/model_metricrules.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/model_metricrules.go new file mode 100644 index 000000000000..44f230a53c59 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/model_metricrules.go @@ -0,0 +1,9 @@ +package tagrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetricRules struct { + FilteringTags *[]FilteringTag `json:"filteringTags,omitempty"` + SendingMetrics *SendingMetricsStatus `json:"sendingMetrics,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/model_monitoringtagrulesproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/model_monitoringtagrulesproperties.go new file mode 100644 index 000000000000..8900c72ac040 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/model_monitoringtagrulesproperties.go @@ -0,0 +1,10 @@ +package tagrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitoringTagRulesProperties struct { + LogRules *LogRules `json:"logRules,omitempty"` + MetricRules *MetricRules `json:"metricRules,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/model_tagrule.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/model_tagrule.go new file mode 100644 index 000000000000..be251a10a4d2 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/model_tagrule.go @@ -0,0 +1,16 @@ +package tagrules + +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 TagRule struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties MonitoringTagRulesProperties `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/predicates.go new file mode 100644 index 000000000000..b8e7c533c9f0 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/predicates.go @@ -0,0 +1,27 @@ +package tagrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagRuleOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p TagRuleOperationPredicate) Matches(input TagRule) 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/dynatrace/2023-04-27/tagrules/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/version.go new file mode 100644 index 000000000000..330c91cdf577 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules/version.go @@ -0,0 +1,10 @@ +package tagrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-04-27" + +func userAgent() string { + return "hashicorp/go-azure-sdk/tagrules/2023-04-27" +} diff --git a/vendor/modules.txt b/vendor/modules.txt index a00e6eefd3fc..718f4426a2c7 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -504,6 +504,10 @@ github.com/hashicorp/go-azure-sdk/resource-manager/dnsresolver/2022-07-01/inboun github.com/hashicorp/go-azure-sdk/resource-manager/dnsresolver/2022-07-01/outboundendpoints github.com/hashicorp/go-azure-sdk/resource-manager/dnsresolver/2022-07-01/virtualnetworklinks github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/monitors +github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2021-09-01/monitors +github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2021-09-01/tagrules +github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/monitors +github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2023-04-27/tagrules github.com/hashicorp/go-azure-sdk/resource-manager/elastic/2023-06-01/monitorsresource github.com/hashicorp/go-azure-sdk/resource-manager/elastic/2023-06-01/rules github.com/hashicorp/go-azure-sdk/resource-manager/elasticsan/2023-01-01 @@ -531,6 +535,10 @@ github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2022-06-15/topics github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2022-06-15/topictypes github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2022-06-15/verifiedpartners github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/namespaces +github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2021-09-01/monitors +github.com/hashicorp/go-azure-sdk/resource-manager/dynatrace/2021-09-01/tagrules +github.com/hashicorp/go-azure-sdk/resource-manager/elastic/2020-07-01/monitorsresource +github.com/hashicorp/go-azure-sdk/resource-manager/elastic/2020-07-01/rules github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/authorizationruleseventhubs github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/authorizationrulesnamespaces github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/checknameavailabilitydisasterrecoveryconfigs diff --git a/website/docs/r/dynatrace_tag_rules.html.markdown b/website/docs/r/dynatrace_tag_rules.html.markdown new file mode 100644 index 000000000000..cf1ea0134d14 --- /dev/null +++ b/website/docs/r/dynatrace_tag_rules.html.markdown @@ -0,0 +1,134 @@ +--- +subcategory: "Dynatrace" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_dynatrace_tag_rules" +description: |- + Manages Dynatrace tag rules. +--- + +# azurerm_dynatrace_tag_rules + +Manages Dynatrace tag rules. + +## Example Usage + +```hcl + +resource "azurerm_resource_group" "example" { + name = "example-resources" + location = "West Europe" +} + +resource "azurerm_dynatrace_monitor" "example" { + name = "exmpledynatracemonitor" + resource_group_name = azurerm_resource_group.example.name + location = azurerm_resource_group.test.location + monitoring_enabled = true + marketplace_subscription_status = "Active" + + identity { + type = "SystemAssigned" + } + + user { + first_name = "Alice" + last_name = "Bobab" + email = "alice@microsoft.com" + phone_number = "123456" + country = "westus" + } + + plan { + usage_type = "COMMITTED" + billing_cycle = "MONTHLY" + plan = "azureportalintegration_privatepreview@TIDhjdtn7tfnxcy" + effective_date = "2019-08-30T15:14:33Z" + } +} + +resource "azurerm_dynatrace_tag_rules" "example" { + name = "examplestreamanalyticscluster" + monitor_id = azurerm_dynatrace_monitors.test.id + + log_rule { + filtering_tag { + name = "Environment" + value = "Prod" + action = "Include" + } + send_azure_active_directory_logs_enabled = true + send_activity_logs_enabled = true + send_subscription_logs_enabled = true + } + + metric_rule { + filtering_tag { + name = "Environment" + value = "Prod" + action = "Include" + } + } +} +``` + +## Arguments Reference + +The following arguments are supported: + +* `name` - (Required) Name of the Dynatrace tag rules. Currently, the only supported value is `default`. Changing this forces a new resource to be created. + +* `monitor_id` - (Required) Name of the Dynatrace monitor. Changing this forces a new resource to be created. + +* `log_rule` - (Optional) Set of rules for sending logs for the Monitor resource. Changing this forces a new resource to be created. A `log_rule` block as defined below. + +* `metric_rule` - (Optional) Set of rules for sending metrics for the Monitor resource. Changing this forces a new resource to be created. A `metric_rule` block as defined below. + +--- + +The `log_rule` block supports the following: + +* `send_azure_active_directory_logs_enabled` - (Optional) Send Azure Active Directory logs. The default value is `false`. Changing this forces a new resource to be created. + +* `send_activity_logs_enabled` - (Optional) Send Activity logs. The default value is `false`. Changing this forces a new resource to be created. + +* `send_subscription_logs_enabled` - (Optional) Send Subscription logs. The default value is `false`. Changing this forces a new resource to be created. + +* `filtering_tag` - (Optional) Filtering tag for the log rule. A `filtering_tag` block as defined below. Changing this forces a new resource to be created. + +--- + +The `metric_rule` block supports the following: + +* `filtering_tag` - (Optional) Filtering tag for the metric rule. A `filtering_tag` block as defined below. + +--- + +The `filtering_tag` block supports the following: + +* `name` - (Required) Name of the filtering tag. Changing this forces a new resource to be created. + +* `value` - (Required) Value of the filtering tag. Changing this forces a new resource to be created. + +* `action` - (Required) Action of the filtering tag. Possible values are `Include` and `Exclude`. Changing this forces a new resource to be created. + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `id` - The ID of the Dynatrace tag rules. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions: + +* `create` - (Defaults to 30 minutes) Used when creating the Dynatrace tag rules. +* `read` - (Defaults to 5 minutes) Used when retrieving the Dynatrace tag rules. +* `delete` - (Defaults to 30 minutes) Used when deleting the Dynatrace tag rules. + +## Import + +Dynatrace tag rules can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_dynatrace_tag_rules.example /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Dynatrace.Observability/monitors/monitor1/tagRules/tagRules1 +```