Skip to content

universe: Add Terraform package - #2192

Merged
helderco merged 4 commits into
dagger:mainfrom
efoncubierta:terraform_package
May 3, 2022
Merged

helderco merged 4 commits into
dagger:mainfrom
efoncubierta:terraform_package

Conversation

@efoncubierta

@efoncubierta efoncubierta commented Apr 14, 2022 •

Copy link
Copy Markdown
Contributor

Signed-off-by: Ezequiel Foncubierta [email protected]

I know there is another contribution for a Terraform package (#2110), but this one we are currently using and implementing at work, and supports a lot more features. The approach is similar to Nico's implementation, so feel free to merge it into his package, or the other way around, if necessary.

Implementation details

There is a terraform.#Run action to wrap the Terraform command and run it within the official Terraform container image, from Hashicorp. You can set the Terraform command you want to run (i.e. plan, apply), the arguments (i.e. -var-file, -var), and environment variables. For common environment variables or arguments, there is a field in terraform.#Run you can use. For example, the workspace fields will become a TF_WORKSPACE environment variable.

For each particular Terraform command (i.e. plan, apply) there is an action (i.e. terraform.#Plan) that extends terraform.#Run. These actions override the command field and define additional fields when necessary. For example, a planFile field.

For things that are not "yet supported", you can always fall back to the terraform.#Run action.

The terraform.#Run actions have two outputs:

  • output: A dagger.#FS with the modified Terraform workspace.
  • outputImage: The docker.#Image that was used to run the command.

Not yet supported

Ezequiel Foncubierta added 3 commits April 14, 2022 07:34
Signed-off-by: Ezequiel Foncubierta <[email protected]>
Signed-off-by: Ezequiel Foncubierta <[email protected]>
@efoncubierta
efoncubierta marked this pull request as ready for review April 14, 2022 05:52
@efoncubierta efoncubierta changed the title Add Terraform package universe: Add Terraform package Apr 14, 2022

@helderco helderco left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

You should comment all your public fields so it gets picked up by the CLI:
https://docs.dagger.io/1226/coding-style

Also, please squash your commits and run linter locally:
https://docs.dagger.io/1227/contributing

@TomChv TomChv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank for your contribution, it's an amazing work!
I really like your implementation, it's a good one.

I left some comments to make it even more awesome 🚀
I will take pleasure to follow up your work on that PR :D

Comment on lines 69 to 85

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: You could use exports from docker.#Run instead of an intermediate steps to retrieve directory

@TomChv

TomChv commented Apr 14, 2022

Copy link
Copy Markdown
Member

The approach is similar to Nico's implementation, so feel free to merge it into his package, or the other way around, if necessary.

Since packages are experimental, it's okay to have duplication.
We will make a choice when we will port a terraform package in the "official" universe

@efoncubierta

Copy link
Copy Markdown
Contributor Author

I amended most of the requested changes, but using mount instead of docker.#Copy. The /src directory is empty when I use mount.

I am getting the following error when running dagger do lint. I don't know exactly what's going on here.

1:49PM FTL failed to execute plan: task failed: actions.lint.cue._dag."4"._exec: process "bash --norc -e -o pipefail /bash/scripts/run.sh" did not complete successfully: exit code: 1

Re squashing commit. I was able to do it only on commits after the rebase from main.

@TomChv TomChv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks really good!

I'll play with your package to understand why you can't simplify the exports.
However, it's already mergeable, we can improve package's internal later ;)

Comment on lines 64 to 80

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could directly use docker.#Run outside docker.#Build, I'll try your package and show you ;)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For completeness, this is what I tried and didn't work

#Run: {
  ...

  _image: #Image

  // Run command within a container
  _run: docker.#Run & {
    input: *_image.output | docker.#Image
    workdir: "/src"
    command: {
      name: cmd
      args: _thisCmdArgs
    }
    mounts: src: {
      dest: "/src"
      contents: source
    }
    env: _thisEnv
  }

  ...
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you are right, you are updating /src and outputting it for further operation so yes, you did great!

@aluzzardi

Copy link
Copy Markdown
Contributor

@TomChv @efoncubierta Really looking forward to merge this. What's missing? Anything we can help with?

@TomChv

TomChv commented Apr 27, 2022

Copy link
Copy Markdown
Member

Really looking forward to merge this. What's missing? Anything we can help with?

Fixing lint and another approval from me after a manual test of the package, I'll do it tomorrow

@aluzzardi

Copy link
Copy Markdown
Contributor

Thanks @TomChv!

@TomChv

TomChv commented Apr 28, 2022

Copy link
Copy Markdown
Member

I manually tested the package! It's really good 🚀

We can merge that package just after lint error are fixed.

@efoncubierta You can just run make cuefmt and then amend your last commit to apply lint.
We will merge your package just after that

@TomChv

TomChv commented Apr 29, 2022

Copy link
Copy Markdown
Member

@efoncubierta I fixed your linter error, just squash all your commits (do not forget to pull, I've fix your lint error) and we will merge that one!

Signed-off-by: Ezequiel Foncubierta <[email protected]>

chore(universe/terraform): fix linter

Signed-off-by: Vasek - Tom C <[email protected]>
@efoncubierta

Copy link
Copy Markdown
Contributor Author

@TomChv I squashed the commits. I can't squash the two commits before the merge from the main branch.

@TomChv

TomChv commented May 2, 2022

Copy link
Copy Markdown
Member

@aluzzardi Ready for merge!

@helderco
helderco merged commit 7039a1c into dagger:main May 3, 2022
@efoncubierta
efoncubierta deleted the terraform_package branch May 4, 2022 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants