Skip to content

Commit

Permalink
Merge branch 'main' into feat/add_env_var_options_for_DT_CONF_MAN
Browse files Browse the repository at this point in the history
  • Loading branch information
dcryans committed Jun 16, 2023
2 parents a36bd6c + 9c7c8e3 commit 2790eca
Show file tree
Hide file tree
Showing 435 changed files with 18,576 additions and 2,403 deletions.
262 changes: 257 additions & 5 deletions .github/workflows/tests.yml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions datasources/alerting/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import (
"sort"

"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api"
managementzonessrv "github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/builtin/managementzones"
managementzones "github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/builtin/managementzones/settings"
alertingsrv "github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/v2/alerting"
alerting "github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/v2/alerting/settings"
managementzonessrv "github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/v2/managementzones"
managementzones "github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/v2/managementzones/settings"
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/settings/services/cache"
"github.com/dynatrace-oss/terraform-provider-dynatrace/provider/config"
"github.com/dynatrace-oss/terraform-provider-dynatrace/provider/logging"
Expand Down
62 changes: 62 additions & 0 deletions datasources/credentials/aws/data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @license
* Copyright 2020 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package aws

import (
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api"
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/export"
"github.com/dynatrace-oss/terraform-provider-dynatrace/provider/config"
"github.com/dynatrace-oss/terraform-provider-dynatrace/provider/logging"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func DataSource() *schema.Resource {
return &schema.Resource{
Read: logging.EnableDS(DataSourceRead),
Schema: map[string]*schema.Schema{
"label": {
Type: schema.TypeString,
Required: true,
},
},
}
}

func DataSourceRead(d *schema.ResourceData, m any) (err error) {
var label string
if v, ok := d.GetOk("label"); ok {
label = v.(string)
}

service := export.Service(config.Credentials(m), export.ResourceTypes.AWSCredentials)
var stubs api.Stubs
if stubs, err = service.List(); err != nil {
return err
}
if len(stubs) > 0 {
for _, stub := range stubs {
if label == stub.Name {
d.SetId(stub.ID)
return nil
}
}
}

d.SetId("")
return nil
}
75 changes: 75 additions & 0 deletions datasources/credentials/aws/supported_services/data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* @license
* Copyright 2020 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package supported_services

import (
"strings"

"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/v1/config/credentials/aws/services"
"github.com/dynatrace-oss/terraform-provider-dynatrace/provider/config"
"github.com/dynatrace-oss/terraform-provider-dynatrace/provider/logging"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func DataSource() *schema.Resource {
return &schema.Resource{
Read: logging.EnableDS(DataSourceRead),
Schema: map[string]*schema.Schema{
"except": {
Type: schema.TypeSet,
Optional: true,
Description: "Services with the given names won't be included in the results",
Elem: &schema.Schema{Type: schema.TypeString},
},
"services": {
Type: schema.TypeMap,
Computed: true,
Description: "The keys are the names of the supported services. The values provide information whether that service is built in or not.",
Elem: &schema.Schema{Type: schema.TypeBool},
},
},
}
}

func DataSourceRead(d *schema.ResourceData, m any) (err error) {
theID := "79cd7a0e-8a89-4234-a4ad-c771de2d59ff"
except := map[string]string{}
if iExcept, ok := d.GetOk("except"); ok && iExcept != nil {
for _, elem := range iExcept.(*schema.Set).List() {
el := strings.TrimSpace(strings.ToLower(elem.(string)))
except[el] = el
theID = theID + ":" + el
}
}
srvc := services.NewSupportedServicesService(config.Credentials(m))
all, err := srvc.List()
if err != nil {
return err
}
srvmap := map[string]bool{}
for k, v := range all {
lk := strings.ToLower(k)
if _, found := except[lk]; !found {
srvmap[lk] = v.BuiltIn
}
}
d.Set("services", srvmap)
d.SetId(theID)
return nil
}
62 changes: 62 additions & 0 deletions datasources/credentials/azure/data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @license
* Copyright 2020 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package azure

import (
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api"
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/export"
"github.com/dynatrace-oss/terraform-provider-dynatrace/provider/config"
"github.com/dynatrace-oss/terraform-provider-dynatrace/provider/logging"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func DataSource() *schema.Resource {
return &schema.Resource{
Read: logging.EnableDS(DataSourceRead),
Schema: map[string]*schema.Schema{
"label": {
Type: schema.TypeString,
Required: true,
},
},
}
}

func DataSourceRead(d *schema.ResourceData, m any) (err error) {
var label string
if v, ok := d.GetOk("label"); ok {
label = v.(string)
}

service := export.Service(config.Credentials(m), export.ResourceTypes.AzureCredentials)
var stubs api.Stubs
if stubs, err = service.List(); err != nil {
return err
}
if len(stubs) > 0 {
for _, stub := range stubs {
if label == stub.Name {
d.SetId(stub.ID)
return nil
}
}
}

d.SetId("")
return nil
}
21 changes: 20 additions & 1 deletion datasources/entity/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ func DataSource() *schema.Resource {
Optional: true,
ConflictsWith: []string{"type", "name"},
},
"properties": {
Type: schema.TypeMap,
Description: "Properties defining the entity.",
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
}
}
Expand All @@ -69,19 +75,32 @@ func DataSourceRead(d *schema.ResourceData, m any) error {
if err := service.Get(service.SchemaID(), &settings); err != nil {
return err
}
d.SetId(service.SchemaID())
if len(settings.Entities) != 0 {
if len(name) > 0 {
// When looking for a specific name
// The first entity that matches that name will be returned
for _, entity := range settings.Entities {
if name == *entity.DisplayName {
d.SetId(*entity.EntityId)
if len(entity.Properties) > 0 {
d.Set("properties", entity.Properties)
}
return nil
}
}
// No entity with that name -> ID empty string signals not found
d.SetId("")
return nil
}
// When looking via entity_selector the first result
// will be returned
d.SetId(*settings.Entities[0].EntityId)
if len(settings.Entities[0].Properties) > 0 {
d.Set("properties", settings.Entities[0].Properties)
}
return nil
}
// Without any matches we're setting the ID to an empty string
d.SetId("")
return nil
}
62 changes: 62 additions & 0 deletions datasources/failuredetection/parameters/data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @license
* Copyright 2020 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package failuredetectionparameters

import (
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api"
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/export"
"github.com/dynatrace-oss/terraform-provider-dynatrace/provider/config"
"github.com/dynatrace-oss/terraform-provider-dynatrace/provider/logging"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func DataSource() *schema.Resource {
return &schema.Resource{
Read: logging.EnableDS(DataSourceRead),
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
},
}
}

func DataSourceRead(d *schema.ResourceData, m any) (err error) {
var name string
if v, ok := d.GetOk("name"); ok {
name = v.(string)
}

service := export.Service(config.Credentials(m), export.ResourceTypes.FailureDetectionParameters)
var stubs api.Stubs
if stubs, err = service.List(); err != nil {
return err
}
if len(stubs) > 0 {
for _, stub := range stubs {
if name == stub.Name {
d.SetId(stub.ID)
return nil
}
}
}

d.SetId("")
return nil
}
4 changes: 2 additions & 2 deletions datasources/mgmz/data_source_multiple.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"sort"

"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api"
managementzonessrv "github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/v2/managementzones"
managementzones "github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/v2/managementzones/settings"
managementzonessrv "github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/builtin/managementzones"
managementzones "github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/builtin/managementzones/settings"
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/settings/services/cache"
"github.com/dynatrace-oss/terraform-provider-dynatrace/provider/config"
"github.com/dynatrace-oss/terraform-provider-dynatrace/provider/logging"
Expand Down
60 changes: 60 additions & 0 deletions datasources/synthetic/nodes/data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* @license
* Copyright 2020 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package nodes

import (
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api"
nodes "github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/v1/config/synthetic/nodes"
nodessettings "github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/v1/config/synthetic/nodes/settings"
"github.com/dynatrace-oss/terraform-provider-dynatrace/provider/config"
"github.com/dynatrace-oss/terraform-provider-dynatrace/provider/logging"
"github.com/dynatrace-oss/terraform-provider-dynatrace/terraform/hcl"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func DataSource() *schema.Resource {
return &schema.Resource{
Read: logging.EnableDS(DataSourceRead),
Schema: map[string]*schema.Schema{
"nodes": {
Type: schema.TypeList,
Elem: &schema.Resource{Schema: new(nodessettings.Settings).Schema()},
Computed: true,
},
},
}
}

func DataSourceRead(d *schema.ResourceData, m any) (err error) {
var stubs api.Stubs
if stubs, err = nodes.Service(config.Credentials(m)).List(); err != nil {
return err
}
nodes := []*nodessettings.Settings{}
for _, stub := range stubs {
value := stub.Value.(nodessettings.Settings)
nodes = append(nodes, &value)
}
marshalled := hcl.Properties{}
if marshalled.EncodeSlice("nodes", nodes); err != nil {
return err
}
d.Set("nodes", marshalled["nodes"])
d.SetId("DYNATRACE_SYNTHETIC_NODES")
return nil
}
Loading

0 comments on commit 2790eca

Please sign in to comment.