Skip to content

Commit

Permalink
added ec2 resource creation sample code in instance-profile example
Browse files Browse the repository at this point in the history
  • Loading branch information
dsreehas committed Apr 29, 2024
1 parent 99b18f3 commit 3490e84
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 11 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ No modules.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_assume_role_policy"></a> [assume\_role\_policy](#input\_assume\_role\_policy) | Assume role policy document | `string` | n/a | yes |
| <a name="input_instance_profile_name"></a> [instance\_profile\_name](#input\_instance\_profile\_name) | Name of the IAM Instance Profile | `string` | n/a | yes |
| <a name="input_role_name"></a> [role\_name](#input\_role\_name) | Name of the IAM role | `string` | n/a | yes |
| <a name="input_aws_profile"></a> [aws\_profile](#input\_aws\_profile) | Selected AWS profile | `string` | `null` | no |
| <a name="input_aws_region"></a> [aws\_region](#input\_aws\_region) | Selected AWS region | `string` | `null` | no |
| <a name="input_aws_region"></a> [aws\_region](#input\_aws\_region) | Specified AWS region | `string` | `null` | no |
| <a name="input_inline_policies"></a> [inline\_policies](#input\_inline\_policies) | List of inline policy documents | `list(string)` | `[]` | no |
| <a name="input_managed_policy_arns"></a> [managed\_policy\_arns](#input\_managed\_policy\_arns) | List of managed policy ARNs | `list(string)` | `[]` | no |

Expand Down
11 changes: 8 additions & 3 deletions examples/instance-profile/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module "iam_role" {
source = "github.com/dsreehas/terraform-iam-role"

source = "github.com/dsreehas/terraform-iam-role"
role_name = var.role_name
assume_role_policy = file("./policies/assume_role_policy.json")
inline_policies = [file("./policies/inline_policy_1.json"), file("./policies/inline_policy_2.json")]
Expand All @@ -10,5 +9,11 @@ module "iam_role" {
resource "aws_iam_instance_profile" "iam_instance_profile" {
name = var.instance_profile_name
role = module.iam_role.iam_role_name

}

# resource "aws_instance" "test_instance" {
# ami = var.instance_ami
# instance_type = var.instance_type
# iam_instance_profile = aws_iam_instance_profile.iam_instance_profile.arn

# }
12 changes: 12 additions & 0 deletions examples/instance-profile/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,15 @@ variable "managed_policy_arns" {
type = list(string)
default = ["arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess", "arn:aws:iam::aws:policy/CloudWatchLogsReadOnlyAccess"]
}

variable "instance_ami" {
description = "EC2 instance AMI"
type = string
default = "ami-0c94855ba95c71c99"
}

variable "instance_type" {
description = "EC2 instance type"
type = string
default = "t2.micro"
}
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ resource "aws_iam_role_policy_attachment" "managed_policy_attachments" {

# Create IAM instance profile
resource "aws_iam_instance_profile" "instance_profile" {
name = "${var.role_name}-instance-profile"
name = var.instance_profile_name
role = aws_iam_role.iam_role.name

}
10 changes: 5 additions & 5 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ output "iam_role_managed_policy_arns" {
value = aws_iam_role_policy_attachment.managed_policy_attachments[*].policy_arn
}

output "iam_instance_profile_arn" {
description = "The ARN of the instance profile"
value = aws_iam_instance_profile.instance_profile.arn
}

output "iam_instance_profile_name" {
description = "The name of the instance profile"
value = aws_iam_instance_profile.instance_profile.name
}

output "iam_instance_profile_arn" {
description = "The ARN of the instance profile"
value = aws_iam_instance_profile.instance_profile.arn
}
7 changes: 6 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
variable "aws_region" {
description = "Selected AWS region"
description = "Specified AWS region"
type = string
default = null

Expand Down Expand Up @@ -32,3 +32,8 @@ variable "managed_policy_arns" {
type = list(string)
default = []
}

variable "instance_profile_name" {
description = "Name of the IAM Instance Profile"
type = string
}

0 comments on commit 3490e84

Please sign in to comment.