codecutout / terraform-provider-powerbi

Terraform Power BI Provider
MIT License
14 stars 16 forks source link

Issue taking over dataset ownership #42

Open choukimasri opened 3 years ago

choukimasri commented 3 years ago

Hi there, I'm having trouble updating report params and datasources

Terraform Version

14.0.3

Affected Resource(s)

Environment variable names

Azure Managed

Terraform Configuration Files

terraform {
  required_providers {
    powerbi = {
      source  = "codecutout/powerbi"
      version = "1.3.1"
    }
  }
}

variable "client_secret" {
  type = string
}

provider "powerbi" {
  tenant_id     = local.tenantid
  client_id       = local.appid
  client_secret = var.client_secret
}

data "powerbi_workspace" "myworkspace" {
  name = local.WorkspaceName
}

resource "powerbi_pbix" "pbis" {

  for_each          = local.reports
  workspace_id = data.powerbi_workspace.myworkspace.id
  name             = each.value.name
  source           = each.value.pbixfilename
  source_hash  = filemd5(each.value.pbixfilename)

  datasource {
    type            = each.value.datasource.type
    url               = each.value.datasource.url
    original_url = each.value.datasource.original_url
  }

  dynamic "parameter" {
    for_each = each.value.datasource.parameters.updateDetails
    content {
      name  = parameter.value.name
      value = parameter.value.newValue
    }
  }

}

Debug Output

For each report:

Error: Post "https://api.powerbi.com/v1.0/myorg/groups/e8/datasets/d7/Default.UpdateDatasources": status code '403 Forbidden' with body {"error":{"code":"InvalidRequest","message":"This operation is only supported for the dataset owner"}}
2021-05-20T11:11:46.5792582Z 
2021-05-20T11:11:46.5793361Z   on main.tf line 24, in resource "powerbi_pbix" "pbis":
2021-05-20T11:11:46.5794609Z   24: resource "powerbi_pbix" "pbis" {
2021-05-20T11:11:46.5794930Z 

Expected Behavior

No Errors

Actual Behavior

Terraform Error printed and ignored

Steps to Reproduce

terraform apply with pbi resources already deployed manually

alex-davies commented 3 years ago

The provider currently doesn't take over ownership. Most of our use and test cases the user already has ownership as they created the initial report

But I agree this would be a useful thing thing to have, particularly if using a service principal where it is more difficult to get back ownership once its been lost. I am happy to accept PRs

choukimasri commented 3 years ago

I tried to lay ground for this with pr #43 somewhere in the provider, it's certainly far from required but something to get the tracks on rolling.