astro icon indicating copy to clipboard operation
astro copied to clipboard

Feature Request: Support `from-module` parameter

Open osterman opened this issue 7 years ago • 2 comments

First of all, I love the direction of this utility. It's a generalized approach to orchestrated complex, multi-phased applies for terraform. It's a nice alternative to terragrunt that's less opinionated. We use a similar tool designed for helm that's called helmfile.

what

  • Support an init.from-module directive for each module.

why

  • Terraform init supports -from-module=SOURCE when initializing a module
  • Enables ultra DRY innovation of modules (what terragrunt uses) and would make it easier to drop terragrunt and use astro instead
  • Rapidly define a complex architecture by referring to root module invocations

example

This example would copy the /aws/app module to core/app and then invoke the commands accordingly

modules:
  - name: app
    init:
      from-module: https://github.com/cloudposse/terraform-root-modules//aws/app
    path: core/app
    deps:
      - module: users
      - module: vpc
    remote:
      backend_config:
        bucket: acme-terraform-states
        key: "{{.aws_region}}/app-{{.environment}}.tfstate"
        region: us-east-1
    variables:
      - name: region
      - name: environment
        values: [dev, prod]

osterman avatar Nov 22 '18 03:11 osterman

I am all for this.

I'm even thinking of a generalised approach, i.e.: within each terraform block, have a way to specify arbitrary arguments to each Terraform command:

E.g.:

modules:
  - name: app
    terraform:
      flags:
        init:
          - from-module=https://github.com/cloudposse/terraform-root-modules//aws/app
    path: core/app
    deps:
      - module: users
      - module: vpc
    remote:
      backend_config:
        bucket: acme-terraform-states
        key: "{{.aws_region}}/app-{{.environment}}.tfstate"
        region: us-east-1
    variables:
      - name: region
      - name: environment
        values: [dev, prod]

Then you get access to all the underlying Terraform flags. For example, one could increase parallelism for all apply commands by doing:

terraform:
  flags:
    apply:
      - parallelism=20

modules:
  - name: app
    terraform:
      flags:
        init:
          - from-module=https://github.com/cloudposse/terraform-root-modules//aws/app
    path: core/app
    deps:
      - module: users
      - module: vpc
    remote:
      backend_config:
        bucket: acme-terraform-states
        key: "{{.aws_region}}/app-{{.environment}}.tfstate"
        region: us-east-1
    variables:
      - name: region
      - name: environment
        values: [dev, prod]

Only consideration there is that users could potentially cause an issue by changing something astro doesn't expect under the hood. I can't see any catastrophic cases of that right now but it could become a problem.

dansimau avatar Dec 06 '18 08:12 dansimau

This is an important feature for greater levels of composition and versioning of infrastructure. Would love to see this implemented or help in the implementation.

If you could init from a module, would it negate the need for the "path" attribute?

Initially when I looked at the project, I was under the impression that the "path" attribute would act like the -from-import functionality of terraform.

gerardaus avatar May 02 '19 20:05 gerardaus