Skip to content

Commit

Permalink
allow setting the instance state
Browse files Browse the repository at this point in the history
  • Loading branch information
cuotos committed Oct 11, 2024
1 parent 9a794b0 commit 3151985
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ The .terraform-docs.yml file contains the configuration to make sure if gets cre

| Name | Version |
|------|---------|
| <a name="provider_awS"></a> [awS](#provider\_awS) | n/a |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.0 |
| <a name="provider_random"></a> [random](#provider\_random) | n/a |
| <a name="provider_template"></a> [template](#provider\_template) | n/a |
Expand All @@ -43,6 +44,7 @@ No modules.

| Name | Type |
|------|------|
| [awS_ec2_instance_state.instance](https://registry.terraform.io/providers/hashicorp/awS/latest/docs/resources/ec2_instance_state) | resource |
| [aws_iam_instance_profile.profile](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_instance_profile) | resource |
| [aws_iam_role.role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
| [aws_instance.instance](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance) | resource |
Expand All @@ -69,6 +71,7 @@ No modules.
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | AWS instance type to create | `string` | `"t3.nano"` | no |
| <a name="input_key_name"></a> [key\_name](#input\_key\_name) | SSH key pair to use | `string` | `""` | no |
| <a name="input_override_name"></a> [override\_name](#input\_override\_name) | Override the name of the instance that is created. | `string` | `null` | no |
| <a name="input_state"></a> [state](#input\_state) | State of the instance. Valiue values are `running`, `stopped` | `string` | `"running"` | no |
| <a name="input_subnet_id"></a> [subnet\_id](#input\_subnet\_id) | Subnet to create the instance in | `string` | n/a | yes |
| <a name="input_volume_size"></a> [volume\_size](#input\_volume\_size) | Root volume size of instance | `number` | `10` | no |
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | VPC to create the test instance in | `string` | n/a | yes |
Expand Down
5 changes: 5 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ resource "aws_instance" "instance" {
}
}

resource "aws_ec2_instance_state" "instance" {
instance_id = aws_instance.id
state = var.state
}

# Create a security group that allows access to internet to pull down yum dependencies
resource "aws_security_group" "security_group" {
name = "${local.username}-tmp-instance-${random_string.module_suffix.result}"
Expand Down
11 changes: 11 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,14 @@ variable "override_name" {
description = "Override the name of the instance that is created."
default = null
}

variable "state" {
type = string
description = "State of the instance. Valiue values are `running`, `stopped`"
default = "running"

validation {
condition = contains(["running", "stopped"], var.state)
error_message = "Valid values for var: state are (running, stopped)."
}
}

0 comments on commit 3151985

Please sign in to comment.