Skip to content

Commit

Permalink
Merge pull request #35 from RoseSecurity/add-terramaid-demo
Browse files Browse the repository at this point in the history
Add terramaid demo
  • Loading branch information
RoseSecurity authored Aug 4, 2024
2 parents 24ff2b1 + 95da9ff commit a8a8be3
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 3 deletions.
30 changes: 30 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM golang:1.22 AS build

# Install Terramaid
RUN go install github.com/RoseSecurity/terramaid@latest

FROM mcr.microsoft.com/vscode/devcontainers/base:debian

# Install required packages
RUN apt-get update && \
apt-get install -y apt-utils ca-certificates curl unzip zsh-autosuggestions

# Change shell to zsh
RUN chsh -s /bin/zsh vscode

# Install Terraform
ARG TERRAFORM_VERSION=1.9.2
RUN curl -fsSL https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip -o terraform.zip && \
unzip terraform.zip && \
mv terraform /usr/local/bin/ && \
rm terraform.zip

# Install the starship prompt
RUN curl -sS https://starship.rs/install.sh | sh -s -- -y

# Copy Terramaid binary from the build stage
COPY --from=build /go/bin/terramaid /usr/local/bin/terramaid

# Install the rootfs/ configurations
COPY rootfs/ /

45 changes: 45 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "Terramaid Demo",
"build": {
"dockerfile": "Dockerfile",
"context": "."
},
"hostRequirements": {
"cpus": 8,
"memory": "16gb",
"storage": "32gb"
},
"features": {
},
"workspaceFolder": "/workspace",
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind",
"customizations": {
"codespaces": {
"openFiles": [
"docs/Getting_Started.md"
]
},
"vscode": {
"extensions": [
"bierner.github-markdown-preview",
"tomasdahlqvist.markdown-admonitions",
"HashiCorp.terraform",
"EditorConfig.EditorConfig"
],
"settings": {
"git.openRepositoryInParentFolders": "always",
"git.autofetch": true,
"git.showProgress": true,
"workbench.startupEditor": "readme",
"workbench.editorAssociations": {
"*.md": "vscode.markdown.preview.editor"
},
"terminal.integrated.tabs.title": "Terramaid (${process})",
"terminal.integrated.tabs.description": "${task}${separator}${local}${separator}${cwdFolder}",
"terminal.integrated.shell.linux": "/bin/zsh",
"terminal.integrated.allowWorkspaceConfiguration": true,
"terminal.integrated.commandsToSkipShell": []
}
}
}
}
49 changes: 49 additions & 0 deletions .devcontainer/rootfs/home/vscode/.config/starship.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
format = """
$username\
$hostname\
$directory\
$git_branch\
$git_state\
$git_status\
$cmd_duration\
$line_break\
$python\
$character"""

command_timeout = 2000

[directory]
style = "blue"

[character]
success_symbol = "[❯](purple)"
error_symbol = "[❯](red)"
vimcmd_symbol = "[❮](green)"

[git_branch]
format = "[$branch]($style)"
style = "bright-black"

[git_status]
format = "[[(*$conflicted$untracked$modified$staged$renamed$deleted)](218) ($ahead_behind$stashed)]($style)"
style = "cyan"
conflicted = ""
untracked = ""
modified = ""
staged = ""
renamed = ""
deleted = ""
stashed = ""

[git_state]
format = '\([$state( $progress_current/$progress_total)]($style)\) '
style = "bright-black"

[cmd_duration]
format = "[$duration]($style) "
style = "yellow"

[python]
format = "[$virtualenv]($style) "
style = "bright-black"

15 changes: 15 additions & 0 deletions .devcontainer/rootfs/home/vscode/.zshrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# ZSH Auto Suggestions
export ZSH_AUTOSUGGEST_STRATEGY=(history completion)
source /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh

autoload -Uz compinit
compinit

# Enable Starship prompt
eval "$(starship init zsh)"

# Install terramaid completion
eval $(terramaid completion zsh)

# Show Terramaid version
terramaid version
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM golang:alpine

# Terraform version
ARG TERRAFORM_VERSION=1.9.2

# Install necessary dependencies
RUN apk update && apk add --no-cache \
bash \
Expand All @@ -8,7 +11,7 @@ RUN apk update && apk add --no-cache \
unzip

# Install Terraform
RUN curl -fsSL https://releases.hashicorp.com/terraform/1.9.2/terraform_1.9.2_linux_amd64.zip -o terraform.zip && \
RUN curl -fsSL https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip -o terraform.zip && \
unzip terraform.zip && \
mv terraform /usr/local/bin/ && \
rm terraform.zip
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ flowchart TD
end
```

> [!TIP]
> ### You can try out `terramaid` directly in your browser using GitHub Codespaces
>
> [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=rosesecurity/terramaid&skip_quickstart=true)
>
>
## Installation

Homebrew installation:
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TerramaidCmd() *cobra.Command {
cmd.Flags().StringVarP(&options.TFBinary, "tf-binary", "b", options.TFBinary, "Path to Terraform binary (env: TERRAMAID_TF_BINARY)")
cmd.Flags().StringVarP(&options.WorkingDir, "working-dir", "w", options.WorkingDir, "Working directory for Terraform (env: TERRAMAID_WORKING_DIR)")

cmd.AddCommand(docsCmd(), versionCmd())
cmd.AddCommand(docsCmd(), versionCmd(Version))

return cmd
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Release struct {
TagName string `json:"tag_name"`
}

func versionCmd() *cobra.Command {
func versionCmd(Version string) *cobra.Command {
cmd := &cobra.Command{
Use: "version",
Short: "Print the CLI version",
Expand Down
16 changes: 16 additions & 0 deletions docs/Getting_Started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Getting Started

This is a guide to help you get started with Terramaid! In this directory, you will find a few Terraform files that can be visualized using Terramaid. To kick the tires, try running the following commands:

```sh
cd test && terramaid -h
```

```sh
terramaid --subgraph-name Demo --direction LR --output Terramaid_Demo.md
```

```sh
cat Terramaid_Demo.md
```

16 changes: 16 additions & 0 deletions test/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
output "logs_bucket_id" {
value = aws_s3_bucket.logs.id
}

output "test_bucket_id" {
value = aws_s3_bucket.test.id
}

output "instance_id" {
value = aws_instance.example_instance.id
}

output "db_instance_id" {
value = aws_db_instance.example_db.id
}

4 changes: 4 additions & 0 deletions test/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
provider "aws" {
region = "us-west-2"
}

0 comments on commit a8a8be3

Please sign in to comment.