Skip to content
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

solaris plan reports a "Template was not specified" error? #2

Open
Juerg-Liechti opened this issue Aug 22, 2022 · 2 comments
Open

solaris plan reports a "Template was not specified" error? #2

Juerg-Liechti opened this issue Aug 22, 2022 · 2 comments

Comments

@Juerg-Liechti
Copy link

Where can i find a template file or an example?

@sontags
Copy link
Contributor

sontags commented Oct 26, 2022

For now, here:

A template that renders to an (ugly) HTML file:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Execution Plan</title>
  <style type="text/css">
    .manual {
      padding-left: 40px;
	  border-left: solid gray 3px;
    }
    pre {
      padding: 5px;
	  background-color: #777;
	  color: white;
      overflow-x: auto;
      white-space: pre-wrap;
      white-space: -moz-pre-wrap;
      white-space: -pre-wrap;
      white-space: -o-pre-wrap;
      word-wrap: break-word;
	}
	th, td {
	  border-bottom: 1px solid #ddd;
	  padding: 15px;
      text-align: left;
    }
    .container {
	  max-width: 800px;
	  width: 90%;
	  margin: 0 auto;
    }
  </style>
</head>
<body>
  <div class="container">
  {{range $tier, $workspaces := .}}
  <h1>({{$tier}}) Tier {{ $tier }}</h1>
  {{range $i, $workspace := $workspaces}}
  <h2>({{$tier}}.{{$i}}) Workspace <code>{{$workspace.Root}}</code></h2>
  {{if $workspace.PreManualRendered}}
  <h3>Manual Pre-Work</h3>
  <div class="manual">
  {{$workspace.PreManualRendered}}
  </div>
  {{end}}
  <h3>Terraform</h3>
  <pre><code>
  (cd {{ $workspace.Root }} && terraform apply)
  </code></pre>
  {{if $workspace.PostManualRendered}}
  <h3>Manual Post-Work</h3>
  <div class="manual">
  {{$workspace.PostManualRendered}}
  </div>
  {{end}}{{end}}{{end}}
  </div>
</body>
</html>

... and one that renders a bash script which does a terraform init and plan for a whole directory and prints the change summary for everything... and all of this is parallel.

#!/bin/bash

RUNPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )/"

WORKDIR=`mktemp -d -p "$DIR"`
function cleanup {
  rm -rf "$WORKDIR"
}
trap cleanup EXIT

execute() {
  CONFIGNAME=$(realpath --relative-to=$RUNPATH $(pwd))
  REPORT=$WORKDIR/$(echo $CONFIGNAME | tr '/' '_').report
  printf "\n------------------------------------\n$CONFIGNAME\n------------------------------------\n" > $REPORT

  rm -f .terraform-version

  terraform version | grep v1 -q
  if [ ! $? -eq 0 ]; then
    echo ">>> WRONG TERRAFORM VERSION!" >> $REPORT
    return 1
  fi

  terraform init -upgrade > /dev/null
  if [ ! $? -eq 0 ]; then
    echo ">>> INIT FAILED!" >> $REPORT
    return 1
  fi

  terraform apply -refresh-only -auto-approve -input=false > /dev/null
  if [ ! $? -eq 0 ]; then
    echo ">>> APPLY (REFRESH ONLY) FAILED!" >> $REPORT
    return 1
  fi

  terraform plan -input=false -json | grep "planned_change\|change_summary" | sed "s/@//g" | jq -r ".message" >> $REPORT
  if [ ! $? -eq 0 ]; then
    echo ">>> PLAN FAILED!" >> $REPORT
    return 1
  fi
}

# terraform fmt -recursive
{{range $tier, $workspaces := .}}
# ------------------------
# tier {{$tier}}
# ------------------------
{{range $i, $workspace := $workspaces}}
{{if mod $i 4}}{{if gt $i 0}}wait{{end}}{{end}}
(cd {{$workspace.Root}} && execute) &
{{end}}
wait
{{end}}

for i in $(ls -d1 $WORKDIR/*.report); do
  cat $i | grep -q "Plan: 0 to add, 0 to change, 0 to destroy." || cat $i;
done

That should serve you for now, but I agree that this lacks a bit of documentation. I am keeping the issue open.

@Juerg-Liechti
Copy link
Author

Many thanks the template works perfectly :-)!

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

2 participants