-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
144 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,31 @@ | ||
# azdeploy | ||
Azure GitHub Action Deploy (azdeploy) | ||
# GitHub Action for Managing Azure Resources | ||
|
||
This action can be used to create or update a resource group in Azure using the [Azure Resource Manager templates](https://azure.microsoft.com/en-in/documentation/articles/resource-group-template-deploy/) | ||
One can also use this to delete a resource group, including all the resources within the resource group. | ||
|
||
To log into a Azure, I recommend using [azlogin](https://github.com/segraef/azlogin) Action. | ||
|
||
## Usage | ||
|
||
``` | ||
- uses: segraef/azdeploy@v1 | ||
with: | ||
resourceGroupName: ${{ secrets.resourceGroupName }} | ||
templateFile: ${{ secrets.templateFile }} | ||
parametersFile: ${{ secrets.parametersFile }} | ||
resourceGroupCommand: ${{ secrets.resourceGroupCommand }} | ||
``` | ||
|
||
### Environment variables | ||
|
||
- `resourceGroupCommand` – **Optional**. | ||
|
||
- If `resourceGroupCommand` is not specified or is "create" | ||
- `resourceGroupName` – **Mandatory** | ||
- `templateFile` – **Mandatory** - Can be a URL or relative path in your github repository | ||
- `parametersFile` – **Mandatory** - Can be a URL or relative path in your github repository | ||
|
||
- If `resourceGroupCommand` is "delete" | ||
- `resourceGroupName` – **Mandatory** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: azdeploy | ||
description: 'Deploy ARM template' | ||
inputs: | ||
resourceGroupName: | ||
description: 'Name of the resource group.' | ||
required: true | ||
templateFile: | ||
description: 'ARM template file location.' | ||
required: true | ||
parametersFile: | ||
description: 'ARM parameters file location.' | ||
required: false | ||
resrouceGroupCommand: | ||
description: 'RG command.' | ||
required: false | ||
outputs: | ||
output: | ||
description: 'ARM outputs' | ||
runs: | ||
using: "docker" | ||
image: "dockerfile" | ||
args: | ||
- -resourceGroupName | ||
- ${{inputs.resourceGroupName}} | ||
- -templateFile | ||
- ${{inputs.templateFile}} | ||
- -parametersFile | ||
- ${{inputs.parametersFile}} | ||
- -resrouceGroupCommand | ||
- ${{inputs.resrouceGroupCommand}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM mcr.microsoft.com/azure-cli:latest | ||
|
||
COPY entry.sh / | ||
|
||
RUN chmod +x /entry.sh | ||
|
||
ENTRYPOINT ["/entry.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
export AZURE_HTTP_USER_AGENT="GITHUBACTIONS_${GITHUB_ACTION_NAME}_${GITHUB_REPOSITORY}" | ||
|
||
if [[ -z "$resourceGroupName" ]] | ||
then | ||
echo "resourceGroupName is not set." >&2 | ||
exit 1 | ||
fi | ||
|
||
if [[ -z "$resourceGroupCommand" ]] || [[ ${resourceGroupCommand,,} == 'create' ]] | ||
then | ||
echo "Executing commands to Create/Update resource group." | ||
# Create Resource group if it does not exists | ||
|
||
resourceGroupExists=$(az group exists -n "$resourceGroupName") | ||
if [[ $resourceGroupExists == "false" ]] | ||
then | ||
if [[ -z "$resourceGroupLocation" ]] | ||
then | ||
echo "resourceGroupLocation is not set." >&2 | ||
exit 1 | ||
fi | ||
az group create --name "$resourceGroupName" --location "$resourceGroupLocation" | ||
fi | ||
|
||
uri_regex="^(http://|https://)\\w+" | ||
guid=$(uuidgen | cut -d '-' -f 1) | ||
|
||
# Download parameters file if it is a remote URL | ||
|
||
if [[ $parametersFile =~ $uri_regex ]] | ||
then | ||
PARAMETERS=$(curl "$parametersFile") | ||
echo "Downloaded parameters from ${parametersFile}" | ||
else | ||
paramsFile="${GITHUB_WORKSPACE}/${parametersFile}" | ||
if [[ ! -e "$paramsFile" ]] | ||
then | ||
echo "Parameters file ${paramsFile} does not exists." >&2 | ||
exit 1 | ||
fi | ||
PARAMETERS="@${paramsFile}" | ||
fi | ||
|
||
# Generate deployment name if not specified | ||
|
||
if [[ -z "$deploymentName" ]] | ||
then | ||
deploymentName="Github-Action-azdeploy-${guid}" | ||
echo "Generated Deployment Name ${deploymentName}" | ||
fi | ||
|
||
# Deploy ARM template | ||
|
||
if [[ $templateFile =~ $uri_regex ]] | ||
then | ||
az group deployment create -g "$resourceGroupName" --name "$deploymentName" --template-uri "$templateFile" --parameters "$PARAMETERS" | ||
else | ||
templFile="${GITHUB_WORKSPACE}/${templateFile}" | ||
if [[ ! -e "$templFile" ]] | ||
then | ||
echo "Template file ${templFile} does not exists." >&2 | ||
exit 1 | ||
fi | ||
az group deployment create -g "$resourceGroupName" --name "$deploymentName" --template-file "$templFile" --parameters "$PARAMETERS" | ||
fi | ||
elif [[ ${resourceGroupCommand,,} == 'delete' ]] | ||
then | ||
echo "Executing commands to Delete resource group." | ||
az group delete -n "$resourceGroupName" --yes | ||
else | ||
echo "Invalid resourceGroupCommand. Allowed values are: CREATE, DELETE." >&2 | ||
exit 1 | ||
fi |