Output and resource import

Hello,
is there a way to make imported resource available in output?

Example:

resource aws_acm_certificate "thekey" {
//this will be imported
}

terraform import aws_acm_certificate.thekey <arn_here>

Adding the “output” to the tf file:

resource aws_acm_certificate "thekey" {
//this will be imported
}

output key {
value = aws_acm_certifiicate.thekey
}
Error: Invalid combination of arguments
│ 
│   with aws_acm_certificate.thekey,
│   on acm.tf line 1, in resource "aws_acm_certificate" "thekey":
│    1: resource "aws_acm_certificate" "thekey" {
│ 
│ "domain_name": one of `domain_name,private_key` must be specified

Similar question : Terraform output does not outputs imported resources

Thank you.
AZ

Hi @AZZ,

As far as I can tell from the error message, this problem is not really related to import, and instead it’s caused by your resource configuration being incomplete.

You will need to write a valid configuration for this resource, and then use the import mechanism to tell Terraform that it should apply that configuration to an existing object rather than using it to create a new object.

Once the configuration for this resource is valid, Terraform will be able to derive output values from it regardless of whether it’s deriving from a new object or from an imported object.

1 Like

Today is a beautiful and sunny. As such, I re-examined my approach and … well … I was over complicating things.

A better solution is to simply refer to the aws resource using “data”.

@apparentlymart, thank you for your review and the answer. As usual - you are correct :slight_smile: