Skip to content

How to test and validate a template locally? #5452

Answered by jsjoeio
jsjoeio asked this question in Q&A
Discussion options

You must be logged in to vote

@johnstcn showed me his workflow:

  1. make a temporary directory: mkdir tmp/tf-template-test
  2. inside that dir: touch main.tf and add your Terraform code
  3. run terraform init
  4. run terraform apply

Here's an example for some code that creates a script:

main.tf

variable "dotfiles_uri" {
  type        = string
}

resource "local_file" "script" {
  filename = "${path.module}/script.sh"
  content  = <<-EOF
    #!/bin/sh
    set -x
    # install and start code-server
    curl -fsSL https://code-server.dev/install.sh | sh -s -- --version 4.8.3
    code-server --auth none --port 13337 &
    sudo service docker start
    DOTFILES_URI=${var.dotfiles_uri}
    if [ -n "$DOTFILES_URI" ]; then
      coder dotf…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by jsjoeio
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants