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

feat: avm helper script #70

Merged
merged 6 commits into from
Jan 5, 2024
Merged

feat: avm helper script #70

merged 6 commits into from
Jan 5, 2024

Conversation

matt-FFFFFF
Copy link
Member

This pull request adds a new script called avm which is a helper script for Azure Terraform module development. The script allows users to run make targets inside a Docker container. This script is useful for automating common development tasks and improving the development workflow.

Copy link
Member

@lonegunmanb lonegunmanb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case someone is using podman or other runtime instead of docker, I think we can add a variable so the user could set it to their runtime like this:

#!/usr/bin/env sh

usage () {
  echo "Usage: avm <make target>"
}

CONTAINER_RUNTIME=${CONTAINER_RUNTIME:-docker}

if [ ! "$(command -v $CONTAINER_RUNTIME)" ]; then
    echo "Error: $CONTAINER_RUNTIME is not installed. Please install $CONTAINER_RUNTIME first."
    exit 1
fi

if [ -z "$1" ]; then
    echo "Error: Please provide a make target. See https://github.com/Azure/tfmod-scaffold/blob/main/avmmakefile for available targets."
    echo
    usage
    exit 1
fi

$CONTAINER_RUNTIME run --rm -v "$(pwd)":/src -w /src mcr.microsoft.com/azterraform make "$1"

I would also like to add a .bat version so Windows user could use the same helper:

@echo off
SETLOCAL

REM Set CONTAINER_RUNTIME to its current value if it's already set, or docker if it's not
IF DEFINED CONTAINER_RUNTIME (SET "CONTAINER_RUNTIME=%CONTAINER_RUNTIME%") ELSE (SET "CONTAINER_RUNTIME=docker")

REM Check if CONTAINER_RUNTIME is installed
WHERE /Q %CONTAINER_RUNTIME%
IF ERRORLEVEL 1 (
    echo Error: %CONTAINER_RUNTIME% is not installed. Please install %CONTAINER_RUNTIME% first.
    exit /b
)

REM Check if a make target is provided
IF "%~1"=="" (
    echo Error: Please provide a make target. See https://github.com/Azure/tfmod-scaffold/blob/main/avmmakefile for available targets.
    exit /b
)

REM Run the make target with CONTAINER_RUNTIME
%CONTAINER_RUNTIME% run --rm -v "%cd%":/src -w /src mcr.microsoft.com/azterraform make %1

ENDLOCAL

Github Copilot is AWESOME!!! 😄

@matt-FFFFFF matt-FFFFFF dismissed lonegunmanb’s stale review January 5, 2024 10:46

implemented requested changes

@matt-FFFFFF matt-FFFFFF merged commit 37295ad into main Jan 5, 2024
6 checks passed
@matt-FFFFFF matt-FFFFFF deleted the feat/helperscript branch January 5, 2024 10:52
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.

2 participants