I’m not quite sure how you managed to import aws_ssoadmin_account_assignment.AWSAdministratorAccess in the first place, unless you imported it, and then changed your configuration before executing the plan.
I attempted to replicate this scenario, and Terraform would not perform the import.
@maxb The import ran fine and I did not change anything between import and plan.
My TF version is 0.12 and AWS provider version is 3.37.0 - if that could explain this different behaviour.
I’m sorry, I didn’t understand the square-bracket reference. Can you please give an example, perhaps?
Based on the shape of the plan output included in the question I think this is a slightly older version of Terraform than current; current Terraform would include a brief reason for why it is proposing to destroy the first object.
Given that, my guess is that this older version of Terraform doesn’t yet have the plan-based import mechanism that allows Terraform to evaluate the for_each expression during the import process, whereas recent Terraform releases treat terraform import essentially as a funny kind of plan, with that culminating in the forthcoming v1.5 release where importing is literally integrated into the normal plan and apply flow. But the intermediate step did at least allow the separate import command to detect and report some more error cases, which I think explains the difference in behavior here
Yes, I’ve mentioned above that my TF version is 0.12 and AWS provider version is 3.37.0. Thanks for the info on the v1.5 - I see that it also creates the config files. Gotta check it out.
@maxb , The indexing bit worked! Now, if I have to assign the same permissionset for the same account to another group AZGP-GLOBAL-SSO-AWS-CloudDevOpsSupportAccess is seen in the above screenshot, how do I do that?
If I redo it by just changing the the group name to AZGP-GLOBAL-SSO-AWS-CloudDevOpsSupportAccess, then I get the error :
Error: Resource already managed by Terraform
Terraform is already managing a remote object for
aws_ssoadmin_account_assignment.AWSAdministratorAccess. To import to this
address you must first remove the existing object from the state.
I think you are misunderstanding a core principal of how Terraform works: Every thing that is managed must be represented in the Terraform configuration.
You are apparently trying to manage at least two different things:
An assigment of (account 354840xxxxx, group AdminAccess)
An assignment of (account 354840xxxxx, group SupportAccess)
By changing the existing configuration that you just imported into, you are instructing Terraform to MODIFY OR DELETE WHAT YOU JUST IMPORTED!
It may be useful to you to spend some time practicing creating, updating, and deleting some simple AWS objects using Terraform to get used to how this works, before trying to master importing existing objects.