Skip to content

Commit 9007807

Browse files
authored
Create main.tf
1 parent 4d71f48 commit 9007807

File tree

1 file changed

+159
-0
lines changed

1 file changed

+159
-0
lines changed

main.tf

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
variable "cockroach_api_key" {
2+
type = string
3+
nullable = false
4+
sensitive = true
5+
}
6+
7+
variable "cockroach_provider" {
8+
type = string
9+
nullable = false
10+
default = "gcp"
11+
}
12+
13+
variable "cockroach_region" {
14+
type = string
15+
nullable = false
16+
default = "southamerica-east1"
17+
}
18+
19+
variable "do_token" {
20+
type = string
21+
nullable = false
22+
sensitive = true
23+
}
24+
25+
variable "sql_database_name" {
26+
type = string
27+
nullable = false
28+
default = "example"
29+
}
30+
31+
variable "sql_user_name" {
32+
type = string
33+
nullable = false
34+
default = "maxroach"
35+
}
36+
37+
variable "sql_user_password" {
38+
type = string
39+
nullable = false
40+
sensitive = true
41+
}
42+
43+
terraform {
44+
required_providers {
45+
cockroach = {
46+
source = "cockroachdb/cockroach"
47+
}
48+
49+
digitalocean = {
50+
source = "digitalocean/digitalocean"
51+
version = "~> 2.0"
52+
}
53+
}
54+
}
55+
56+
provider "cockroach" {
57+
apikey = var.cockroach_api_key
58+
}
59+
60+
provider "digitalocean" {
61+
token = var.do_token
62+
}
63+
64+
resource "cockroach_cluster" "sql_cluster" {
65+
name = "java-docker-tutorial"
66+
cloud_provider = upper(var.cockroach_provider)
67+
serverless = {
68+
spend_limit = 0
69+
}
70+
regions = [{
71+
name = var.cockroach_region
72+
}]
73+
}
74+
75+
resource "cockroach_sql_user" "sql_user" {
76+
name = var.sql_user_name
77+
password = var.sql_user_password
78+
cluster_id = cockroach_cluster.sql_cluster.id
79+
}
80+
81+
resource "cockroach_database" "sql_database" {
82+
name = var.sql_database_name
83+
cluster_id = cockroach_cluster.sql_cluster.id
84+
}
85+
86+
resource "digitalocean_app" "java-docker-tutorial" {
87+
spec {
88+
name = "java-docker-tutorial"
89+
region = "ams"
90+
91+
env {
92+
key = "DATABASE_URL"
93+
value = "jdbc:postgresql://${cockroach_cluster.sql_cluster.regions[0].sql_dns}:26257/${var.sql_database_name}"
94+
scope = "RUN_TIME"
95+
type = "SECRET"
96+
}
97+
98+
env {
99+
key = "DATABASE_USERNAME"
100+
value = var.sql_user_name
101+
scope = "RUN_TIME"
102+
type = "SECRET"
103+
}
104+
105+
env {
106+
key = "DATABASE_PASSWORD"
107+
value = var.sql_user_password
108+
scope = "RUN_TIME"
109+
type = "SECRET"
110+
}
111+
112+
service {
113+
name = "web"
114+
instance_count = 1
115+
instance_size_slug = "basic-xxs"
116+
http_port = 8080
117+
118+
image {
119+
registry_type = "DOCR"
120+
registry = "raniagus"
121+
repository = "java_docker_tutorial"
122+
tag = "web"
123+
124+
deploy_on_push {
125+
enabled = true
126+
}
127+
}
128+
129+
env {
130+
key = "DATABASE_HBM2DDL_AUTO"
131+
value = "none"
132+
scope = "RUN_TIME"
133+
}
134+
}
135+
136+
worker {
137+
name = "cron"
138+
instance_count = 1
139+
instance_size_slug = "basic-xxs"
140+
141+
image {
142+
registry_type = "DOCR"
143+
registry = "raniagus"
144+
repository = "java_docker_tutorial"
145+
tag = "cron"
146+
147+
deploy_on_push {
148+
enabled = true
149+
}
150+
}
151+
152+
env {
153+
key = "DATABASE_HBM2DDL_AUTO"
154+
value = "create-drop"
155+
scope = "RUN_TIME"
156+
}
157+
}
158+
}
159+
}

0 commit comments

Comments
 (0)