Skip to content

Commit 41332a4

Browse files
Fixes for #45, #43, #42, #41, #40, #39, #37,
1 parent acce644 commit 41332a4

File tree

15 files changed

+384
-367
lines changed

15 files changed

+384
-367
lines changed

README.md

+12-37
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,33 @@
11
# Dynatrace Terraform Provider
2-
[![Gitter chat](https://badges.gitter.im/hashicorp-terraform/Lobby.png)](https://gitter.im/hashicorp-terraform/Lobby)
3-
- Terraform Website: [https://www.terraform.io](https://www.terraform.io)
4-
- Mailing list: [Google Groups](http://groups.google.com/group/terraform-tool)
52
## Requirements
63

7-
- [Terraform](https://www.terraform.io/downloads.html) 0.12+
4+
- [Terraform](https://www.terraform.io/downloads.html) 0.13.x+
85

96
## Using the provider
107

11-
If you want to run Terraform with the dynatrace provider plugin on your system, complete the following steps:
12-
13-
1. [Download](https://github.com/dynatrace-oss/terraform-provider-dynatrace/releases/latest) the dynatrace provider plugin for Terraform.
14-
15-
1. Unzip the release archive to extract the plugin binary (`terraform-provider-dynatrace_vX.Y.Z`).
16-
17-
For Terraform version 0.12.x
18-
19-
1. Move the binary into the Terraform [plugins directory] for the platform.
20-
- Linux/Unix/macOS: `~/.terraform.d/plugins`
21-
- Windows: `%APPDATA%\terraform.d\plugins`
22-
23-
1. Add the plug-in provider to the Terraform configuration file.
8+
If you want to run Terraform with the dynatrace provider plugin on your system, add the plug-in provider to the Terraform configuration file.
249

2510
```hcl
2611
terraform {
12+
required_version = "~> 0.13.0"
2713
required_providers {
2814
dynatrace = {
29-
version = "1.1.0"
15+
version = "1.2.2"
16+
source = "dynatrace.com/com/dynatrace"
3017
}
3118
}
32-
}
19+
}
3320
```
34-
35-
36-
For Terraform version 0.13.x
3721

38-
1. Move the binary into the Terraform [plugins directory] for the platform.
39-
- Linux: `~/.terraform.d/plugins/dynatrace.com/com/dynatrace/1.0.4/linux_amd64/`
40-
- macOS: `~/.terraform.d/plugins/dynatrace.com/com/dynatrace/1.0.4/darwin_amd64/`
41-
- Windows: `%APPDATA%\terraform.d\plugins\dynatrace.com\com\dynatrace\1.0.4\windows_amd64\`
42-
43-
1. Add the plug-in provider to the Terraform configuration file.
22+
In order to configure the provider, add a code section like this into your Terraform configuration file
4423

4524
```hcl
46-
terraform {
47-
required_version = "~> 0.13.0"
48-
required_providers {
49-
dynatrace = {
50-
version = "1.1.0"
51-
source = "dynatrace.com/com/dynatrace"
52-
}
53-
}
54-
}
25+
provider "dynatrace" {
26+
dt_env_url = "https://#######.live.dynatrace.com"
27+
dt_api_token = "##########################################"
28+
}
5529
```
30+
where `dt_env_url` represents the URL of your Dynatrace Environment and `dt_api_token` needs to be an API Token with the permissions `Read configuration` and `Capture request data`.
5631

5732
## Currently supported configuration settings
5833
* Dashboards

alerting/resource.go

-27
Original file line numberDiff line numberDiff line change
@@ -80,33 +80,6 @@ func Update(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Dia
8080
return Read(ctx, d, m)
8181
}
8282

83-
// func traverseSlice(elems []interface{}) []interface{} {
84-
// return elems
85-
// }
86-
87-
// func unique(v interface{}) int {
88-
// return 0
89-
// }
90-
91-
// func traverseMap(m map[string]interface{}) map[string]interface{} {
92-
// if m == nil {
93-
// return m
94-
// }
95-
// for k, v := range m {
96-
// switch tv := v.(type) {
97-
// case hcl.Set:
98-
// m[k] = schema.NewSet(nil, []interface{}(tv))
99-
// case []interface{}:
100-
// m[k] = traverseSlice(tv)
101-
// case map[string]interface{}:
102-
// m[k] = traverseMap(tv)
103-
// default:
104-
// m[k] = tv
105-
// }
106-
// }
107-
// return m
108-
// }
109-
11083
// Read queries the Dynatrace Server for the configuration
11184
func Read(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
11285
config, err := NewService(m).Get(d.Id())

anomalies/applications/resource.go

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ func NewService(m interface{}) *applications.Service {
5252

5353
// Create expects the configuration within the given ResourceData and sends it to the Dynatrace Server in order to create that resource
5454
func Create(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
55-
d.SetId("dynatrace_application_anomalies")
5655
config := new(applications.AnomalyDetection)
5756
if err := config.UnmarshalHCL(hcl.DecoderFrom(d)); err != nil {
5857
return diag.FromErr(err)

anomalies/databases/resource.go

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ func NewService(m interface{}) *databaseservices.Service {
5252

5353
// Create expects the configuration within the given ResourceData and sends it to the Dynatrace Server in order to create that resource
5454
func Create(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
55-
d.SetId("dynatrace_database_anomalies")
5655
config := new(databaseservices.AnomalyDetection)
5756
if err := config.UnmarshalHCL(hcl.DecoderFrom(d)); err != nil {
5857
return diag.FromErr(err)

anomalies/disks/resource.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import (
2323
"github.com/dtcookie/dynatrace/api/config/anomalies/diskevents"
2424
"github.com/dtcookie/dynatrace/rest"
2525
"github.com/dtcookie/hcl"
26+
"github.com/dtcookie/opt"
2627
"github.com/dynatrace-oss/terraform-provider-dynatrace/config"
2728
"github.com/dynatrace-oss/terraform-provider-dynatrace/hcl2sdk"
2829
"github.com/dynatrace-oss/terraform-provider-dynatrace/logging"
29-
"github.com/google/uuid"
3030

3131
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
3232
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -53,8 +53,8 @@ func NewService(m interface{}) *diskevents.Service {
5353

5454
// Create expects the configuration within the given ResourceData and sends it to the Dynatrace Server in order to create that resource
5555
func Create(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
56-
d.SetId(uuid.New().String())
5756
config := new(diskevents.AnomalyDetection)
57+
config.ID = opt.NewString(d.Id())
5858
if err := config.UnmarshalHCL(hcl.DecoderFrom(d)); err != nil {
5959
return diag.FromErr(err)
6060
}
@@ -69,6 +69,7 @@ func Create(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Dia
6969
// Update expects the configuration within the given ResourceData and send them to the Dynatrace Server in order to update that resource
7070
func Update(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
7171
config := new(diskevents.AnomalyDetection)
72+
config.ID = opt.NewString(d.Id())
7273
if err := config.UnmarshalHCL(hcl.DecoderFrom(d)); err != nil {
7374
return diag.FromErr(err)
7475
}

anomalies/hosts/resource.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,14 @@ func NewService(m interface{}) *hosts.Service {
5252

5353
// Create expects the configuration within the given ResourceData and sends it to the Dynatrace Server in order to create that resource
5454
func Create(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
55-
d.SetId("dynatrace_host_anomalies")
5655
config := new(hosts.AnomalyDetection)
5756
if err := config.UnmarshalHCL(hcl.DecoderFrom(d)); err != nil {
5857
return diag.FromErr(err)
5958
}
6059
if err := NewService(m).Update(config); err != nil {
6160
return diag.FromErr(err)
6261
}
63-
d.SetId("dynatrace_host_anomalies")
62+
d.SetId("dynatrace_host_anomalies")
6463
return Read(ctx, d, m)
6564
}
6665

anomalies/metrics/resource.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import (
2323
"github.com/dtcookie/dynatrace/api/config/anomalies/metricevents"
2424
"github.com/dtcookie/dynatrace/rest"
2525
"github.com/dtcookie/hcl"
26+
"github.com/dtcookie/opt"
2627
"github.com/dynatrace-oss/terraform-provider-dynatrace/config"
2728
"github.com/dynatrace-oss/terraform-provider-dynatrace/hcl2sdk"
2829
"github.com/dynatrace-oss/terraform-provider-dynatrace/logging"
29-
"github.com/google/uuid"
3030

3131
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
3232
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -53,7 +53,6 @@ func NewService(m interface{}) *metricevents.Service {
5353

5454
// Create expects the configuration within the given ResourceData and sends it to the Dynatrace Server in order to create that resource
5555
func Create(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
56-
d.SetId(uuid.New().String())
5756
config := new(metricevents.MetricEvent)
5857
if err := config.UnmarshalHCL(hcl.DecoderFrom(d)); err != nil {
5958
return diag.FromErr(err)
@@ -70,6 +69,7 @@ func Create(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Dia
7069
// Update expects the configuration within the given ResourceData and send them to the Dynatrace Server in order to update that resource
7170
func Update(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
7271
config := new(metricevents.MetricEvent)
72+
config.ID = opt.NewString(d.Id())
7373
if err := config.UnmarshalHCL(hcl.DecoderFrom(d)); err != nil {
7474
return diag.FromErr(err)
7575
}

anomalies/services/resource.go

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ func NewService(m interface{}) *services.Service {
5252

5353
// Create expects the configuration within the given ResourceData and sends it to the Dynatrace Server in order to create that resource
5454
func Create(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
55-
d.SetId("dynatrace_service_anomalies")
5655
config := new(services.AnomalyDetection)
5756
if err := config.UnmarshalHCL(hcl.DecoderFrom(d)); err != nil {
5857
return diag.FromErr(err)

docs/index.md

+7-13
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,27 @@ The Dynatrace Terraform Provider is used to interact with the resources supporte
1212
Use the links to the left to learn about the available resources.
1313

1414
## Example
15-
```
16-
# Terraform 0.13+ uses the Terraform Registry:
1715

16+
# Terraform 0.13+ uses the Terraform Registry:
17+
```
1818
terraform {
1919
required_version = "~> 0.13.0"
2020
required_providers {
2121
dynatrace = {
22+
version = "1.2.2"
2223
source = "dynatrace.com/com/dynatrace"
2324
}
2425
}
25-
}
26-
26+
}
27+
```
2728
# Configure the Dynatrace provider
29+
```
2830
provider "dynatrace" {
2931
dt_env_url = "https://########.live.dynatrace.com"
3032
dt_api_token = "################"
3133
}
32-
33-
# Terraform 0.12- can be specified as:
34-
terraform {
35-
required_providers {
36-
dynatrace = {
37-
version = "1.0.11"
38-
}
39-
}
40-
}
4134
```
35+
where `dt_env_url` represents the URL of your Dynatrace Environment and `dt_api_token` needs to be an API Token with the permissions `Read configuration` and `Capture request data`.
4236

4337
<!-- schema generated by tfplugindocs -->
4438
## Schema

0 commit comments

Comments
 (0)