Skip to content

Extend coder to allow reuse of template terraform code #6117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alexandrulita91 opened this issue Feb 8, 2023 · 6 comments
Closed

Extend coder to allow reuse of template terraform code #6117

alexandrulita91 opened this issue Feb 8, 2023 · 6 comments

Comments

@alexandrulita91
Copy link

As a coder administrator, I want to avoid the need of copying the common logic for each new template I create. (dry principle)
The common logic is currently part of a terraform module that I would like to ship together with the template.

One idea suggested by the authors is to add a dir property that allows the authors to execute Terraform in a subdirectory and have the general files in the root directory.

@alexandrulita91 alexandrulita91 changed the title Extend coder to allow reuse of templates Extend coder to allow reuse of template terraform code Feb 8, 2023
@bpmct
Copy link
Member

bpmct commented Feb 8, 2023

Do you want to avoid shipping the module as a part of each template? You could reference a module from a GitHub repo to avoid duplication and then just extend it or pass template-specific parameters/resources.

# template1/main.tf
module "central-coder-module" {
  source = "github.com/yourorg/central-coder-module"
  myparam = "custom-for-template1"
}

resource "ebs_volume` `custom_template1_only_resource ` {
}
# template2/main.tf
module "central-coder-module" {
  source = "github.com/yourorg/central-coder-module"
  myparam = "custom-for-template2"
  myparam2 = "bar"
}

resource "aws_instance` `custom_template2_only_resource ` {
}

@alexandrulita91
Copy link
Author

alexandrulita91 commented Feb 9, 2023

Hi,

The module is locally and I would like to ship the module together with the template.

templates/
- modules/common
- template_1 (use the common module)
- template_2 (use the common module)

@pratheekrebala
Copy link

pratheekrebala commented Feb 10, 2023

One workaround that came up earlier is to symlink the module directory inside the template directory and then tar ing the template.

  • ln -s modules template_1/modules
  • tar -cvh -C ./template_1 | coder templates <push|create> -d - <name>

FWIW: We were trying use this approach but switched to remote modules like @bpmct mentioned which we found easier to manage/version.

@bpmct
Copy link
Member

bpmct commented Feb 10, 2023

Do you plan on managing all the projects in the same GitHub repo? If so, you could do the symlink or copy approach to include the module if you push via CI/CD.

@bpmct
Copy link
Member

bpmct commented Feb 10, 2023

It seems a bit risky for Coder to have a feature that grabs/copies arbitrary files from outside of the directory you are in.

@kylecarbs
Copy link
Member

I feel like we don't have great plans to fix this right now... and we wouldn't want to stray away from Terraform primitives unless required.

Closing for now, but please feel free to contribute ideas! We're open to them :)

@kylecarbs kylecarbs closed this as not planned Won't fix, can't repro, duplicate, stale Apr 3, 2023
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

No branches or pull requests

4 participants