Issue with 'aws_acm_certificate_validation' resource importing to terraform state file?

I'm moving terraform resources from one project to another. I have resource "aws_route53_record", which was validated by the "aws_acm_certificate_validation" resource.

I've successfully imported "aws_route53_record" to the terraform state file, as soon as we have an official instruction in the Terraform documentation for that.

I checked official Terraform documentation for the "aws_acm_certificate_validation" resource and I haven't found a way how to import such resource.

Have someone been faced with such a question?

P.S. I can see that resource (terraform state list) in the Terraform state file (project from which I'm moving resources)

Upvotes: 4

Views: 2508

Answers (3)

0xF4D3C0D3
0xF4D3C0D3

Reputation: 827

If you already have the state without any diff, try this

Extract Old State: In your old Terraform module, run terraform state pull > old_state.json. This command pulls the current state and saves it to old_state.json.

Extract New State: In your new Terraform module, execute terraform state pull > new_state.json. This retrieves the state for the new module and stores it in new_state.json.

Copy Resource Definition: Manually transfer the aws_acm_certificate_validation resource block from old_state.json to new_state.json. This step involves editing the JSON files directly.

Run Terraform Plan: Execute terraform plan in the new module directory. This will display the proposed changes, likely indicating the destruction of the resource in the old state and its creation in the new state.

Move State Resource: Finally, use terraform state mv {old_resource} {new_resource}. Replace {old_resource} and {new_resource} with the appropriate resource addresses. This command moves the state of the specified resource from the old module to the new module, preventing Terraform from destroying and recreating it.


I don't think this method is safe or good, but it's the only solution I know that works.

Upvotes: 0

Francisco Cardoso
Francisco Cardoso

Reputation: 1968

If you moved the certificate correctly, shouldn't have any issues applying or destroying that resource. That's because nothing is going to happen on AWS side, just the state will be updated.

Upvotes: 0

This resource shouldn't be imported as soon as AWS doesn't have such an entity inside.

Upvotes: 1

Related Questions