Skip to content

Commit 6851df4

Browse files
ci: Add terraform (wip)
1 parent c683be8 commit 6851df4

File tree

8 files changed

+224
-0
lines changed

8 files changed

+224
-0
lines changed

.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# ETC
22
!.gitkeep
33
*.sqlite
4+
tfplan
45

56
# Byte-compiled / optimized / DLL files
67
__pycache__/
@@ -237,3 +238,38 @@ dist
237238
.yarn/build-state.yml
238239
.yarn/install-state.gz
239240
.pnp.*
241+
242+
# Local .terraform directories
243+
**/.terraform/*
244+
245+
# .tfstate files
246+
*.tfstate
247+
*.tfstate.*
248+
249+
# Crash log files
250+
crash.log
251+
crash.*.log
252+
253+
# Exclude all .tfvars files, which are likely to contain sensitive data, such as
254+
# password, private keys, and other secrets. These should not be part of version
255+
# control as they are data points which are potentially sensitive and subject
256+
# to change depending on the environment.
257+
*.tfvars
258+
*.tfvars.json
259+
260+
# Ignore override files as they are usually used to override resources locally and so
261+
# are not checked in
262+
override.tf
263+
override.tf.json
264+
*_override.tf
265+
*_override.tf.json
266+
267+
# Include override files you do wish to add to version control using negated pattern
268+
# !example_override.tf
269+
270+
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
271+
# example: *tfplan*
272+
273+
# Ignore CLI configuration files
274+
.terraformrc
275+
terraform.rc

.tflint.hcl

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# https://github.com/terraform-linters/tflint/blob/master/docs/user-guide/module-inspection.md
2+
# borrowed & modified indefinitely from https://github.com/ksatirli/building-infrastructure-you-can-mostly-trust/blob/main/.tflint.hcl
3+
4+
plugin "aws" {
5+
enabled = true
6+
version = "0.14.0"
7+
source = "github.com/terraform-linters/tflint-ruleset-aws"
8+
}
9+
10+
config {
11+
module = true
12+
force = false
13+
}
14+
15+
rule "terraform_required_providers" {
16+
enabled = true
17+
}
18+
19+
rule "terraform_required_version" {
20+
enabled = true
21+
}
22+
23+
rule "terraform_naming_convention" {
24+
enabled = true
25+
format = "snake_case"
26+
}
27+
28+
rule "terraform_typed_variables" {
29+
enabled = true
30+
}
31+
32+
rule "terraform_unused_declarations" {
33+
enabled = true
34+
}
35+
36+
rule "terraform_comment_syntax" {
37+
enabled = true
38+
}
39+
40+
rule "terraform_deprecated_index" {
41+
enabled = true
42+
}
43+
44+
rule "terraform_deprecated_interpolation" {
45+
enabled = true
46+
}
47+
48+
rule "terraform_documented_outputs" {
49+
enabled = true
50+
}
51+
52+
rule "terraform_documented_variables" {
53+
enabled = true
54+
}
55+
56+
rule "terraform_module_pinned_source" {
57+
enabled = true
58+
}
59+
60+
rule "terraform_standard_module_structure" {
61+
enabled = true
62+
}
63+
64+
rule "terraform_workspace_remote" {
65+
enabled = true
66+
}

.tool-versions

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
golang 1.20.6
12
python 3.11.6
23
poetry 1.7.1
4+
terraform 1.7.3

terraform/.terraform.lock.hcl

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

terraform/main.tf

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# TODO: fix unauthorized errors (test w/raw api)
2+
# λ tfa tfplan
3+
# render_service.db: Creating...
4+
# render_service.web: Creating...
5+
#
6+
# │ Error: failed to create service
7+
#
8+
# │ with render_service.web,
9+
# │ on main.tf line 1, in resource "render_service" "web":
10+
# │ 1: resource "render_service" "web" {
11+
#
12+
# │ Unauthorized
13+
#
14+
# │ Error: failed to create service
15+
#
16+
# │ with render_service.db,
17+
# │ on main.tf line 28, in resource "render_service" "db":
18+
# │ 28: resource "render_service" "db" {
19+
#
20+
# │ Unauthorized
21+
22+
resource "render_service" "web" {
23+
name = "qaas-web"
24+
type = "web_service"
25+
repo = "https://github.com/pythoninthegrass/qaas.git"
26+
branch = "main"
27+
auto_deploy = true
28+
owner = local.owner
29+
30+
web_service_details = {
31+
env = "docker"
32+
plan = "starter"
33+
region = "ohio"
34+
pull_request_previews_enabled = true
35+
health_check_path = "/healthz"
36+
}
37+
}
38+
39+
resource "render_service_environment" "web" {
40+
service = render_service.web.id
41+
variables = [{
42+
key = "PORT"
43+
value = "8000"
44+
key = "POSTGRES_URI"
45+
value = render_service.db.private_service_details.url
46+
}]
47+
}
48+
49+
resource "render_service" "db" {
50+
name = "qaas-postgres"
51+
type = "private_service"
52+
repo = "hhttps://github.com/pythoninthegrass/render-postgres"
53+
branch = "main"
54+
owner = local.owner
55+
56+
private_service_details = {
57+
env = "docker"
58+
plan = "free"
59+
disk = {
60+
name = "quotes"
61+
mount_path = "/data/db"
62+
size_gb = 5
63+
}
64+
}
65+
}
66+

terraform/outputs.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
output "web_url" {
2+
value = render_service.web.web_service_details.url
3+
}
4+
5+
output "db_url" {
6+
value = render_service.db.private_service_details.url
7+
}

terraform/provider.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
terraform {
2+
required_providers {
3+
render = {
4+
source = "jackall3n/render"
5+
version = "1.3.0"
6+
}
7+
}
8+
}
9+
10+
provider "render" {
11+
# email = local.email
12+
api_key = base64encode(local.api_token)
13+
}

terraform/variables.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SOURCE: https://stackoverflow.com/a/76194380/15454191
2+
locals {
3+
dot_env_file_path = "../.render.env"
4+
dot_env_regex = "(?m:^\\s*([^#\\s]\\S*)\\s*=\\s*[\"']?(.*[^\"'\\s])[\"']?\\s*$)"
5+
dot_env = { for tuple in regexall(local.dot_env_regex, file(local.dot_env_file_path)) : tuple[0] => sensitive(tuple[1]) }
6+
api_token = local.dot_env["RENDER_API_KEY"]
7+
email = local.dot_env["RENDER_EMAIL"]
8+
owner = local.dot_env["OWNER"]
9+
}

0 commit comments

Comments
 (0)