Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to pass instance_profile dynamically as the data block of instance profile is blocking #213

Open
mrt1991d opened this issue Jan 9, 2025 · 0 comments
Labels
bug 🐛 An issue with the system

Comments

@mrt1991d
Copy link

mrt1991d commented Jan 9, 2025

Describe the Bug

unable to pass instance profile dynamically from other module as the below data block is looking for existing resource in aws.

data "aws_iam_instance_profile" "given" {
count = local.enabled && var.instance_profile_enabled && var.instance_profile != "" ? 1 : 0
name = var.instance_profile
}

Expected Behavior

Code should facilitate to pass instance profile externally from other module also, however data block looks for already existing resource in aws

data block is not required as it is not allowing to pass the instance profile dynamically from another module

Steps to Reproduce

module "ec2_instance" {
source = "cloudposse/ec2-instance/aws"
version = "1.6.1"
namespace = var.namespace
stage = var.stage
name = var.name
enabled = var.enabled
ami = var.ami
instance_type = var.instance_type
ssh_key_pair = var.ssh_key_pair
vpc_id = var.vpc_id
subnet = var.subnet
availability_zone = var.availability_zone
security_group_enabled = false
security_groups = var.security_groups
user_data = var.user_data
user_data_base64 = var.user_data_base64
user_data_replace_on_change = var.user_data_replace_on_change
delete_on_termination = var.delete_on_termination
disable_api_stop = var.disable_api_stop
disable_api_termination = var.disable_api_termination
monitoring = var.monitoring
secondary_private_ips = var.external_network_interface_enabled ? null : var.secondary_private_ips
instance_profile_enabled = var.instance_profile_enabled
instance_profile = local.instance_profile
}
locals {
instance_profile = var.instance_profile_enabled && var.custom_instance_profile != "" ? var.custom_instance_profile : (var.instance_profile_enabled ? "BURoleForEC2" : "")
instance_profile_count = var.enabled && var.instance_profile_enabled && var.custom_instance_profile == "" ? 1 : 0
}

Screenshots

Error: reading IAM Instance Profile (BURoleForEC2test): couldn't find resource

with module.test_ec2_1.module.ec2_instance.data.aws_iam_instance_profile.given[0],
on .terraform/modules/test_ec2_1.ec2_instance/main.tf line 84, in data "aws_iam_instance_profile" "given":
84: data "aws_iam_instance_profile" "given" {

Environment

No response

Additional Context

No response

@mrt1991d mrt1991d added the bug 🐛 An issue with the system label Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An issue with the system
Projects
None yet
Development

No branches or pull requests

1 participant