Skip to content

Commit c3bca7c

Browse files
authored
Initial V2 Release Candidate (#30)
* bugfix the V2 release with update to variables and main.tf logic. Updated readme to better explain the getting started process. * remove .atmos
1 parent f6a6d2f commit c3bca7c

File tree

6 files changed

+226
-189
lines changed

6 files changed

+226
-189
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ aws-assumed-role/
77
*.iml
88
.direnv
99
.envrc
10-
10+
.atmos/
1111
# Compiled and auto-generated files
1212
# Note that the leading "**/" appears necessary for Docker even if not for Git
1313

README.md

Lines changed: 80 additions & 68 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.yaml

Lines changed: 65 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ description: |-
4949
5050
Regardless of the networking style, you should have these defaults in common:
5151
52-
(`defaults.yaml`)
52+
(`runs-on/defaults.yaml`)
5353
5454
```yaml
5555
components:
@@ -64,19 +64,30 @@ description: |-
6464
capabilities: ["CAPABILITY_IAM"]
6565
on_failure: "ROLLBACK"
6666
timeout_in_minutes: 30
67-
template_url: https://runs-on.s3.eu-west-1.amazonaws.com/cloudformation/template.yaml
67+
# template_url: https://runs-on.s3.eu-west-1.amazonaws.com/cloudformation/template.yaml
68+
# See latest version and changelog at https://runs-on.com/changelog/
69+
template_url: https://runs-on.s3.eu-west-1.amazonaws.com/cloudformation/template-v2.8.3.yaml
6870
parameters:
69-
AppCPU: 512
70-
AppMemory: 1024
71-
EmailAddress: devops@acme.com
72-
Environment: core-auto
73-
GithubOrganization: ACME
74-
LicenseKey: <LICENSE>
75-
Private: always # always | true | false - Always will default place in private subnet, true will place in private subnet if tag `private=true` present on workflow, false will place in public subnet
71+
AppCPU: 256
72+
AppMemory: 512
73+
EmailAddress: developer@cloudposse.com
74+
# Environments let you run multiple Stacks in one organization and segregate resources.
75+
# If you specify an environment, then all the jobs must also specify the which environment they are running in.
76+
# To keep things simple, we use the default environment ("production") and leave the `env` label unset in the workflow.
77+
EncryptEbs: true
78+
# With the default value of SSHAllowed: true, the runners that are placed in a public subnet
79+
# will allow ingress on port 22. This is highly abused (scanners running constantly looking for vulernable SSH servers)
80+
# and should not be allowed. If you need access to the runners, use Session Manager (SSM).
81+
SSHAllowed: false
82+
LicenseKey: <LICENSE_KEY>
83+
Private: false # always | true | false - Always will default place in private subnet, true will place in private subnet if tag `private=true` present on workflow, false will place in public subnet
84+
RunnerLargeDiskSize: 120 # Disk size in GB for disk=large runners
85+
Ec2LogRetentionInDays: 30
86+
VpcFlowLogRetentionInDays: 14
7687
```
7788
7889
79-
### Embedded networking
90+
### Embedded networking (Runs On managed VPC)
8091
8192
When no VPC details are set, the component will create a new VPC and subnets for you. This is done via the CloudFormation template.
8293
@@ -102,7 +113,49 @@ description: |-
102113
parameters:
103114
VpcCidrBlock: 10.100.0.0/16
104115
```
105-
### (DEPRECATED) Configuring with Transit Gateway
116+
117+
### External networking (Use existing VPC)
118+
119+
When you want to use an existing VPC, you can set the `vpc_id`, `subnet_ids`, and `security_group_id` variables.
120+
121+
(`_defaults.yaml`)
122+
123+
```yaml
124+
terraform:
125+
hooks:
126+
store-outputs:
127+
name: auto/ssm
128+
```
129+
130+
(`runs-on.yaml`)
131+
132+
```yaml
133+
import:
134+
- orgs/acme/core/auto/_defaults
135+
- mixins/region/us-east-1
136+
- catalog/vpc/defaults
137+
- catalog/runs-on/defaults
138+
139+
components:
140+
terraform:
141+
runs-on:
142+
metadata:
143+
inherits:
144+
- runs-on/defaults
145+
component: runs-on
146+
vars:
147+
networking_stack: external
148+
# There are other ways to get the vpc_id, subnet_ids, and security_group_id. You can
149+
# Harcode
150+
# Use Atmos KV Store
151+
# Use atmos !terraform.output yaml function
152+
vpc_id: !store auto/ssm vpc vpc_id
153+
subnet_ids: !store auto/ssm vpc private_subnet_ids
154+
security_group_id: !store auto/ssm vpc default_security_group_id
155+
```
156+
157+
<details>
158+
<summary>(DEPRECATED) Configuring with Transit Gateway</summary>
106159
107160
It's important to note that the embedded networking will require some customization to work with Transit Gateway.
108161
@@ -229,48 +282,7 @@ description: |-
229282
- runs-on
230283
...
231284
```
232-
233-
### External networking
234-
235-
When you want to use an existing VPC, you can set the `vpc_id`, `subnet_ids`, and `security_group_id` variables.
236-
237-
(`_defaults.yaml`)
238-
239-
```yaml
240-
terraform:
241-
hooks:
242-
store-outputs:
243-
name: auto/ssm
244-
```
245-
246-
(`runs-on.yaml`)
247-
248-
```yaml
249-
import:
250-
- orgs/acme/core/auto/_defaults
251-
- mixins/region/us-east-1
252-
- catalog/vpc/defaults
253-
- catalog/runs-on/defaults
254-
255-
components:
256-
terraform:
257-
vpc:
258-
vars:
259-
name: vpc
260-
enabled: true
261-
cidr_block: 10.100.0.0/16
262-
263-
runs-on:
264-
metadata:
265-
inherits:
266-
- runs-on/defaults
267-
component: runs-on
268-
vars:
269-
networking_stack: external
270-
vpc_id: !store auto/ssm vpc vpc_id
271-
subnet_ids: !store auto/ssm vpc private_subnet_ids
272-
security_group_id: !store auto/ssm vpc default_security_group_id
273-
```
285+
</details>
274286
275287
# Terraform Docs
276288

src/README.md

Lines changed: 65 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.tf

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
locals {
22
enabled = module.this.enabled
33

4-
external_vpc_id = var.vpc_id != null ? { "ExternalVpcId" = var.vpc_id } : {}
5-
networking_stack = var.networking_stack != null ? { "NetworkingStack" = var.networking_stack } : {}
6-
subnet_ids = var.subnet_ids != null ? { "ExternalVpcSubnetIds" = var.subnet_ids } : {}
4+
external_vpc_id = var.vpc_id != null ? { "ExternalVpcId" = var.vpc_id } : {}
5+
networking_stack = var.networking_stack != null ? { "NetworkingStack" = var.networking_stack } : {}
6+
subnet_ids = var.subnet_ids != null ? { "ExternalVpcSubnetIds" = join(",", var.subnet_ids) } : {}
7+
// If var.security_group_id is provided, we use it. Otherwise, if we are using the external networking stack, we create one.
78
external_security_group_id = var.security_group_id != null ? { "ExternalVpcSecurityGroupId" = var.security_group_id } : {}
8-
created_security_group_id = var.security_group_id == null && var.networking_stack == "external" ? { "ExternalVpcSecurityGroupId" = module.security_group.id } : {}
9+
// If var.security_group_id is not provided and we are using the external networking stack, we create one.
10+
created_security_group_id = var.security_group_id == null && var.networking_stack == "external" ? { "ExternalVpcSecurityGroupId" = module.security_group.id } : {}
911

1012
parameters = merge({
1113
"EC2InstanceCustomPolicy" = module.iam_policy.policy_arn
@@ -68,13 +70,20 @@ module "iam_policy" {
6870
]
6971
}
7072

73+
// Typically when runs-on is installed, and we're using the embedded networking stack, we need a security group.
74+
// This is a batties included optional feature.
7175
module "security_group" {
7276
source = "cloudposse/security-group/aws"
7377
version = "2.2.0"
7478

75-
enabled = local.enabled && var.security_group_id == null && var.networking_stack == "external"
79+
// Enabled if we are using the external networking stack and no security group ID is provided
80+
enabled = local.enabled && var.networking_stack == "external" && var.security_group_id == null
7681

77-
vpc_id = local.vpc_id
82+
// This cannot be local.vpc_id because that would create a dependency cycle - as the local.vpc_id is determined as the resulting VPC id.
83+
// The vpc_id is the created vpc by runs-on, or the one provided by the user if using the external networking stack.
84+
// Thus the security group ID (which is passed in as `ExternalVpcSecurityGroupId` as a parameter to the stack) cannot depend on the stacks' vpc_id.
85+
// `var.vpc_id` is safe to use here, because the networking_stack is required to be external for this.
86+
vpc_id = var.vpc_id
7887

7988
context = module.this.context
8089
}

src/variables.tf

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,13 @@ variable "vpc_id" {
5454
description = "VPC ID"
5555
nullable = true
5656
default = null
57-
validation {
58-
condition = var.networking_stack != "external" || var.vpc_id != null
59-
error_message = "VPC ID is required when networking stack is `external`."
60-
}
6157
}
6258

6359
variable "subnet_ids" {
6460
type = list(string)
6561
description = "Subnet IDs"
6662
nullable = true
6763
default = null
68-
validation {
69-
condition = var.networking_stack != "external" || var.subnet_ids != null && length(var.subnet_ids) > 0
70-
error_message = "Subnet IDs are required when networking stack is `external`."
71-
}
7264
}
7365

7466
variable "security_group_id" {

0 commit comments

Comments
 (0)