diff --git a/README.md b/README.md
index 4233705..f93a571 100644
--- a/README.md
+++ b/README.md
@@ -1,11 +1,8 @@
-# terraform-aws-ec2-instance [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-aws-ec2-instance.svg)](https://github.com/cloudposse/terraform-aws-ec2-instance/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)
+# terraform-aws-ec2-instance [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-aws-ec2-instance.svg)](https://github.com/cloudposse/terraform-aws-ec2-instance/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)
-[![README Header][readme_header_img]][readme_header_link]
-
-[![Cloud Posse][logo]](https://cpco.io/homepage)
-
-## Share the Love
-
-Like this project? Please give it a ★ on [our GitHub](https://github.com/cloudposse/terraform-aws-ec2-instance)! (it helps us **a lot**)
-
-
-
## Related Projects
Check out these related projects.
@@ -375,54 +341,8 @@ For additional context, refer to some of these links.
- [terraform-aws-ec2-bastion-server](https://github.com/cloudposse/terraform-aws-ec2-bastion-server) - Terraform Module to define a generic Bastion host with parameterized user_data
-## Help
-
-**Got a question?** We got answers.
-
-File a GitHub [issue](https://github.com/cloudposse/terraform-aws-ec2-instance/issues), send us an [email][email] or join our [Slack Community][slack].
-
-[![README Commercial Support][readme_commercial_support_img]][readme_commercial_support_link]
-
-## DevOps Accelerator for Startups
-
-
-We are a [**DevOps Accelerator**][commercial_support]. We'll help you build your cloud infrastructure from the ground up so you can own it. Then we'll show you how to operate it and stick around for as long as you need us.
-
-[![Learn More](https://img.shields.io/badge/learn%20more-success.svg?style=for-the-badge)][commercial_support]
-
-Work directly with our team of DevOps experts via email, slack, and video conferencing.
-
-We deliver 10x the value for a fraction of the cost of a full-time engineer. Our track record is not even funny. If you want things done right and you need it done FAST, then we're your best bet.
-
-- **Reference Architecture.** You'll get everything you need from the ground up built using 100% infrastructure as code.
-- **Release Engineering.** You'll have end-to-end CI/CD with unlimited staging environments.
-- **Site Reliability Engineering.** You'll have total visibility into your apps and microservices.
-- **Security Baseline.** You'll have built-in governance with accountability and audit logs for all changes.
-- **GitOps.** You'll be able to operate your infrastructure via Pull Requests.
-- **Training.** You'll receive hands-on training so your team can operate what we build.
-- **Questions.** You'll have a direct line of communication between our teams via a Shared Slack channel.
-- **Troubleshooting.** You'll get help to triage when things aren't working.
-- **Code Reviews.** You'll receive constructive feedback on Pull Requests.
-- **Bug Fixes.** We'll rapidly work with you to fix any bugs in our projects.
-
-## Slack Community
-
-Join our [Open Source Community][slack] on Slack. It's **FREE** for everyone! Our "SweetOps" community is where you get to talk with others who share a similar vision for how to rollout and manage infrastructure. This is the best place to talk shop, ask questions, solicit feedback, and work together as a community to build totally *sweet* infrastructure.
-
-## Newsletter
-
-Sign up for [our newsletter][newsletter] that covers everything on our technology radar. Receive updates on what we're up to on GitHub as well as awesome new projects we discover.
-
-## Office Hours
-
-[Join us every Wednesday via Zoom][office_hours] for our weekly "Lunch & Learn" sessions. It's **FREE** for everyone!
-
-[![zoom](https://img.cloudposse.com/fit-in/200x200/https://cloudposse.com/wp-content/uploads/2019/08/Powered-by-Zoom.png")][office_hours]
-
## ✨ Contributing
-
-
This project is under active development, and we encourage contributions from our community.
Many thanks to our outstanding contributors:
@@ -430,15 +350,13 @@ Many thanks to our outstanding contributors:
-
-
-### Bug Reports & Feature Requests
+### 🐛 Bug Reports & Feature Requests
Please use the [issue tracker](https://github.com/cloudposse/terraform-aws-ec2-instance/issues) to report any bugs or file feature requests.
-### Developing
+### 💻 Developing
-If you are interested in being a contributor and want to get involved in developing this project or [help out](https://cpco.io/help-out) with our other projects, we would love to hear from you! Shoot us an [email][email].
+If you are interested in being a contributor and want to get involved in developing this project or [help out](https://cpco.io/help-out) with Cloud Posse's other projects, we would love to hear from you! Shoot us an [email][email].
In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.
@@ -450,13 +368,43 @@ In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.
**NOTE:** Be sure to merge the latest changes from "upstream" before making a pull request!
+### 🌎 Slack Community
-## Copyright
+Join our [Open Source Community][slack] on Slack. It's **FREE** for everyone! Our "SweetOps" community is where you get to talk with others who share a similar vision for how to rollout and manage infrastructure. This is the best place to talk shop, ask questions, solicit feedback, and work together as a community to build totally *sweet* infrastructure.
-Copyright © 2017-2023 [Cloud Posse, LLC](https://cpco.io/copyright)
+### 📰 Newsletter
+
+Sign up for [our newsletter][newsletter] that covers everything on our technology radar. Receive updates on what we're up to on GitHub as well as awesome new projects we discover.
+
+### 📆 Office Hours
+
+[Join us every Wednesday via Zoom][office_hours] for our weekly "Lunch & Learn" sessions. It's **FREE** for everyone!
+
+## About
+
+This project is maintained and funded by [Cloud Posse, LLC][website].
+
+
+We are a [**DevOps Accelerator**][commercial_support]. We'll help you build your cloud infrastructure from the ground up so you can own it. Then we'll show you how to operate it and stick around for as long as you need us.
+
+[![Learn More](https://img.shields.io/badge/learn%20more-success.svg?style=for-the-badge)][commercial_support]
+
+Work directly with our team of DevOps experts via email, slack, and video conferencing.
+We deliver 10x the value for a fraction of the cost of a full-time engineer. Our track record is not even funny. If you want things done right and you need it done FAST, then we're your best bet.
+- **Reference Architecture.** You'll get everything you need from the ground up built using 100% infrastructure as code.
+- **Release Engineering.** You'll have end-to-end CI/CD with unlimited staging environments.
+- **Site Reliability Engineering.** You'll have total visibility into your apps and microservices.
+- **Security Baseline.** You'll have built-in governance with accountability and audit logs for all changes.
+- **GitOps.** You'll be able to operate your infrastructure via Pull Requests.
+- **Training.** You'll receive hands-on training so your team can operate what we build.
+- **Questions.** You'll have a direct line of communication between our teams via a Shared Slack channel.
+- **Troubleshooting.** You'll get help to triage when things aren't working.
+- **Code Reviews.** You'll receive constructive feedback on Pull Requests.
+- **Bug Fixes.** We'll rapidly work with you to fix any bugs in our projects.
+[![README Commercial Support][readme_commercial_support_img]][readme_commercial_support_link]
## License
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
@@ -482,29 +430,12 @@ specific language governing permissions and limitations
under the License.
```
-
-
-
-
-
-
-
-
## Trademarks
All other trademarks referenced herein are the property of their respective owners.
-
-## About
-
-This project is maintained and funded by [Cloud Posse, LLC][website]. Like it? Please let us know by [leaving a testimonial][testimonial]!
-
-[![Cloud Posse][logo]][website]
-
-We're a [DevOps Professional Services][hire] company based in Los Angeles, CA. We ❤️ [Open Source Software][we_love_open_source].
-
-We offer [paid support][commercial_support] on all of our projects.
-
-Check out [our other projects][github], [follow us on twitter][twitter], [apply for a job][jobs], or [hire us][hire] to help with your cloud strategy and implementation.[![README Footer][readme_footer_img]][readme_footer_link]
+---
+Copyright © 2017-2024 [Cloud Posse, LLC](https://cpco.io/copyright)
+[![README Footer][readme_footer_img]][readme_footer_link]
[![Beacon][beacon]][website]
[logo]: https://cloudposse.com/logo-300x69.svg
@@ -515,7 +446,6 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
[hire]: https://cpco.io/hire?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-ec2-instance&utm_content=hire
[slack]: https://cpco.io/slack?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-ec2-instance&utm_content=slack
[twitter]: https://cpco.io/twitter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-ec2-instance&utm_content=twitter
- [testimonial]: https://cpco.io/leave-testimonial?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-ec2-instance&utm_content=testimonial
[office_hours]: https://cloudposse.com/office-hours?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-ec2-instance&utm_content=office_hours
[newsletter]: https://cpco.io/newsletter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-ec2-instance&utm_content=newsletter
[email]: https://cpco.io/email?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-ec2-instance&utm_content=email
diff --git a/docs/terraform.md b/docs/terraform.md
index 3c5fb31..3c0a628 100644
--- a/docs/terraform.md
+++ b/docs/terraform.md
@@ -88,6 +88,7 @@
| [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).
Set to `0` for unlimited length.
Set to `null` for keep the existing setting, which defaults to `0`.
Does not affect `id_full`. | `number` | `null` | no |
| [instance\_initiated\_shutdown\_behavior](#input\_instance\_initiated\_shutdown\_behavior) | Specifies whether an instance stops or terminates when you initiate shutdown from the instance. Can be one of 'stop' or 'terminate'. | `string` | `null` | no |
| [instance\_profile](#input\_instance\_profile) | A pre-defined profile to attach to the instance (default is to build our own) | `string` | `""` | no |
+| [instance\_profile\_enabled](#input\_instance\_profile\_enabled) | Whether an IAM instance profile is created to pass a role to an Amazon EC2 instance when the instance starts | `bool` | `true` | no |
| [instance\_type](#input\_instance\_type) | The type of the instance | `string` | `"t2.micro"` | no |
| [ipv6\_address\_count](#input\_ipv6\_address\_count) | Number of IPv6 addresses to associate with the primary network interface. Amazon EC2 chooses the IPv6 addresses from the range of your subnet (-1 to use subnet default) | `number` | `0` | no |
| [ipv6\_addresses](#input\_ipv6\_addresses) | List of IPv6 addresses from the range of the subnet to associate with the primary network interface | `list(string)` | `[]` | no |
diff --git a/main.tf b/main.tf
index 9124cba..c5745b5 100644
--- a/main.tf
+++ b/main.tf
@@ -3,8 +3,8 @@ locals {
instance_count = local.enabled ? 1 : 0
volume_count = var.ebs_volume_count > 0 && local.instance_count > 0 ? var.ebs_volume_count : 0
# create an instance profile if the instance is enabled and we aren't given one to use
- instance_profile_count = module.this.enabled && var.instance_profile == "" ? 1 : 0
- instance_profile = var.instance_profile != "" ? var.instance_profile : one(aws_iam_instance_profile.default[*].name)
+ instance_profile_count = module.this.enabled && var.instance_profile_enabled && var.instance_profile == "" ? 1 : 0
+ instance_profile = var.instance_profile_enabled && var.instance_profile != "" ? var.instance_profile : (var.instance_profile_enabled ? one(aws_iam_instance_profile.default[*].name) : "")
security_group_enabled = module.this.enabled && var.security_group_enabled
region = var.region != "" ? var.region : data.aws_region.default.name
root_iops = contains(["io1", "io2", "gp3"], var.root_volume_type) ? var.root_iops : null
@@ -82,18 +82,18 @@ data "aws_ami" "info" {
}
data "aws_iam_instance_profile" "given" {
- count = local.enabled && var.instance_profile != "" ? 1 : 0
+ count = local.enabled && var.instance_profile_enabled && var.instance_profile != "" ? 1 : 0
name = var.instance_profile
}
resource "aws_iam_instance_profile" "default" {
- count = local.instance_profile_count
+ count = var.instance_profile_enabled ? local.instance_profile_count : 0
name = module.this.id
role = one(aws_iam_role.default[*].name)
}
resource "aws_iam_role" "default" {
- count = local.instance_profile_count
+ count = var.instance_profile_enabled ? local.instance_profile_count : 0
name = module.this.id
path = "/"
assume_role_policy = data.aws_iam_policy_document.default.json
@@ -112,7 +112,7 @@ resource "aws_instance" "default" {
disable_api_termination = var.disable_api_termination
user_data = var.user_data
user_data_base64 = var.user_data_base64
- iam_instance_profile = local.instance_profile
+ iam_instance_profile = var.instance_profile_enabled ? local.instance_profile : ""
instance_initiated_shutdown_behavior = var.instance_initiated_shutdown_behavior
associate_public_ip_address = var.external_network_interface_enabled ? null : var.associate_public_ip_address
key_name = var.ssh_key_pair
diff --git a/outputs.tf b/outputs.tf
index 73d82a1..151a35a 100644
--- a/outputs.tf
+++ b/outputs.tf
@@ -50,12 +50,12 @@ output "security_group_ids" {
output "role" {
description = "Name of AWS IAM Role associated with the instance"
- value = local.instance_profile_count > 0 ? one(aws_iam_role.default[*].name) : one(data.aws_iam_instance_profile.given[*].role_name)
+ value = local.instance_profile_count > 0 ? one(aws_iam_role.default[*].name) : (var.instance_profile_enabled ? one(data.aws_iam_instance_profile.given[*].role_name) : one([""]))
}
output "role_arn" {
description = "ARN of AWS IAM Role associated with the instance"
- value = local.instance_profile_count > 0 ? one(aws_iam_role.default[*].arn) : one(data.aws_iam_instance_profile.given[*].role_arn)
+ value = local.instance_profile_count > 0 ? one(aws_iam_role.default[*].arn) : (var.instance_profile_enabled ? one(data.aws_iam_instance_profile.given[*].role_arn) : one([""]))
}
output "alarm" {
diff --git a/variables.tf b/variables.tf
index dfca0c8..bfc02a6 100644
--- a/variables.tf
+++ b/variables.tf
@@ -309,6 +309,12 @@ variable "instance_profile" {
default = ""
}
+variable "instance_profile_enabled" {
+ type = bool
+ default = true
+ description = "Whether an IAM instance profile is created to pass a role to an Amazon EC2 instance when the instance starts"
+}
+
variable "instance_initiated_shutdown_behavior" {
type = string
description = "Specifies whether an instance stops or terminates when you initiate shutdown from the instance. Can be one of 'stop' or 'terminate'."
@@ -406,4 +412,4 @@ variable "external_network_interfaces" {
}))
description = "The external interface definitions to attach to the instances. This depends on the instance type"
default = null
-}
\ No newline at end of file
+}