Skip to content

Commit

Permalink
Introduced dynatrace_cloud_development_environments resource
Browse files Browse the repository at this point in the history
  • Loading branch information
kishikawa12 committed Nov 5, 2024
1 parent 912a151 commit d0c07b5
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 2 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,19 @@ jobs:
DT_CLIENT_SECRET: ${{ secrets.DT_CLIENT_SECRET }}
DT_ACCOUNT_ID: ${{ secrets.DT_ACCOUNT_ID }}
run: go test -v ./dynatrace/api/app/dynatrace/infraops/settings
- name: TestAccCloudDevelopmentEnvironments
if: success() || failure()
env:
GOPROXY: "https://proxy.golang.org"
TF_ACC: true
DYNATRACE_DEBUG: true
DT_NO_REPAIR_INPUT: false
DYNATRACE_ENV_URL: ${{ secrets.DYNATRACE_ENV_URL }}
DYNATRACE_API_TOKEN: ${{ secrets.DYNATRACE_API_TOKEN }}
DT_CLIENT_ID: ${{ secrets.DT_CLIENT_ID }}
DT_CLIENT_SECRET: ${{ secrets.DT_CLIENT_SECRET }}
DT_ACCOUNT_ID: ${{ secrets.DT_ACCOUNT_ID }}
run: go test -v ./dynatrace/api/builtin/appengineregistry/clouddevelopmentenvironments
- name: TestAccHistogramMetrics
if: success() || failure()
env:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"allowedScopes": [
"environment"
],
"description": "In order to enable Cloud Development Environment (CDE) for application development, the respective domains need to be configured here.",
"displayName": "Cloud Development Environments",
"documentation": "",
"dynatrace": "1",
"enums": {},
"maxObjects": 1,
"multiObject": false,
"properties": {
"cloudDevelopmentEnvironments": {
"description": "The URL to allow app development from. E.g. `https://*.my-company.my-cde-provider.com`.",
"displayName": "Cloud Development Environments",
"documentation": "",
"items": {
"constraints": [
{
"customMessage": "Not a valid URL. Use \"https://[*.]host[:port]\"",
"pattern": "^https://(\\x2a\\.)?[^\\s/?#.\\x2a:]+?(\\.[^\\s/?#.\\x2a:]+?)*(:[0-9]{1,5})?$",
"type": "PATTERN"
},
{
"customMessage": "Special characters [;'] are not supported",
"pattern": "^[^;']+$",
"type": "PATTERN"
},
{
"maxLength": 500,
"minLength": 1,
"type": "LENGTH"
},
{
"customMessage": "Not a valid URI",
"pattern": "^(([^\\s:/?#]+?):){1}((//)?([^\\s/?#]+?)){1}([^\\s?#]*?)(\\?([^\\s#]*?))?(#([^\\s]*?))?$",
"type": "PATTERN"
},
{
"customMessage": "Not a valid http(s) URL",
"pattern": "^https?://.*$",
"type": "PATTERN"
}
],
"description": "",
"displayName": "",
"documentation": "",
"subType": "url",
"type": "text"
},
"maxObjects": 20,
"minObjects": 0,
"modificationPolicy": "DEFAULT",
"nullable": false,
"type": "set"
}
},
"schemaGroups": [
"group:dt-apps-development",
"group:preferences"
],
"schemaId": "builtin:app-engine-registry.cloud-development-environments",
"types": {},
"version": "1.1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @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 clouddevelopmentenvironments

import (
clouddevelopmentenvironments "github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/builtin/appengineregistry/clouddevelopmentenvironments/settings"
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/settings"
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/settings/services/settings20"
)

const SchemaVersion = "1.1"
const SchemaID = "builtin:app-engine-registry.cloud-development-environments"

