Skip to content

Commit a0962f8

Browse files
Custom terraform module for opta (#327)
Use it like this: ```yaml name: live-example-dev org_name: runx providers: aws: region: us-east-1 account_id: 445935066876 modules: - type: base - type: custom-terraform path_to_module: "../blah_module" terraform_inputs: a: "${{module.base.vpc_id}}" ```
1 parent a120bbc commit a0962f8

4 files changed

Lines changed: 32 additions & 1 deletion

File tree

config/registry.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ modules:
285285
host: "${{{module_source}.k8s_endpoint}}"
286286
token: "${{data.aws_eks_cluster_auth.k8s.token}}"
287287
cluster_ca_certificate: "${{base64decode({module_source}.k8s_ca_data)}}"
288+
custom-terraform:
289+
cloud: any
290+
location: custom-terraform
291+
halt: true
292+
variables:
293+
path_to_module: str
288294
datadog:
289295
cloud: any
290296
location: datadog

opta/layer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from opta.module_processors.azure_k8s_base import AzureK8sBaseProcessor
4141
from opta.module_processors.azure_k8s_service import AzureK8sServiceProcessor
4242
from opta.module_processors.base import ModuleProcessor
43+
from opta.module_processors.custom_terraform import CustomTerraformProcessor
4344
from opta.module_processors.datadog import DatadogProcessor
4445
from opta.module_processors.external_ssl_cert import ExternalSSLCert
4546
from opta.module_processors.gcp_dns import GCPDnsProcessor
@@ -81,6 +82,7 @@ class Layer:
8182
"external-ssl-cert": ExternalSSLCert,
8283
"aws-s3": AwsS3Processor,
8384
"gcp-dns": GCPDnsProcessor,
85+
"custom-terraform": CustomTerraformProcessor,
8486
}
8587

8688
def __init__(

opta/module.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __init__(
2626
raise UserErrors(f"{self.type} is not a valid module type")
2727
self.aliased_type: Optional[str] = None
2828
self.layer_name = layer.name
29-
self.desc = REGISTRY["modules"][self.type]
29+
self.desc = REGISTRY["modules"][self.type].copy()
3030
if "alias" in self.desc:
3131
cloud = layer.cloud
3232
if cloud not in self.desc["alias"]:
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import os
2+
from typing import TYPE_CHECKING
3+
4+
from opta.module_processors.base import ModuleProcessor
5+
6+
if TYPE_CHECKING:
7+
from opta.layer import Layer
8+
from opta.module import Module
9+
10+
11+
class CustomTerraformProcessor(ModuleProcessor):
12+
def __init__(self, module: "Module", layer: "Layer"):
13+
super(CustomTerraformProcessor, self).__init__(module, layer)
14+
15+
def process(self, module_idx: int) -> None:
16+
current_desc = self.module.desc
17+
self.module.module_dir_path = os.path.join(
18+
os.path.dirname(self.layer.path), self.module.data["path_to_module"]
19+
)
20+
current_desc["variables"] = {
21+
x: "optional" for x in self.module.data.get("terraform_inputs", {}).keys()
22+
}
23+
self.module.data.update(self.module.data.get("terraform_inputs", {}))

0 commit comments

Comments
 (0)