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

Can't create powerplatform_billing_policy (timeout) #397

Closed marcortw closed 2 months ago

marcortw commented 2 months ago

Describe the bug

I can't seem to create a billing policy - it always ends up in a "timeout reached" message. I've read https://github.com/microsoft/terraform-provider-power-platform/issues/376 and https://github.com/microsoft/terraform-provider-power-platform/pull/392 but from what I can see that should already be in 2.7.0-preview?

To Reproduce

These are the relevant bits of my config:

module "label_pp_environment" {
  source  = "../../modules/labels"
  name    = "env"
  context = module.label.context
}

resource "powerplatform_environment" "ppenv" {
  display_name      = module.label_pp_environment.id
  location          = var.foundation.az_region == "Switzerland North" ? "switzerland" : var.foundation.az_region
  environment_type  = "Sandbox"
  billing_policy_id = powerplatform_billing_policy.pay_as_you_go.id
}

module "label_billing_policy" {
  source  = "../../modules/labels"
  name    = "billingpolicy"
  context = module.label.context
}

resource "powerplatform_billing_policy" "pay_as_you_go" {
  name     = module.label_billing_policy.id
  location = "europe"
  status   = "Enabled"
  billing_instrument = {
    resource_group  = azurerm_resource_group.resource_group.name
    subscription_id = var.subscription_id
  }
}

resource "powerplatform_billing_policy_environment" "pay_as_you_go_policy_envs" {
  billing_policy_id = powerplatform_billing_policy.pay_as_you_go.id
  environments      = [powerplatform_environment.ppenv.id]
}

After tf apply, I get the following error:

...
module.powerplatform_nonprod.powerplatform_billing_policy.pay_as_you_go: Still creating... [3m0s elapsed]
╷
│ Error: Client error when creating powerplatform__billing_policy
│
│   with module.powerplatform_nonprod.powerplatform_billing_policy.pay_as_you_go,
│   on projects\powerplatform-nonprod\environment.tf line 28, in resource "powerplatform_billing_policy" "pay_as_you_go":
│   28: resource "powerplatform_billing_policy" "pay_as_you_go" {
│
│ timeout reached while waiting for billing policy to reach a terminal state (Enabled or Disabled)

The billing policy is not created.

Expected behavior

I can create a billing policy using the microsoft/power-platform provider.

System Information

Additional context

I can create new billing policies in the power platform admin web console, using the same account, without any problems and almost immediate response. I was also wondering if the creation of this policy happens asynchronously and if the cli command was working in the first place, that, despite it would fail with this error, the billing policy should still be created? (I am not very familiar with terraform). I also double-checked subscription ids and the other references - fairly sure they are correct.

mattdot commented 2 months ago

This will be fixed in the next release. The PR has already merged #392