hashicorp / terraform-provider-azuread

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

Error: resource address "azuread_application_api_access.add-api-permission[0]" does not exist in the configuration. #1457

Open srawatage opened 2 months ago

srawatage commented 2 months ago

Context : I have App Registration A and App Registration B. A had role1 and role2. I want to assign role1 of A to B as requiredResourceAccess.

I am using azuread_application_api_access providing necessary inputs. When i did a terraform run to add role1 to give required resource access to B. It worked fine . when i ran second pileline to add both role1 and role2 to provide required api access to B. I am getting below error.

I could see terrraform uses object id and app id alone in resource . this is causing issue . becasue for same A and B these will be same . role id is unique identifier here.

Can you help here

Error : module.add-api-access-module[0].azuread_application_api_access.add-api-permission["780exxxxxx-709b-fxx46f22"]: Creating... ╷ │ Error: A resource with the ID "/applications/d0650550-8xxxxe3-bb2d6bfd546c/apiAccess/7970xxcd-1dc34efb6ec8" already exists - to be managed via Terraform this resource needs to be imported into the State. Please see the resource documentation for "azuread_application_api_access" for more information. │ │ with module.add-api-access-module[0].azuread_application_api_access.add-api-permission["780e1xxxxx-709b-f1244b446f22"], │ on ../acm-modules/api-access/access.tf line 31, in resource "azuread_application_api_access" "add-api-permission": │ 31: resource "azuread_application_api_access" "add-api-permission" { │ │ A resource with the ID │ "/applications/d065055xxxxxb2d6bfd546c/apiAccess/79700e3d-a1bc-xxxfb6ec8" │ already exists - to be managed via Terraform this resource needs to be │ imported into the State. Please see the resource documentation for │ "azuread_application_api_access" for more information.

Community Note

Terraform (and AzureAD Provider) Version

Affected Resource(s)

Terraform Configuration Files

# Copy-paste your Terraform configurations here - for large Terraform configs,
# please use a service like Dropbox and share a link to the ZIP file. For
# security, you can also encrypt the files using our GPG public key: https://keybase.io/hashicorp

Debug Output

Panic Output

Expected Behavior

Actual Behavior

Steps to Reproduce

  1. terraform apply

Important Factoids

References

nbaju1 commented 2 months ago

Please provide an example of the Terraform configuration you are using. Much easier to understand your problem and help you if you provide that.