SIOS-Technology-Inc / dacrane

"Dacrane" is a Delivery as Code (DaC) tool for deploying cloud infrastructures and applications anywhere.
Apache License 2.0
61 stars 1 forks source link

Terraform Support #10

Closed t-ikeda-sti closed 1 year ago

t-ikeda-sti commented 1 year ago

User Story

Developers want to use the familiar IaC tools to perform deployments; resources can be defined in the same way as terraform arguments using dacrane.yaml. IaC tools should be interchangeable, but Terraform is supported first.

Acceptance Criteria

Convert the code in Dacrane.yaml to HCL and implement a plugin to execute Terraform apply. After applying, the state is retrieved from state.json. When deleting, Terraform destroy is executed.

An example of a terraform resource conversion is shown below.

modules:
- name: foo 
  module: resource/terraform
  arguments:
  - provider: bar
    resource: baz
    name: quz
    configurations:
       user: Alice
       password: abc123
    arguments:
       a: 1
       b: 2
provider "bar" {
  user = "Alice"
  password = "abc123"
}

resource "baz" "quz" {
  a = 1
  b = 2
}

An example of a terraform data conversion is shown below.

modules:
- name: foo 
  module: data/terraform
  arguments:
  - provider: bar
    resource: baz
    name: quz
    configurations:
       user: Alice
       password: abc123
    arguments:
       a: 1
       b: 2
provider "bar" {
  user = "Alice"
  password = "abc123"
}

data "baz" "quz" {
  a = 1
  b = 2
}

The following directories are at the provider's disposal, and the terraform provider will generate tf files in the following directories.

.dacrane/instances/[instance_name]/custom_states/[local_module_name]/

Reference

https://pkg.go.dev/github.com/hashicorp/hcl/v2/gohcl

t-ikeda-sti commented 1 year ago

@ka-sasaki-sti Please implement a function to convert YAML to HCL. We will implement this as a provider after #18 , so you only need to write a simple conversion code first.

t-ikeda-sti commented 1 year ago

Implemented. #25