Skip to content

Port/reimplement the Terraform package to Dagger 0.2 - #2110

Closed
nmeisenzahl wants to merge 1 commit into
dagger:mainfrom
nmeisenzahl:terraform-package
Closed

nmeisenzahl wants to merge 1 commit into
dagger:mainfrom
nmeisenzahl:terraform-package

Conversation

@nmeisenzahl

Copy link
Copy Markdown

Signed-off-by: Nico Meisenzahl [email protected]

Fixes #2109

@nmeisenzahl

Copy link
Copy Markdown
Author

Hi all. I'm pretty new to Dagger. I started porting/reimplementing the Terraform package. So far this is work in progress but I thought it might be helpful to get some feedback earlier than later ;)

@nmeisenzahl nmeisenzahl changed the title Ports/reimplement the Terraform package to Dagger 0.2 Port/reimplement the Terraform package to Dagger 0.2 Apr 11, 2022
@aluzzardi

Copy link
Copy Markdown
Contributor

Thank you for the contribution @nmeisenzahl, really appreciated!

Just a small note on my end: the testing infrastructure/conventions have changed in 0.2. So these new terraform tests are not currently running because of that. You can take a look at python or yarn for an example but in short:

  • You should add a test.bats file alongside your test.cue (take a look at pkg/universe.dagger.io/python/test/test.bats -- it's a tiny file you need to add)
  • The directory is called test rather than tests
  • Tests should be nested under a parent test action (e.g. actions: test: { [what you already have, no changes needed] }). So they can all run with dagger do test (again, see python/test/test.cue)

/cc @helderco for the actual package review

@nmeisenzahl

Copy link
Copy Markdown
Author

Hey,

@aluzzardi thanks for your feedback. I just implemented your findings.
@helderco I just want to know if the actions/structure itself is fine until I implement the missing parts.

@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.

Looks pretty good overall 🙂

@helderco

Copy link
Copy Markdown
Contributor

@nmeisenzahl can you please squash your commits? Take it out of draft when you're ready.

@nmeisenzahl
nmeisenzahl marked this pull request as ready for review April 12, 2022 19:55
@nmeisenzahl
nmeisenzahl requested a review from shykes as a code owner April 12, 2022 19:55

@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.

Can you please move the package into pkg/universe.dagger.io/x/<email>/terraform?

Context here: #1362 (comment)

@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.

Great, we're very close. I just ask you to squash your commits. 🙂

@nmeisenzahl

Copy link
Copy Markdown
Author

Great, we're very close. I just ask you to squash your commits. 🙂

Sry. Missed that one. Just squashed them.

@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.

Thanks for your contribution, I added some comments to make it perfect :D

Indeed, make sure CI succeed 🚀

// Terraform apply
#Apply: {
// Terraform version
version: string | *"latest"

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 should use a stable version as default to avoid unexpected behaviour

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.

Agree.

Comment on lines +26 to +30
// Copy source
docker.#Copy & {
dest: "/src"
contents: source
},

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 just mounts to copy src in docker.#Run instead of a whole step

Comment on lines +22 to +24
docker.#Pull & {
source: "hashicorp/terraform:\(version)"
},

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.

Since you are using this step on each definition, why you do not create a definition #Image and reuse it everywhere?
You could also take as parameter a base image so the user can give his own if he want.

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.

I don't think it matters much in this case because the command is fixed. Not much you can do with a different image.

Comment on lines +26 to +28
docker.#Pull & {
source: "hashicorp/terraform:\(version)"
},

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.

Duplication, see my comments above

Comment on lines +26 to +28
docker.#Pull & {
source: "hashicorp/terraform:\(version)"
},

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.

Duplication, see my comments above

Comment on lines +31 to +34
docker.#Copy & {
dest: "/src"
contents: source
},

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 just mounts to copy src in docker.#Run instead of a whole step

Comment on lines +48 to +51
_output: core.#Subdir & {
input: _run.output.rootfs
path: "/src/"
}

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 export field of docker.#Run instead

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.

He's not using export because of docker.#Build, but if the copy is a mount instead, then you can reduce all of this into two steps: 1) pull image; 2) run command with mount and export at the same time.

Comment on lines +48 to +51
_output: core.#Subdir & {
input: _run.output.rootfs
path: "/src/"
}

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 export field of docker.#Run instead

// Terraform init
#Init: {
// Terraform version
version: string | *"latest"

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.

See my comment on #Apply

// Terraform plan
#Plan: {
// Terraform version
version: string | *"latest"

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.

See my comment on #Apply

@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.

On second look, these three definitions look like practically the same except for the commands.

How about creating a #Command:

#Plan: #Command & {
    command: {
        name: "plan"
        args: [...]
    }
}

#Apply: #Command & {
    command: {
        name: "apply"
        args: [...]
    }
}

Just a suggestion, we can merge and improve later.

@helderco

helderco commented Apr 13, 2022 •

Copy link
Copy Markdown
Contributor

It seems the checks failed due to a timeout. If you amend your commit and force push it'll re-run them.

@jpadams

jpadams commented Apr 13, 2022 •

Copy link
Copy Markdown
Contributor

I did a manual re-run of the Lint to see if it would work. Let's see.

Seems to work. Re-running the other two failed checks.

This was referenced Apr 14, 2022
@nmeisenzahl

Copy link
Copy Markdown
Author

@helderco @TomChv I just came back from vacation. Do you think it makes sense to proceed with this implementation?

The Terraform package implementation in #2192 by @efoncubierta looks far more complete than mine. Also, it has already been approved by most of you. I also do not see a use case to implement two packages.

What do you think?

@TomChv

TomChv commented Apr 20, 2022

Copy link
Copy Markdown
Member

The Terraform package implementation in #2192 by @efoncubierta looks far more complete than mine. Also, it has already been approved by most of you. I also do not see a use case to implement two packages.

What do you think?

I agree with you, I think it would be awesome if you can play with his package and see if you can use for your own use case and then add some suggestions to his package so both of you have what you need 🚀

@shykes

shykes commented May 17, 2022

Copy link
Copy Markdown
Contributor

Just checking in, @nmeisenzahl did you end up contributing this package in another PR? Did you get stuck anywhere?

@nmeisenzahl

Copy link
Copy Markdown
Author

Just checking in, @nmeisenzahl did you end up contributing this package in another PR? Did you get stuck anywhere?

Hey @shykes, thanks for asking. I stopped implementing this due to PR #2192 which was contributed in parallel and was far more complete than mine.

@shykes

shykes commented May 17, 2022

Copy link
Copy Markdown
Contributor

OK I see, thanks! I think it may be time to promote some of these experimental packages to the top-level namespace, so more people feel comfortable trying them.

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.

✨ Dagger 0.2 Terraform package

6 participants