Skip to content

Commit

Permalink
V1 (#1)
Browse files Browse the repository at this point in the history
* v1

* azdeploy

* action.yml

* azlogin

* azdeploy

* another one

* let's try this

* let's see

* tpyos

* -ErrorAction SilentlyContinue

* location

* typo

* resourceGroupLocation

* gci

* indent

* params

* recurse

* Get-Location

* az

* other path

* go

* workspace

* testing delete

* and

* error handling

* remove

* test no azlogin

* go

* typo

* typo

* v1

* go

* go

* deploymentname

* delete

* delete

* go

* output

* create

Co-authored-by: Sebastian Gräf <[email protected]>
  • Loading branch information
segraef and segraef authored Mar 23, 2020
1 parent 4a3eb6d commit 0872419
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 99 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/azdeploy.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: azlogin
name: azdeploy

on:
push:
branches: [ master ]
branches: [ v1 ]
pull_request:
branches: [ master ]

Expand All @@ -21,7 +21,8 @@ jobs:
- name: Azure ARM Deployment
uses: segraef/azdeploy@v1
with:
resourceGroupName: ${{ secrets.resourceGroupName }}
templateFile: "deploy.json"
parametersFile: "parameters.json"
resourceGroupCommand: ${{ secrets.resourceGroupCommand }}
resourceGroupName: "rg-storage"
resourceGroupLocation: "westeurope"
templateFile: "Modules/StorageAccount/deploy.json"
parametersFile: "Modules/StorageAccount/parameters.json"
resourceGroupCommand: "create"
File renamed without changes.
File renamed without changes.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ To log into a Azure, I recommend using [azlogin](https://github.com/segraef/azlo
- uses: segraef/azdeploy@v1
with:
resourceGroupName: ${{ secrets.resourceGroupName }}
templateFile: ${{ secrets.templateFile }}
parametersFile: ${{ secrets.parametersFile }}
resourceGroupCommand: ${{ secrets.resourceGroupCommand }}
resourceGroupName: "rg-deploy"
resourceGroupLocation: "westeurope"
templateFile: "deploy.json"
parametersFile: "parameters.json"
```

Expand All @@ -24,8 +24,9 @@ To log into a Azure, I recommend using [azlogin](https://github.com/segraef/azlo

- 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
- `resourceGroupLocation`**Mandatory**
- `templateFile`**Mandatory** - Relative path in your github repository. URL is in progress.
- `parametersFile`**Mandatory** - Relative path in your github repository. URL is in progress.

- If `resourceGroupCommand` is "delete"
- `resourceGroupName`**Mandatory**
20 changes: 13 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ inputs:
resourceGroupName:
description: 'Name of the resource group.'
required: true
resourceGroupLocation:
description: 'Location of the resource group.'
required: true
templateFile:
description: 'ARM template file location.'
required: true
parametersFile:
description: 'ARM parameters file location.'
required: false
resrouceGroupCommand:
required: true
resourceGroupCommand:
description: 'RG command.'
default: 'create'
required: false
outputs:
output:
Expand All @@ -21,10 +25,12 @@ runs:
image: "dockerfile"
args:
- -resourceGroupName
- ${{inputs.resourceGroupName}}
- ${{ inputs.resourceGroupName }}
- -resourceGroupLocation
- ${{ inputs.resourceGroupLocation }}
- -templateFile
- ${{inputs.templateFile}}
- ${{ inputs.templateFile }}
- -parametersFile
- ${{inputs.parametersFile}}
- -resrouceGroupCommand
- ${{inputs.resrouceGroupCommand}}
- ${{ inputs.parametersFile }}
- -resourceGroupCommand
- ${{ inputs.resourceGroupCommand }}
8 changes: 4 additions & 4 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM mcr.microsoft.com/azure-cli:latest
FROM mcr.microsoft.com/powershell:latest

COPY entry.sh /
RUN pwsh -c "Install-Module Az -Scope AllUsers -Acceptlicense -Force"

RUN chmod +x /entry.sh
COPY entry.ps1 /entry.ps1

ENTRYPOINT ["/entry.sh"]
ENTRYPOINT ["pwsh", "-File", "/entry.ps1"]
59 changes: 59 additions & 0 deletions entry.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Param(
[string]$resourceGroupName,
[string]$resourceGroupLocation,
[string]$resourceGroupCommand,
[string]$templateFile,
[string]$parametersFile
)

$resourceGroupName
$resourceGroupLocation
$resourceGroupCommand
$templateFile
$parametersFile

$context = Get-AzContext
if (!$context) {
Write-Output "No Azure context found! Please make sure azlogin has run before."
exit
}

if (-not $resourceGroupName) {
Write-Output "resourceGroupName is not set."
exit
}

if ($resourceGroupCommand -and ($resourceGroupCommand -like "create")) {
Write-Output "Executing commands to Create/Update resource group."
if (-not (Get-AzResourceGroup -Name $resourceGroupName -ErrorAction SilentlyContinue)) {
if ($resourceGroupLocation) {
New-AzResourceGroup -Name $resourceGroupName -Location "$resourceGroupLocation"

if ($templateFile -and $parametersFile) {
$DeploymentInputs = @{
Name = "$($env:GITHUB_WORKFLOW)-$($env:GITHUB_ACTOR)-$(Get-Date -Format yyyyMMddHHMMss)"
ResourceGroupName = "$resourceGroupName"
TemplateFile = "$templateFile"
TemplateParameterFile = "$parametersFile"
Mode = "Incremental"
Verbose = $true
ErrorAction = "Stop"
}

New-AzResourceGroupDeployment @DeploymentInputs
}
else {
Write-Output "Template or parameters file does not exist."
}
}
else {
Write-Output "resourceGroupLocation is not set."
exit
}
}
} elseif ($resourceGroupCommand -like "delete") {
Write-Output "resourceGroupCommand is set to 'delete'. Removing $resourceGroupName now. "
Remove-AzResourceGroup -Name $resourceGroupName -Force
} else {
Write-Output "Something went wrong."
}
76 changes: 0 additions & 76 deletions entry.sh

This file was deleted.

0 comments on commit 0872419

Please sign in to comment.