func Service(credentials *settings.Credentials) settings.CRUDService[*clouddevelopmentenvironments.Settings] {
return settings20.Service[*clouddevelopmentenvironments.Settings](credentials, SchemaID, SchemaVersion)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @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 clouddevelopmentenvironments_test

import (
"testing"

"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/testing/api"
)

func TestAccCloudDevelopmentEnvironments(t *testing.T) {
api.TestAcc(t)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* @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 clouddevelopmentenvironments

import (
"github.com/dynatrace-oss/terraform-provider-dynatrace/terraform/hcl"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

type Settings struct {
CloudDevelopmentEnvironments []string `json:"cloudDevelopmentEnvironments,omitempty"` // The URL to allow app development from. E.g. `https://*.my-company.my-cde-provider.com`.
}

func (me *Settings) Name() string {
return "cloud_development_environments"
}

func (me *Settings) Schema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"cloud_development_environments": {
Type: schema.TypeSet,
Description: "The URL to allow app development from. E.g. `https://*.my-company.my-cde-provider.com`.",
Optional: true, // minobjects == 0
Elem: &schema.Schema{Type: schema.TypeString},
},
}
}

func (me *Settings) MarshalHCL(properties hcl.Properties) error {
return properties.EncodeAll(map[string]any{
"cloud_development_environments": me.CloudDevelopmentEnvironments,
})
}

func (me *Settings) UnmarshalHCL(decoder hcl.Decoder) error {
return decoder.DecodeAll(map[string]any{
"cloud_development_environments": &me.CloudDevelopmentEnvironments,
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "dynatrace_cloud_development_environments" "#name#" {
cloud_development_environments = ["https://example1.my-company.my-cde-provider.com", "https://example2.my-company.my-cde-provider.com", "https://example3.my-company.my-cde-provider.com"]
}
2 changes: 2 additions & 0 deletions dynatrace/export/enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ var ResourceTypes = struct {
OpenPipelineSecurityEvents ResourceType
OpenPipelineBusinessEvents ResourceType
OpenPipelineSDLCEvents ResourceType
CloudDevelopmentEnvironments ResourceType
}{
"dynatrace_autotag",
"dynatrace_autotag_v2",
Expand Down Expand Up @@ -785,6 +786,7 @@ var ResourceTypes = struct {
"dynatrace_openpipeline_security_events",
"dynatrace_openpipeline_business_events",
"dynatrace_openpipeline_sdlc_events",
"dynatrace_cloud_development_environments",
}

func (me ResourceType) GetFolderName(override string) string {
Expand Down
6 changes: 4 additions & 2 deletions dynatrace/export/resource_descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import (
web_app_anomalies "github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/builtin/anomalydetection/rum/web"
service_anomalies_v2 "github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/builtin/anomalydetection/services"
apidetection "github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/builtin/apis/detectionrules"
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/builtin/appengineregistry/clouddevelopmentenvironments"
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/builtin/appsec/attackprotectionadvancedconfig"
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/builtin/appsec/attackprotectionallowlistconfig"
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/builtin/appsec/attackprotectionsettings"
Expand Down Expand Up @@ -1361,8 +1362,9 @@ var AllResources = map[ResourceType]ResourceDescriptor{
Coalesce(Dependencies.CloudApplicationNamespace),
Coalesce(Dependencies.K8sCluster),
),
ResourceTypes.DevObsDataMasking: NewResourceDescriptor(devobsmasking.Service),
ResourceTypes.DavisCoPilot: NewResourceDescriptor(dataminingblocklist.Service),
ResourceTypes.DevObsDataMasking: NewResourceDescriptor(devobsmasking.Service),
ResourceTypes.DavisCoPilot: NewResourceDescriptor(dataminingblocklist.Service),
ResourceTypes.CloudDevelopmentEnvironments: NewResourceDescriptor(clouddevelopmentenvironments.Service),
}

type ResourceExclusion struct {
Expand Down
1 change: 1 addition & 0 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ func Provider() *schema.Provider {
"dynatrace_openpipeline_security_events": resources.NewGeneric(export.ResourceTypes.OpenPipelineSecurityEvents).Resource(),
"dynatrace_openpipeline_business_events": resources.NewGeneric(export.ResourceTypes.OpenPipelineBusinessEvents).Resource(),
"dynatrace_openpipeline_sdlc_events": resources.NewGeneric(export.ResourceTypes.OpenPipelineSDLCEvents).Resource(),
"dynatrace_cloud_development_environments": resources.NewGeneric(export.ResourceTypes.CloudDevelopmentEnvironments).Resource(),
},
ConfigureContextFunc: config.ProviderConfigure,
}
Expand Down
29 changes: 29 additions & 0 deletions templates/resources/cloud_development_environments.md.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
layout: ""
page_title: "dynatrace_cloud_development_environments Resource - terraform-provider-dynatrace"
subcategory: "Environment Settings"
description: |-
The resource `dynatrace_cloud_development_environments` covers configuration for cloud development environments
---

# dynatrace_cloud_development_environments (Resource)

-> This resource requires the API token scopes **Read settings** (`settings.read`) and **Write settings** (`settings.write`)

## Dynatrace Documentation

- AppEngine - https://docs.dynatrace.com/docs/platform/appengine

- Settings API - https://www.dynatrace.com/support/help/dynatrace-api/environment-api/settings (schemaId: `builtin:app-engine-registry.cloud-development-environments`)

## Export Example Usage

- `terraform-provider-dynatrace -export dynatrace_cloud_development_environments` downloads existing cloud development environments configuration

The full documentation of the export feature is available [here](https://dt-url.net/h203qmc).

## Resource Example Usage

{{ tffile "dynatrace/api/builtin/appengineregistry/clouddevelopmentenvironments/testdata/terraform/example_a.tf" }}

{{ .SchemaMarkdown | trimspace }}

0 comments on commit d0c07b5

Please sign in to comment.