This works fine for first time. But If I want to make it dynamic in order to import any number of policies, I don’t know how to do.
The first import was successful but for second & third it failed with error
Terraform is already managing a remote object for aws_iam_policy.customer_managed_policy. To import to this address you must first remove the existing object from the state.
I have explored many ways in google nothing relevent to this found. Hence I’m reaching out to get help from you on how to use import command for importing multiple policies If those are defined in list or map or something. Seeking quick response from you. Thank you
Every resource of any kind imported into Terraform needs to have a unique resource address. In your code example, it only accomodates a single resource address, aws_iam_policy.customer_managed_policy, so using this configuration file, you can only import one policy into each Terraform state file you use this code with.
Even if you get these imports done, what is the point? Since your Terraform code specifies a dummy placeholder value, "{}", actually trying to do any Terraform plan/apply will want to replace the actual policy content with the dummy placeholder.
That’s why I say it’s impossible to figure out where you’re going with all of this, given what you’ve revealed so far, and therefore it’s impossible to advise you how to get there.
Is there any way to write resource of iam_policy to accomadate number of policies for import. Please suggest. My ultimate goal is to import all the policies that are in our AWS account
If you want to import multiple policies you need code which relates to that. Either multiple aws_iam_policy resource blocks, or a single block using count or for_each.
For single block using count or for_each, I can use count or for_each on policy name but import command uses arn argument. In this case how to pass arn value multiple times. Please provide your suggestions with the example