summaryrefslogtreecommitdiff
path: root/module
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2021-02-01 16:45:47 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2021-02-01 16:45:47 +0100
commit2957c76e4027f47959f79354b07cdaa4b04da8c6 (patch)
tree0c7ddcada1549a2db7d3e4d09e2be9bd5442ae9d /module
parent2726bd8739b78738745a462a4950b39cbfe4c1d7 (diff)
downloadrules-sandbox-2957c76e4027f47959f79354b07cdaa4b04da8c6.tar.gz
rules-sandbox-2957c76e4027f47959f79354b07cdaa4b04da8c6.tar.bz2
rules-sandbox-2957c76e4027f47959f79354b07cdaa4b04da8c6.tar.xz
rules-sandbox-2957c76e4027f47959f79354b07cdaa4b04da8c6.zip
Updating files.
Diffstat (limited to 'module')
-rw-r--r--module/acme/src/main/resources/io/trygvis/acme/acme.drl49
-rw-r--r--module/ri-base/src/main/java/io/trygvis/rules/terraform/TerraformResource.java17
2 files changed, 60 insertions, 6 deletions
diff --git a/module/acme/src/main/resources/io/trygvis/acme/acme.drl b/module/acme/src/main/resources/io/trygvis/acme/acme.drl
index 76bad0a..6a2f33b 100644
--- a/module/acme/src/main/resources/io/trygvis/acme/acme.drl
+++ b/module/acme/src/main/resources/io/trygvis/acme/acme.drl
@@ -2,7 +2,10 @@ package io.trygvis.acme;
import io.trygvis.rules.machine.Machine;
import io.trygvis.rules.dba.Cluster;
-import io.trygvis.rules.dba.Container;
+import io.trygvis.rules.dba.Container
+import io.trygvis.rules.terraform.TerraformResource;
+import io.trygvis.rules.terraform.TerraformMain
+import io.trygvis.rules.terraform.TerraformProvider;
dialect "mvel"
@@ -32,3 +35,47 @@ then
fqdn = fqdn
}
end
+
+rule "Make Terraform module for machines"
+when
+ not TerraformMain(module == "terraform")
+then
+ var module = new TerraformMain("terraform");
+
+ var scaleway = new TerraformProvider("scaleway", "2.0.0-rc1");
+ module.getProviders().put("scaleway", scaleway);
+
+ insert(module)
+end
+
+rule "Make Scaleway Terraform resources for Machine"
+when
+ $m : Machine()
+ $s : AcmeServer(machine == $m)
+then
+ var ip = new TerraformResource("terraform/" + $m.name + "-ip.tf", "scaleway_instance_ip", $m.name);
+ var instance = new TerraformResource("terraform/" + $m.name + "-instance.tf", "scaleway_server_instance", $m.name)
+ .set("name", "acme-1")
+ .set("type", "DEV1-S")
+ .set("image", "b3042271-d2b1-4f87-b407-aedd3bbd1663")
+ .setExpression("ip_id", ip.name + ".ip")
+ .set("enable_dynamic_ip", false)
+ .set("enable_ipv6", true);
+
+
+ var rev = new TerraformResource("terraform/" + $m.name + "-ip.tf", "scaleway_instance_reverse_dns", $m.name)
+ .set("reverse", $m.fqdn + ".")
+ .setExpression("ip_id", ip.name + ".id");
+ var dns = new TerraformResource("terraform/" + $m.name + "-dns.tf", "google_dns_record_set", $m.name)
+ .set("name", $m.fqdn)
+ .setExpression("managed_zone", "var.dns_zone")
+ .set("type", "A")
+ .set("ttl", 300)
+ .array("rrdatas")
+ .addExpression(ip.name + ".id");
+
+ insert(instance)
+ insert(ip)
+ insert(rev)
+ insert(dns)
+end
diff --git a/module/ri-base/src/main/java/io/trygvis/rules/terraform/TerraformResource.java b/module/ri-base/src/main/java/io/trygvis/rules/terraform/TerraformResource.java
index 2615dde..351a3e1 100644
--- a/module/ri-base/src/main/java/io/trygvis/rules/terraform/TerraformResource.java
+++ b/module/ri-base/src/main/java/io/trygvis/rules/terraform/TerraformResource.java
@@ -22,6 +22,10 @@ public class TerraformResource {
return output;
}
+ public String getName() {
+ return kind + "." + instance;
+ }
+
public String getKind() {
return kind;
}
@@ -34,20 +38,24 @@ public class TerraformResource {
return values;
}
- public void set(String key, String value) {
+ public TerraformResource set(String key, String value) {
values.put(key, new StringTerraformValue(value));
+ return this;
}
- public void set(String key, boolean value) {
+ public TerraformResource set(String key, boolean value) {
values.put(key, new BooleanTerraformValue(value));
+ return this;
}
- public void set(String key, int value) {
+ public TerraformResource set(String key, int value) {
values.put(key, new IntegerTerraformValue(value));
+ return this;
}
- public void setExpression(String key, String value) {
+ public TerraformResource setExpression(String key, String value) {
values.put(key, new ExpressionTerraformValue(value));
+ return this;
}
public ArrayTerraformValue array(String key) {
@@ -75,7 +83,6 @@ public class TerraformResource {
}
buf.append("}");
- buf.append(EOL);
return buf.toString();
}