From 59ef07a9f583f0f0f64055a47938d57516b43541 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 31 Jan 2021 12:05:03 +0100 Subject: Better Terraform support. --- .../main/resources/io/trygvis/rules/scaleway/terraform.drl | 2 +- .../io/trygvis/rules/terraform/terraform-resources.drl | 14 ++++++++++++++ .../ri-base/src/main/resources/templates/terraform/main.j2 | 10 ++++++++++ .../src/main/resources/templates/terraform/variables.j2 | 10 ++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 module/ri-base/src/main/resources/templates/terraform/main.j2 create mode 100644 module/ri-base/src/main/resources/templates/terraform/variables.j2 (limited to 'module/ri-base/src/main/resources') diff --git a/module/ri-base/src/main/resources/io/trygvis/rules/scaleway/terraform.drl b/module/ri-base/src/main/resources/io/trygvis/rules/scaleway/terraform.drl index 06bfc68..7e0ff03 100644 --- a/module/ri-base/src/main/resources/io/trygvis/rules/scaleway/terraform.drl +++ b/module/ri-base/src/main/resources/io/trygvis/rules/scaleway/terraform.drl @@ -1,4 +1,4 @@ -package io.trygvis.rules.terraform.scaleway +package io.trygvis.rules.scaleway import io.trygvis.rules.dba.Cluster import io.trygvis.rules.dba.Container diff --git a/module/ri-base/src/main/resources/io/trygvis/rules/terraform/terraform-resources.drl b/module/ri-base/src/main/resources/io/trygvis/rules/terraform/terraform-resources.drl index 34af8fe..40a81f0 100644 --- a/module/ri-base/src/main/resources/io/trygvis/rules/terraform/terraform-resources.drl +++ b/module/ri-base/src/main/resources/io/trygvis/rules/terraform/terraform-resources.drl @@ -1,5 +1,9 @@ package io.trygvis.rules.terraform; + +import java.util.ArrayList +import java.util.HashSet import java.util.Map +import java.util.Set global io.trygvis.rules.engine.TemplateEngine te; @@ -12,3 +16,13 @@ when then te.template("terraform/resource", $r.output, Map.of("resource", $r)); end + +rule "main.tf" + agenda-group "generate" +when + $main : TerraformMain() + $variables : ArrayList() from collect(TerraformInputVariable(module == $main.module)) +then + te.template("terraform/main", $main.module + "/main.tf", Map.of("main", $main)); + te.template("terraform/variables", $main.module + "/vars.tf", Map.of("variables", $variables)); +end diff --git a/module/ri-base/src/main/resources/templates/terraform/main.j2 b/module/ri-base/src/main/resources/templates/terraform/main.j2 new file mode 100644 index 0000000..009f4ed --- /dev/null +++ b/module/ri-base/src/main/resources/templates/terraform/main.j2 @@ -0,0 +1,10 @@ +terraform { + required_providers { +{% for alias, provider in main.providers.entrySet() %} + {{ alias }} = { + version = "{{ provider.version }}" + source = "{{ provider.source }}" + } +{%- endfor %} + } +} diff --git a/module/ri-base/src/main/resources/templates/terraform/variables.j2 b/module/ri-base/src/main/resources/templates/terraform/variables.j2 new file mode 100644 index 0000000..6c37d99 --- /dev/null +++ b/module/ri-base/src/main/resources/templates/terraform/variables.j2 @@ -0,0 +1,10 @@ +{%- for var in variables %} +variable "{{ var.name }}" { +{%- if var.type %} + type = {{ var.type }} +{% endif %} +{%- if var.default %} + default = {{ var.default }} +{% endif %} +} +{% endfor %} -- cgit v1.2.3