Skip to content

Commit

Permalink
Merge pull request #3 from zoitech/feature/user-data
Browse files Browse the repository at this point in the history
Feature/user data
  • Loading branch information
Geartrixy authored Dec 17, 2020
2 parents 95e98b6 + 1db09f2 commit 4b0d73e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 1.1.0

ENHANCEMENTS:

* Added optional user_data configuration [#1](https://github.com/zoitech/terraform-aws-ec2/issues/1)
* Added optional iam_instance_profile configuration [#2](https://github.com/zoitech/terraform-aws-ec2/issues/2)

## 1.0.0

INITIAL RELEASE:
Expand Down
2 changes: 2 additions & 0 deletions ec2.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ resource "aws_instance" "instance" {
key_name = var.key_name
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: 5 additions & 0 deletions iam_instance_profile.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "aws_iam_instance_profile" "profile" {
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.profile[0].name
}
18 changes: 18 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ variable "vpc_security_group_ids" {
default = []
}

variable "user_data" {
type = string
description = "(Optional) The user data to provide when launching the instance. Do not pass gzip-compressed data via this argument; see user_data_base64 instead."
default = ""
}

variable "iam_instance_profile_name" {
type = string
description = "(Optional, Forces new resource) The profile's name. If omitted, Terraform will assign a random, unique name."
default = ""
}

variable "iam_role_name" {
type = string
description = "(Optional) The role name to include in the profile"
default = ""
}

# https://github.com/hashicorp/terraform/issues/24188
# lifecycle: Support for dynamic blocks and meta-arguments still open
// variable "lifecycle_ignore_changes" {
Expand Down

0 comments on commit 4b0d73e

Please sign in to comment.