Skip to content

Commit

Permalink
inclined some functions, changed docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jiaweitao001 committed Oct 24, 2024
1 parent 5e19d3a commit 4c2f4c1
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 104 deletions.
84 changes: 80 additions & 4 deletions internal/services/dynatrace/dynatrace_monitors_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dynatrace
import (
"context"
"fmt"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/apimanagement/validate"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
Expand Down Expand Up @@ -72,16 +73,91 @@ func (r MonitorsResource) Arguments() map[string]*pluginsdk.Schema {
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
"Active",
"Suspended",
string(monitors.MarketplaceSubscriptionStatusActive),
string(monitors.MarketplaceSubscriptionStatusSuspended),
}, false),
},

"identity": commonschema.SystemAssignedIdentityRequired(),

"plan": SchemaPlanData(),
"plan": {
Type: pluginsdk.TypeList,
Required: true,
ForceNew: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"billing_cycle": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"MONTHLY",
"WEEKLY",
}, false),
},

"plan": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"usage_type": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"PAYG",
"COMMITTED",
}, false),
},

"effective_date": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
},
},

"user": SchemaUserInfo(),
"user": {
Type: pluginsdk.TypeList,
Required: true,
ForceNew: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"country": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"email": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validate.EmailAddress,
},

"first_name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"last_name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"phone_number": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},
},
},
},

"tags": tags.Schema(),
}
Expand Down
102 changes: 5 additions & 97 deletions internal/services/dynatrace/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,93 +3,8 @@ 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/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
)

func SchemaPlanData() *pluginsdk.Schema {
return &pluginsdk.Schema{
Type: pluginsdk.TypeList,
Required: true,
ForceNew: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"billing_cycle": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"MONTHLY",
"WEEKLY",
}, false),
},

"plan": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"usage_type": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"PAYG",
"COMMITTED",
}, false),
},

"effective_date": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
},
}
}

func SchemaUserInfo() *pluginsdk.Schema {
return &pluginsdk.Schema{
Type: pluginsdk.TypeList,
Required: true,
ForceNew: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"country": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"email": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"first_name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"last_name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"phone_number": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},
},
},
}
}

func ExpandDynatracePlanData(input []PlanData) *monitors.PlanData {
if len(input) == 0 {
return nil
Expand Down Expand Up @@ -160,20 +75,13 @@ func FlattenDynatraceUserInfo(input []interface{}) []UserInfo {
}

v := input[0].(map[string]interface{})

country := v["country"].(string)
emailAddress := v["email"].(string)
firstName := v["first_name"].(string)
lastName := v["last_name"].(string)
phoneNumber := v["phone_number"].(string)

return []UserInfo{
{
Country: country,
EmailAddress: emailAddress,
FirstName: firstName,
LastName: lastName,
PhoneNumber: phoneNumber,
Country: v["country"].(string),
EmailAddress: v["email"].(string),
FirstName: v["first_name"].(string),
LastName: v["last_name"].(string),
PhoneNumber: v["phone_number"].(string),
},
}
}
6 changes: 3 additions & 3 deletions website/docs/r/dynatrace_monitors.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ The following arguments are supported:

* `identity` - (Required) The kind of managed identity assigned to this resource. A `identity` block as defined below.

* `marketplace_subscription` - (Required) Flag specifying the Marketplace Subscription Status of the resource. If payment is not made in time, the resource will go in Suspended state. Possible values are `Active`, `Suspended`.
* `marketplace_subscription` - (Required) Flag specifying the Marketplace Subscription Status of the resource. If payment is not made in time, the resource will go in Suspended state. Possible values are `Active` and `Suspended`.

* `plan` - (Required) Billing plan information. A `plan` block as defined below. Changing this forces a new resource to be created.

Expand All @@ -79,13 +79,13 @@ A `identity` block supports the following:

A `plan` block supports the following:

* `billing_cycle` - (Optional) Different billing cycles. Possible values are `MONTHLY`, `WEEKLY`.
* `billing_cycle` - (Optional) Different billing cycles. Possible values are `MONTHLY` and `WEEKLY`.

* `effective_date` - (Required) Date when plan was applied.

* `plan` - (Required) Plan id as published by Dynatrace.

* `usage_type` - (Optional) Different usage type. Possible values are `PAYG`, `COMMITTED`.
* `usage_type` - (Optional) Different usage type. Possible values are `PAYG` and `COMMITTED`.

---

Expand Down

0 comments on commit 4c2f4c1

Please sign in to comment.