Skip to content

Commit 8d62e1c

Browse files
committed
refactor(examples/complete): extract locals to variables
1 parent da7d754 commit 8d62e1c

File tree

5 files changed

+167
-69
lines changed

5 files changed

+167
-69
lines changed

examples/complete/.header.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,56 @@ Configuration in this directory creates:
55
- ECS Cluster using self-managed EC2
66
- Autoscaling Group with self-managed EC2 for the created ECS Cluster
77

8+
## Example tfvars file
9+
10+
```text
11+
cluster_name = "cluster"
12+
cluster_setting = [
13+
{
14+
name = "containerInsights"
15+
value = "enabled"
16+
}
17+
]
18+
cluster_tags = {
19+
Project = "project"
20+
}
21+
22+
# Autoscaling Group Variables
23+
asg_name = "my-asg"
24+
asg_vpc_zone_identifier = ["subnet-1341324123", "subnet-13241234123"]
25+
asg_desired_capacity = 2
26+
asg_min_size = 1
27+
asg_max_size = 3
28+
asg_instances_tags = {
29+
Name = "instance"
30+
}
31+
asg_tags = {
32+
Project = "project"
33+
}
34+
35+
# Launch Template Variables
36+
asg_create_launch_template = true
37+
asg_launch_template = {
38+
image_id = "ami-068e0f1a600cd311c"
39+
instance_type = "t2.micro"
40+
key_name = "<actual-key-name>"
41+
security_group_ids = []
42+
}
43+
asg_launch_template_version = "<actual-version>"
44+
45+
# IAM Role Variables
46+
asg_iam_role_name = "asg-role"
47+
asg_iam_role_tags = {
48+
Project = "project"
49+
}
50+
51+
# IAM Instance Profile Variables
52+
asg_iam_instance_profile_name = "asg-instance-profile"
53+
asg_iam_instance_profile_tags = {
54+
Project = "project"
55+
}
56+
```
57+
858
## Usage
959

1060
To run this example, you will need to execute the commands:

examples/complete/locals.tf

Lines changed: 0 additions & 49 deletions
This file was deleted.

examples/complete/main.tf

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
module "ecs" {
22
source = "../../"
33

4-
cluster_name = local.cluster_name
5-
cluster_setting = local.cluster_setting
6-
cluster_tags = local.cluster_tags
4+
cluster_name = var.cluster_name
5+
cluster_setting = var.cluster_setting
6+
cluster_tags = var.cluster_tags
77

88
# ASG Variables
9-
asg_name = local.asg_name
10-
asg_vpc_zone_identifier = local.asg_vpc_zone_identifier
11-
asg_desired_capacity = local.asg_desired_capacity
12-
asg_min_size = local.asg_min_size
13-
asg_max_size = local.asg_max_size
14-
asg_instances_tags = local.asg_instances_tags
15-
asg_tags = local.asg_tags
9+
asg_name = var.asg_name
10+
asg_vpc_zone_identifier = var.asg_vpc_zone_identifier
11+
asg_desired_capacity = var.asg_desired_capacity
12+
asg_min_size = var.asg_min_size
13+
asg_max_size = var.asg_max_size
14+
asg_instances_tags = var.asg_instances_tags
15+
asg_tags = var.asg_tags
1616

1717
# Launch Template
18-
asg_create_launch_template = local.asg_create_launch_template
19-
asg_launch_template = local.asg_launch_template
20-
asg_launch_template_version = local.asg_launch_template_version
18+
asg_create_launch_template = var.asg_create_launch_template
19+
asg_launch_template = var.asg_launch_template
20+
asg_launch_template_version = var.asg_launch_template_version
2121

2222
# IAM Role
23-
asg_iam_role_name = local.asg_iam_role_name
24-
asg_iam_role_tags = local.asg_iam_role_tags
23+
asg_iam_role_name = var.asg_iam_role_name
24+
asg_iam_role_tags = var.asg_iam_role_tags
2525

2626
# IAM Instance Profile
27-
asg_iam_instance_profile_name = local.asg_iam_instance_profile_name
28-
asg_iam_instance_profile_tags = local.asg_iam_instance_profile_tags
27+
asg_iam_instance_profile_name = var.asg_iam_instance_profile_name
28+
asg_iam_instance_profile_tags = var.asg_iam_instance_profile_tags
2929
}

examples/complete/provider.tf

Lines changed: 0 additions & 3 deletions
This file was deleted.

examples/complete/variables.tf

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
################################################################################
2+
# ECS Cluster
3+
################################################################################
4+
5+
variable "cluster_name" {
6+
description = "The name of the ECS cluster."
7+
type = string
8+
}
9+
10+
variable "cluster_setting" {
11+
description = "The settings to use when creating the cluster."
12+
type = list(object({
13+
name = string
14+
value = string
15+
}))
16+
}
17+
18+
variable "cluster_tags" {
19+
description = "A map of tags to assign to the cluster."
20+
type = map(string)
21+
}
22+
23+
################################################################################
24+
# Autoscaling Group
25+
################################################################################
26+
27+
variable "asg_name" {
28+
description = "The name of the Auto Scaling Group."
29+
type = string
30+
}
31+
32+
variable "asg_vpc_zone_identifier" {
33+
description = "A list of subnet IDs to launch resources in."
34+
type = list(string)
35+
}
36+
37+
variable "asg_desired_capacity" {
38+
description = "The number of Amazon EC2 instances that should be running in the Auto Scaling Group."
39+
type = number
40+
}
41+
42+
variable "asg_min_size" {
43+
description = "The minimum size of the Auto Scaling Group."
44+
type = number
45+
}
46+
47+
variable "asg_max_size" {
48+
description = "The maximum size of the Auto Scaling Group."
49+
type = number
50+
}
51+
52+
variable "asg_instances_tags" {
53+
description = "A map of tags to assign to the instances within the Auto Scaling Group."
54+
type = map(string)
55+
}
56+
57+
variable "asg_tags" {
58+
description = "A map of tags to assign to the Auto Scaling Group."
59+
type = map(string)
60+
}
61+
62+
variable "asg_create_launch_template" {
63+
description = "Whether to create a launch template."
64+
type = bool
65+
}
66+
67+
variable "asg_launch_template" {
68+
description = "The configuration of the launch template."
69+
type = object({
70+
image_id = string
71+
instance_type = string
72+
key_name = string
73+
security_group_ids = list(string)
74+
})
75+
}
76+
77+
variable "asg_launch_template_version" {
78+
description = "The version of the launch template to use."
79+
type = string
80+
}
81+
82+
variable "asg_iam_role_name" {
83+
description = "The name of the IAM role for the Auto Scaling Group."
84+
type = string
85+
}
86+
87+
variable "asg_iam_role_tags" {
88+
description = "A map of tags to assign to the IAM role."
89+
type = map(string)
90+
}
91+
92+
variable "asg_iam_instance_profile_name" {
93+
description = "The name of the IAM instance profile for the Auto Scaling Group."
94+
type = string
95+
}
96+
97+
variable "asg_iam_instance_profile_tags" {
98+
description = "A map of tags to assign to the IAM instance profile."
99+
type = map(string)
100+
}

0 commit comments

Comments
 (0)