microsoft / terraform-provider-power-platform

Power Platform Terraform Provider
https://registry.terraform.io/providers/microsoft/power-platform/latest/docs
MIT License
35 stars 13 forks source link

Changing Environment type from "Sandbox" to "Production" creates a new environment_id #468

Closed eduardodfmex closed 1 month ago

eduardodfmex commented 1 month ago

Changing Environment type from "Sandbox" to "Production" creates a new environment_id

Changing Environment type from "Sandbox" to "Production" creates a new environment_id and all the configuration on the state is broken because all the resources that use the environment_id now points to a new environment.

│ Error: Provider produced inconsistent result after apply │ │ When applying changes to │ module.test.module.power_platform.powerplatform_environment_settings.pp_environment_settings, │ provider "provider[\"registry.terraform.io/microsoft/power-platform\"]" │ produced an unexpected new value: .environment_id: was │ cty.StringVal("91b08444-52a6-e176-8ca4-b2db8599XXXX"), but now │ cty.StringVal("3484dea0-fa1e-e88a-b826-06567fd4XXXX"). │ │ This is a bug in the provider, which should be reported in the provider's │ own issue tracker.

To Reproduce

Steps to reproduce the behavior:

  1. You create a new environment with environment type "Sandbox", with: environment_type = "Sandbox"
  2. Deploy the environment
  3. You change the environment type value from Sandbox to Production and deploy the change: environment_type = "Production"
  4. Alternately you can add settings to see the error.
  5. You will see that the environment_id is different.

Sample Terraform Code

If applicable, add terraform code to help explain your problem.

terraform {
  required_providers {
    powerplatform = {
      source = "microsoft/power-platform"
    }
  }
}

provider "powerplatform" {
  use_cli = true
}

resource "powerplatform_environment" "example_environment_settings" {
  display_name     = "example_environment_settings"
  location         = "europe"
  environment_type = "Sandbox"
  dataverse = {
    language_code     = "1033"
    currency_code     = "USD"
    security_group_id = "00000000-0000-0000-0000-000000000000"
  }
}

resource "powerplatform_environment_settings" "settings" {
  environment_id = powerplatform_environment.example_environment_settings.id

  audit_and_logs = {
    plugin_trace_log_setting = "Exception"
    audit_settings = {
      is_audit_enabled             = true
      is_user_access_audit_enabled = true
      is_read_audit_enabled        = true
    }
  }
  email = {
    email_settings = {
      max_upload_file_size_in_bytes = 123456
    }
  }
  product = {
    behavior_settings = {
      show_dashboard_cards_in_expanded_state = true
    }
    features = {
      power_apps_component_framework_for_canvas_apps = false
    }
  }
}

Expected behavior

If I change the environment type from Sandbox to production the environment_id should be the same and tied resources and configuration can conserve the same environment_id.

System Information

Additional context

Add any other context about the problem here.

Contribution

mattdot commented 1 month ago

@eduardodfmex can you confirm that this is still an issue in 3.0.0

eduardodfmex commented 1 month ago

I will test with 3.0.0

eduardodfmex commented 1 month ago

@mattdot I confirm yes, is still an issue in 3.0.0.

Is destroying the Environment and creating a new one and ends with error:

Plan: 1 to add, 1 to change, 1 to destroy.

Changes to Outputs: ~ environment_id = "a1deee2c-f6aa-ee7b-b0c7-c36fec629443" -> (known after apply) ~ environment_type = "Sandbox" -> "Production"

Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve.

Enter a value: yes

powerplatform_environment.example_environment_settings: Destroying... [id=a1deee2c-f6aa-ee7b-b0c7-c36fec629443] powerplatform_environment.example_environment_settings: Still destroying... [id=a1deee2c-f6aa-ee7b-b0c7-c36fec629443, 10s elapsed] powerplatform_environment.example_environment_settings: Still destroying... [id=a1deee2c-f6aa-ee7b-b0c7-c36fec629443, 20s elapsed] powerplatform_environment.example_environment_settings: Still destroying... [id=a1deee2c-f6aa-ee7b-b0c7-c36fec629443, 30s elapsed] powerplatform_environment.example_environment_settings: Destruction complete after 3m7s powerplatform_environment.example_environment_settings: Creating...

│ Error: Provider produced inconsistent result after apply │ │ When applying changes to powerplatform_environment_settings.settings, provider "provider[\"registry.terraform.io/microsoft/power-platform\"]" produced an unexpected new value: .environment_id: was │ cty.StringVal("06ae29e4-724f-e98e-9d8c-2dce9bf3f650"), but now cty.StringVal("a1deee2c-f6aa-ee7b-b0c7-c36fec629443"). │ │ This is a bug in the provider, which should be reported in the provider's own issue tracker.