Skip to content

Commit

Permalink
#2 dynamic instance profile
Browse files Browse the repository at this point in the history
  • Loading branch information
ZOI\graham.geary committed Dec 17, 2020
1 parent 262342d commit 3d9576f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions ec2.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ resource "aws_instance" "instance" {
subnet_id = var.subnet_id
vpc_security_group_ids = var.vpc_security_group_ids
user_data = var.user_data
iam_instance_profile = local.iam_instance_profile

# Modifying any of the root_block_device settings other than volume_size requires resource replacement
dynamic "root_block_device" {
Expand Down
5 changes: 3 additions & 2 deletions iam_instance_profile.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
resource "aws_iam_instance_profile" "profile" {
name = var.iam_instance_profile_name
role = var.iam_role_name
count = local.create_iam_instance_profile
name = var.iam_instance_profile_name
role = var.iam_role_name
}
4 changes: 4 additions & 0 deletions locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
locals {
create_iam_instance_profile = var.iam_instance_profile_name == "" ? 0 : 1
iam_instance_profile = var.iam_instance_profile_name == "" ? "" : aws_iam_instance_profile[0].profile.name
}

0 comments on commit 3d9576f

Please sign in to comment.