dynatrace-oss / terraform-provider-dynatrace

Apache License 2.0
71 stars 33 forks source link

Exporting with -flat and -ref results in duplicate dynatrace_entity resources #586

Closed myrveln closed 1 week ago

myrveln commented 1 week ago

Describe the bug When running the export on command-line, using a combination of -flat, -import-state and -ref. I get errors during initializing terraform due to duplicate data resources in configuration/___datasources___.tf.

Executing 'terraform init'
Error: Duplicate data "dynatrace_entity" configuration

To Reproduce

  1. Run the export with the following flags: ./terraform-provider-dynatrace -export -flat -import-state -ref dynatrace_muted_requests

Expected behavior Removing the -flat flag in the above command will result in a configuration/modules/muted_requests/datasources.tf with a single data resource, and the terraform init will not result with errors.

Additional context Output log from the command, service_id deducted:

# ./terraform-provider-dynatrace -export -flat -import-state -ref dynatrace_muted_requests
The environment variable DYNATRACE_TARGET_FOLDER has not been set - using folder 'configuration' as default
Downloading "dynatrace_muted_requests" Count:  1  
Post-Processing Resources ...
- [POSTPROCESS] dynatrace_muted_requests - SERVICE-0000000000000000Post-Processing Resources - Group child configs with parent configs ...
Finishing touches ...
Writing ___datasources___.tf
Writing ___variables___.tf
Writing main ___providers___.tf
Remove Non-Referenced Modules ...
Finish Export ...
Terraform executable path:  /opt/homebrew/bin/terraform
Executing 'terraform init'

Error: Terraform encountered problems during initialisation, including problems
with the configuration, described below.

The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.

Error: Duplicate data "dynatrace_entity" configuration

  on ___datasources___.tf line 6:
   6: data "dynatrace_entity" "SERVICE-0000000000000000" {

A dynatrace_entity data resource named "SERVICE-0000000000000000" was already
declared at ___datasources___.tf:1,1-51. Resource names must be unique per
type in each module.

Error: Duplicate data "dynatrace_entity" configuration

  on ___datasources___.tf line 6:
   6: data "dynatrace_entity" "SERVICE-0000000000000000" {

A dynatrace_entity data resource named "SERVICE-0000000000000000" was already
declared at ___datasources___.tf:1,1-51. Resource names must be unique per
type in each module.
Importing Resources into Terraform State ...
Refreshing State - Plan ...
out: 
err: 
Error: Duplicate data "dynatrace_entity" configuration

  on ___datasources___.tf line 6:
   6: data "dynatrace_entity" "SERVICE-0000000000000000" {

A dynatrace_entity data resource named "SERVICE-0000000000000000" was already
declared at ___datasources___.tf:1,1-51. Resource names must be unique per
type in each module.

Refreshing State - Apply ...
out: 
err: 
Error: Failed to load "terraform.plan" as a plan file

Error: stat terraform.plan: no such file or directory

Imported Resources into Terraform State ...
... finished after 7 seconds

Dynatrace Provider version: 1.69.1

Reinhard-Pilz-Dynatrace commented 1 week ago

Hello @myrveln, thanks for reporting this issue. It will be fixed with the upcoming release of the provider.