'Unable to use module output in terraform

I have this tf that is referencing a modules instance role

resource "aws_kms_grant" "grant" {
  name              = "kms-grant"
  key_id            = module.cmk_module.key_id
  grantee_principal = module.elastic_beanstalk.arn
  operations        = ["Encrypt"]

}

The module being called by the grant:

module "elastic_beanstalk" {
  source         = "git::ssh://[email protected]/link-to-module"
  environment    = terraform.workspace
  component_name = "app-microservice"
  #Plus other config....

The modules outputs.tf

output "arn" {
  description = "Fixed iam instance role arn"
  value       = aws_iam_role.ec2.arn
}

When i run a plan on the tf that contains the grant, I get this error:

Error: Unsupported attribute

 on cmk.tf line 25, in resource "aws_kms_grant" “grant”:
 25:   grantee_principal = module.elastic_beanstalk.arn
   
 module.elastic_beanstalk is a object, known only after apply

 This object does not have an attribute named "arn".

How can i fix this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source