hashicorp / terraform-provider-azuread

Terraform provider for Azure Active Directory
https://registry.terraform.io/providers/hashicorp/azuread/latest/docs
Mozilla Public License 2.0
415 stars 280 forks source link

Errors importing azuread_access_package_assignment_policy containing multiple choice questions #1425

Open tjrobinson opened 6 days ago

tjrobinson commented 6 days ago

When importing an azuread_access_package_assignment_policy resource containing multiple choice questions, it errors with:

│ Error: Retrieving access package assignment policy with object ID: "b4118c2f-5ccc-434e-a5bf-5335d1595cf5"
│
│ json.Unmarshal(): json: invalid use of ,string struct tag, trying to unmarshal "Yes" into string
Full example output ```text > terraform plan var.tenant_id Microsoft Entra Tenant ID Enter a value: XXXXXXXXXXXXXXXXX azuread_access_package.example_package: Preparing import... [id=d4300416-ec6c-4b5c-b7a7-71c54bed555c] azuread_access_package_catalog.example_catalog: Preparing import... [id=c018eef6-34df-4edc-9f24-ba35f1c80a2e] azuread_access_package_catalog.example_catalog: Refreshing state... [id=c018eef6-34df-4edc-9f24-ba35f1c80a2e] azuread_access_package.example_package: Refreshing state... [id=d4300416-ec6c-4b5c-b7a7-71c54bed555c] azuread_access_package_assignment_policy.example_policy: Preparing import... [id=b4118c2f-5ccc-434e-a5bf-5335d1595cf5] azuread_access_package_assignment_policy.example_policy: Refreshing state... [id=b4118c2f-5ccc-434e-a5bf-5335d1595cf5] Terraform planned the following actions, but then encountered a problem: # azuread_access_package.example_package will be imported resource "azuread_access_package" "example_package" { catalog_id = "c018eef6-34df-4edc-9f24-ba35f1c80a2e" description = "An example access package" display_name = "My Access Package" hidden = false id = "d4300416-ec6c-4b5c-b7a7-71c54bed555c" } # azuread_access_package_catalog.example_catalog will be imported resource "azuread_access_package_catalog" "example_catalog" { description = "An example catalog for testing access packages" display_name = "Example Catalog" externally_visible = false id = "c018eef6-34df-4edc-9f24-ba35f1c80a2e" published = true } Plan: 2 to import, 0 to add, 0 to change, 0 to destroy. ╷ │ Error: Retrieving access package assignment policy with object ID: "b4118c2f-5ccc-434e-a5bf-5335d1595cf5" │ │ json.Unmarshal(): json: invalid use of ,string struct tag, trying to unmarshal "Yes" into string ╵ ```

Community Note

Terraform (and AzureAD Provider) Version

Terraform v1.9.0
on windows_amd64
+ provider registry.terraform.io/hashicorp/azuread v2.53.1

Affected Resource(s)

Terraform Configuration Files

terraform {
  required_providers {
    azuread = {
      source  = "hashicorp/azuread"
      version = "~> 2.53.1"
    }
  }

  required_version = "~> 1.9.0"
}

provider "azuread" {
  tenant_id = var.tenant_id
}

variable "tenant_id" {
  type        = string
  description = "Microsoft Entra Tenant ID"
}

resource "azuread_access_package_catalog" "example_catalog" {
  display_name       = "Example Catalog"
  description        = "An example catalog for testing access packages"
  externally_visible = false
}

resource "azuread_access_package" "example_package" {
  catalog_id   = "c018eef6-34df-4edc-9f24-ba35f1c80a2e"
  description  = "An example access package"
  display_name = "My Access Package"
  hidden       = false
}

resource "azuread_access_package_assignment_policy" "example_policy" {
  display_name      = "Initial Policy"
  access_package_id = azuread_access_package.example_package.id
  description       = "Initial Policy"
}

import {
  to = azuread_access_package_catalog.example_catalog
  id = "c018eef6-34df-4edc-9f24-ba35f1c80a2e"
}

import {
  to = azuread_access_package.example_package
  id = "d4300416-ec6c-4b5c-b7a7-71c54bed555c"
}

import {
  to = azuread_access_package_assignment_policy.example_policy
  id = "b4118c2f-5ccc-434e-a5bf-5335d1595cf5"
}

Debug Output

Available on request.

Expected Behavior

The resource should import without any errors.

Actual Behavior

It errors, see above.

Steps to Reproduce

Create an access package assignment policy with multiple choice questions, for example:

image

image

Graph API (beta) data - trimmed to `questions` section only ```json "questions": [ { "@odata.type": "#microsoft.graph.accessPackageMultipleChoiceQuestion", "id": "71721dd4-5fd1-4018-9164-e75282feadc2", "isRequired": false, "isAnswerEditable": null, "text": "Are you sure?", "sequence": 0, "isMultipleSelectionAllowed": false, "localizations": [], "choices": [ { "text": "Yes", "actualValue": "Yes", "localizations": [ { "text": "Yes", "languageCode": "en-GB" } ] }, { "text": "No", "actualValue": "No", "localizations": [ { "text": "No", "languageCode": "en-GB" } ] } ] } ], ```

Import this assignment policy (see code above).

Run terraform plan

Important Factoids

References

N/A