Amending changes from @TomChv

Signed-off-by: Sujay Pillai <sujayopillai@gmail.com>
This commit is contained in:
Sujay Pillai 2021-08-12 01:37:17 +08:00
parent bdd6b5a56e
commit d74753bca7
3 changed files with 37 additions and 19 deletions

View File

@ -7,16 +7,19 @@ import (
"alpha.dagger.io/os"
)
// Default Azure CLI version
let defaultVersion = "2.27.1@sha256:1e117183100c9fce099ebdc189d73e506e7b02d2b73d767d3fc07caee72f9fb1"
//Azure Config shared by all Azure packages
#Config: {
// AZURE tenant id
tenantId: dagger.#Secret @dagger(input)
tenantId: dagger.#Secret & dagger.#Input
// AZURE subscription id
subscriptionId: dagger.#Secret @dagger(input)
subscriptionId: dagger.#Secret & dagger.#Input
// AZURE app id for the service principal used
appId: dagger.#Secret @dagger(input)
appId: dagger.#Secret & dagger.#Input
// AZURE password for the service principal used
password: dagger.#Secret @dagger(input)
password: dagger.#Secret & dagger.#Input
}
// Azure Cli to be used by all Azure packages
@ -24,11 +27,15 @@ import (
// Azure Config
config: #Config
// Azure CLI version to install
version: string | *defaultVersion
// Container image
os.#Container & {
image: docker.#Pull & {
from: "mcr.microsoft.com/azure-cli"
from: "mcr.microsoft.com/azure-cli:\(version)"
}
always: true
command: """
@ -36,9 +43,11 @@ import (
az account set -s "$(cat /run/secrets/subscriptionId)"
"""
secret: "/run/secrets/appId": config.appId
secret: "/run/secrets/password": config.password
secret: "/run/secrets/tenantId": config.tenantId
secret: "/run/secrets/subscriptionId": config.subscriptionId
secret: {
"/run/secrets/appId": config.appId
"/run/secrets/password": config.password
"/run/secrets/tenantId": config.tenantId
"/run/secrets/subscriptionId": config.subscriptionId
}
}
}

View File

@ -3,6 +3,7 @@ package resourcegroup
import (
"alpha.dagger.io/azure"
"alpha.dagger.io/os"
"alpha.dagger.io/dagger"
)
// Create a resource group
@ -11,10 +12,13 @@ import (
config: azure.#Config
// ResourceGroup name
rgName: string @dagger(input)
rgName: string & dagger.#Input
// ResourceGroup location
rgLocation: string @dagger(input)
rgLocation: string & dagger.#Input
// ResourceGroup Id
id: string & dagger.#Output
// Container image
ctr: os.#Container & {
@ -24,16 +28,21 @@ import (
always: true
command: """
az group create -l "\(rgLocation)" -n "\(rgName)"
az group show -n "\(rgName)" --query "id" -o json | jq -r . | tr -d "\n" > /resourceGroupId
az group create -l "$AZURE_DEFAULTS_LOCATION" -n "$AZURE_DEFAULTS_GROUP"
az group show -n "$AZURE_DEFAULTS_GROUP" --query "id" -o json | jq -r . | tr -d "\n" > /resourceGroupId
"""
env: {
AZURE_DEFAULTS_GROUP: rgName
AZURE_DEFAULTS_LOCATION: rgLocation
}
}
// Resource Id
id: {
id: ({
os.#File & {
from: ctr
path: "/resourceGroupId"
}
}.contents @dagger(output)
}).contents
}

View File

@ -6,12 +6,12 @@ import (
"alpha.dagger.io/random"
)
suffix: random.#String & {
TestSuffix: random.#String & {
seed: "azrg"
}
rg: resourcegroup.#ResourceGroup & {
TestRG: resourcegroup.#ResourceGroup & {
config: azure.#Config
rgName: "rg-test-\(suffix.out)"
rgName: "rg-test-\(TestSuffix.out)"
rgLocation: "eastus2"
}