From 5908aa628eaebbd078b4ef159031d5e1214dc86f Mon Sep 17 00:00:00 2001 From: Sujay Pillai Date: Wed, 11 Aug 2021 01:20:16 +0800 Subject: [PATCH 1/5] Adding support for azure and create a resource group Signed-off-by: Sujay Pillai --- docs/reference/universe/README.md | 2 + docs/reference/universe/azure/README.md | 45 +++++++++++++++++++ .../reference/universe/azure/resourcegroup.md | 34 ++++++++++++++ .../azure-resourcegroup/cue.mod/module.cue | 1 + .../cue.mod/pkg/.gitignore | 2 + stdlib/.dagger/env/azure-resourcegroup/rg.cue | 17 +++++++ stdlib/azure/azure.cue | 44 ++++++++++++++++++ stdlib/azure/resourcegroup/rg.cue | 42 +++++++++++++++++ stdlib/azure/resourcegroup/tests/rg.cue | 17 +++++++ stdlib/universe.bats | 4 ++ 10 files changed, 208 insertions(+) create mode 100644 docs/reference/universe/azure/README.md create mode 100644 docs/reference/universe/azure/resourcegroup.md create mode 100644 stdlib/.dagger/env/azure-resourcegroup/cue.mod/module.cue create mode 100644 stdlib/.dagger/env/azure-resourcegroup/cue.mod/pkg/.gitignore create mode 100644 stdlib/.dagger/env/azure-resourcegroup/rg.cue create mode 100644 stdlib/azure/azure.cue create mode 100644 stdlib/azure/resourcegroup/rg.cue create mode 100644 stdlib/azure/resourcegroup/tests/rg.cue diff --git a/docs/reference/universe/README.md b/docs/reference/universe/README.md index c0458a15..f6657b91 100644 --- a/docs/reference/universe/README.md +++ b/docs/reference/universe/README.md @@ -9,6 +9,8 @@ - [aws/elb](./aws/elb.md) - AWS Elastic Load Balancer (ELBv2) - [aws/rds](./aws/rds.md) - AWS Relational Database Service (RDS) - [aws/s3](./aws/s3.md) - AWS Simple Storage Service +- [azure](./azure/README.md) - Azure base package +- [azure/resourcegroup](./azure/resourcegroup.md) - - - [dagger](./dagger/README.md) - Dagger core types - [dagger/op](./dagger/op.md) - op: low-level operations for Dagger processing pipelines - [docker](./docker/README.md) - Docker container operations diff --git a/docs/reference/universe/azure/README.md b/docs/reference/universe/azure/README.md new file mode 100644 index 00000000..5b54802d --- /dev/null +++ b/docs/reference/universe/azure/README.md @@ -0,0 +1,45 @@ +--- +sidebar_label: azure +--- + +# alpha.dagger.io/azure + +Azure base package + +```cue +import "alpha.dagger.io/azure" +``` + +## azure.#CLI + +Azure Cli to be used by all Azure packages + +### azure.#CLI Inputs + +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*config.tenantId* | `dagger.#Secret` |AZURE tenant id | +|*config.subscriptionId* | `dagger.#Secret` |AZURE subscription id | +|*config.appId* | `dagger.#Secret` |AZURE app id for the service principal used | +|*config.password* | `dagger.#Secret` |AZURE password for the service principal used | + +### azure.#CLI Outputs + +_No output._ + +## azure.#Config + +Azure Config shared by all Azure packages + +### azure.#Config Inputs + +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*tenantId* | `dagger.#Secret` |AZURE tenant id | +|*subscriptionId* | `dagger.#Secret` |AZURE subscription id | +|*appId* | `dagger.#Secret` |AZURE app id for the service principal used | +|*password* | `dagger.#Secret` |AZURE password for the service principal used | + +### azure.#Config Outputs + +_No output._ diff --git a/docs/reference/universe/azure/resourcegroup.md b/docs/reference/universe/azure/resourcegroup.md new file mode 100644 index 00000000..e6a9b670 --- /dev/null +++ b/docs/reference/universe/azure/resourcegroup.md @@ -0,0 +1,34 @@ +--- +sidebar_label: resourcegroup +--- + +# alpha.dagger.io/azure/resourcegroup + +```cue +import "alpha.dagger.io/azure/resourcegroup" +``` + +## resourcegroup.#ResourceGroup + +Create a resource group + +### resourcegroup.#ResourceGroup Inputs + +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*config.tenantId* | `dagger.#Secret` |AZURE tenant id | +|*config.subscriptionId* | `dagger.#Secret` |AZURE subscription id | +|*config.appId* | `dagger.#Secret` |AZURE app id for the service principal used | +|*config.password* | `dagger.#Secret` |AZURE password for the service principal used | +|*rgName* | `string` |ResourceGroup name | +|*rgLocation* | `string` |ResourceGroup location | +|*ctr.image.config.tenantId* | `dagger.#Secret` |AZURE tenant id | +|*ctr.image.config.subscriptionId* | `dagger.#Secret` |AZURE subscription id | +|*ctr.image.config.appId* | `dagger.#Secret` |AZURE app id for the service principal used | +|*ctr.image.config.password* | `dagger.#Secret` |AZURE password for the service principal used | + +### resourcegroup.#ResourceGroup Outputs + +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*id* | `string` |Resource Id | diff --git a/stdlib/.dagger/env/azure-resourcegroup/cue.mod/module.cue b/stdlib/.dagger/env/azure-resourcegroup/cue.mod/module.cue new file mode 100644 index 00000000..f8af9cef --- /dev/null +++ b/stdlib/.dagger/env/azure-resourcegroup/cue.mod/module.cue @@ -0,0 +1 @@ +module: "" diff --git a/stdlib/.dagger/env/azure-resourcegroup/cue.mod/pkg/.gitignore b/stdlib/.dagger/env/azure-resourcegroup/cue.mod/pkg/.gitignore new file mode 100644 index 00000000..a572e9ee --- /dev/null +++ b/stdlib/.dagger/env/azure-resourcegroup/cue.mod/pkg/.gitignore @@ -0,0 +1,2 @@ +# dagger universe +alpha.dagger.io diff --git a/stdlib/.dagger/env/azure-resourcegroup/rg.cue b/stdlib/.dagger/env/azure-resourcegroup/rg.cue new file mode 100644 index 00000000..86b07df6 --- /dev/null +++ b/stdlib/.dagger/env/azure-resourcegroup/rg.cue @@ -0,0 +1,17 @@ +package rg + +import ( + "alpha.dagger.io/azure" + "alpha.dagger.io/azure/resourcegroup" + "alpha.dagger.io/random" +) + +suffix: random.#String & { + seed: "azrg" +} + +rg: resourcegroup.#ResourceGroup & { + config: azure.#Config + rgName: "rg-test-\(suffix.out)" + rgLocation: "eastus2" +} diff --git a/stdlib/azure/azure.cue b/stdlib/azure/azure.cue new file mode 100644 index 00000000..23429454 --- /dev/null +++ b/stdlib/azure/azure.cue @@ -0,0 +1,44 @@ +// Azure base package +package azure + +import ( + "alpha.dagger.io/dagger" + "alpha.dagger.io/dagger/op" +) + +//Azure Config shared by all Azure packages +#Config: { + // AZURE tenant id + tenantId: dagger.#Secret @dagger(input) + // AZURE subscription id + subscriptionId: dagger.#Secret @dagger(input) + // AZURE app id for the service principal used + appId: dagger.#Secret @dagger(input) + // AZURE password for the service principal used + password: dagger.#Secret @dagger(input) +} + +// Azure Cli to be used by all Azure packages +#CLI: { + // Azure Config + config: #Config + + #up: [ + op.#FetchContainer & { + ref: "mcr.microsoft.com/azure-cli" + }, + + op.#Exec & { + args: ["sh", "-c", + #""" + az login --service-principal -u "$(cat /run/secrets/appId)" -p "$(cat /run/secrets/password)" -t "$(cat /run/secrets/tenantId)" + az account set -s "$(cat /run/secrets/subscriptionId)" + """#, + ] + mount: "/run/secrets/appId": secret: config.appId + mount: "/run/secrets/password": secret: config.password + mount: "/run/secrets/tenantId": secret: config.tenantId + mount: "/run/secrets/subscriptionId": secret: config.subscriptionId + }, + ] +} diff --git a/stdlib/azure/resourcegroup/rg.cue b/stdlib/azure/resourcegroup/rg.cue new file mode 100644 index 00000000..26a3ae96 --- /dev/null +++ b/stdlib/azure/resourcegroup/rg.cue @@ -0,0 +1,42 @@ +package resourcegroup + +import ( + "alpha.dagger.io/os" + "alpha.dagger.io/azure" +) + +// Create a resource group +#ResourceGroup: { + // Azure Config + config: azure.#Config + + // ResourceGroup name + rgName: string @dagger(input) + + // ResourceGroup location + rgLocation: string @dagger(input) + + // Container image + ctr: os.#Container & { + image: azure.#CLI & { + "config": config + } + // Path of the shell to execute + shell: path: "/bin/bash" + + 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 + """ + } + + // Resource Id + id: { + os.#File & { + from: ctr + path: "/resourceGroupId" + } + }.contents @dagger(output) +} diff --git a/stdlib/azure/resourcegroup/tests/rg.cue b/stdlib/azure/resourcegroup/tests/rg.cue new file mode 100644 index 00000000..ac5aaca8 --- /dev/null +++ b/stdlib/azure/resourcegroup/tests/rg.cue @@ -0,0 +1,17 @@ +package resourcegroup + +import ( + "alpha.dagger.io/azure" + "alpha.dagger.io/azure/resourcegroup" + "alpha.dagger.io/random" +) + +suffix: random.#String & { + seed: "azrg" +} + +rg: resourcegroup.#ResourceGroup & { + config: azure.#Config + rgName: "rg-test-\(suffix.out)" + rgLocation: "eastus2" +} diff --git a/stdlib/universe.bats b/stdlib/universe.bats index 79a0e680..54de3063 100644 --- a/stdlib/universe.bats +++ b/stdlib/universe.bats @@ -184,3 +184,7 @@ setup() { run dagger -w "$DAGGER_SANDBOX" -e terraform input unset TestTerraform.apply.tfvars.input assert_success } + +# @test "azure-resourcegroup" { +# dagger -e azure-resourcegroup up +# } \ No newline at end of file From bdd6b5a56eccf60da05157fbbdee7c949dbac045 Mon Sep 17 00:00:00 2001 From: Guillaume de Rouville Date: Wed, 11 Aug 2021 15:16:56 +0200 Subject: [PATCH 2/5] Port azure.#CLI from `up` to `os.#Container` + manual testing + integrate bats test Signed-off-by: Guillaume de Rouville --- docs/reference/universe/azure/README.md | 13 +++---- .../reference/universe/azure/resourcegroup.md | 25 ++++++------- .../env/azure-resourcegroup/.gitignore | 2 ++ .../azure-resourcegroup/cue.mod/module.cue | 1 - .../cue.mod/pkg/.gitignore | 2 -- stdlib/.dagger/env/azure-resourcegroup/rg.cue | 17 --------- .../env/azure-resourcegroup/values.yaml | 23 ++++++++++++ stdlib/azure/azure.cue | 36 +++++++++---------- stdlib/azure/resourcegroup/rg.cue | 5 +-- stdlib/universe.bats | 7 ++-- 10 files changed, 68 insertions(+), 63 deletions(-) create mode 100644 stdlib/.dagger/env/azure-resourcegroup/.gitignore delete mode 100644 stdlib/.dagger/env/azure-resourcegroup/cue.mod/module.cue delete mode 100644 stdlib/.dagger/env/azure-resourcegroup/cue.mod/pkg/.gitignore delete mode 100644 stdlib/.dagger/env/azure-resourcegroup/rg.cue create mode 100644 stdlib/.dagger/env/azure-resourcegroup/values.yaml diff --git a/docs/reference/universe/azure/README.md b/docs/reference/universe/azure/README.md index 5b54802d..1f2e288d 100644 --- a/docs/reference/universe/azure/README.md +++ b/docs/reference/universe/azure/README.md @@ -16,12 +16,13 @@ Azure Cli to be used by all Azure packages ### azure.#CLI Inputs -| Name | Type | Description | -| ------------- |:-------------: |:-------------: | -|*config.tenantId* | `dagger.#Secret` |AZURE tenant id | -|*config.subscriptionId* | `dagger.#Secret` |AZURE subscription id | -|*config.appId* | `dagger.#Secret` |AZURE app id for the service principal used | -|*config.password* | `dagger.#Secret` |AZURE password for the service principal used | +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*config.tenantId* | `dagger.#Secret` |AZURE tenant id | +|*config.subscriptionId* | `dagger.#Secret` |AZURE subscription id | +|*config.appId* | `dagger.#Secret` |AZURE app id for the service principal used | +|*config.password* | `dagger.#Secret` |AZURE password for the service principal used | +|*image.from* | `"mcr.microsoft.com/azure-cli"` |Remote ref (example: "index.docker.io/alpine:latest") | ### azure.#CLI Outputs diff --git a/docs/reference/universe/azure/resourcegroup.md b/docs/reference/universe/azure/resourcegroup.md index e6a9b670..9de772be 100644 --- a/docs/reference/universe/azure/resourcegroup.md +++ b/docs/reference/universe/azure/resourcegroup.md @@ -14,18 +14,19 @@ Create a resource group ### resourcegroup.#ResourceGroup Inputs -| Name | Type | Description | -| ------------- |:-------------: |:-------------: | -|*config.tenantId* | `dagger.#Secret` |AZURE tenant id | -|*config.subscriptionId* | `dagger.#Secret` |AZURE subscription id | -|*config.appId* | `dagger.#Secret` |AZURE app id for the service principal used | -|*config.password* | `dagger.#Secret` |AZURE password for the service principal used | -|*rgName* | `string` |ResourceGroup name | -|*rgLocation* | `string` |ResourceGroup location | -|*ctr.image.config.tenantId* | `dagger.#Secret` |AZURE tenant id | -|*ctr.image.config.subscriptionId* | `dagger.#Secret` |AZURE subscription id | -|*ctr.image.config.appId* | `dagger.#Secret` |AZURE app id for the service principal used | -|*ctr.image.config.password* | `dagger.#Secret` |AZURE password for the service principal used | +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*config.tenantId* | `dagger.#Secret` |AZURE tenant id | +|*config.subscriptionId* | `dagger.#Secret` |AZURE subscription id | +|*config.appId* | `dagger.#Secret` |AZURE app id for the service principal used | +|*config.password* | `dagger.#Secret` |AZURE password for the service principal used | +|*rgName* | `string` |ResourceGroup name | +|*rgLocation* | `string` |ResourceGroup location | +|*ctr.image.config.tenantId* | `dagger.#Secret` |AZURE tenant id | +|*ctr.image.config.subscriptionId* | `dagger.#Secret` |AZURE subscription id | +|*ctr.image.config.appId* | `dagger.#Secret` |AZURE app id for the service principal used | +|*ctr.image.config.password* | `dagger.#Secret` |AZURE password for the service principal used | +|*ctr.image.image.from* | `"mcr.microsoft.com/azure-cli"` |Remote ref (example: "index.docker.io/alpine:latest") | ### resourcegroup.#ResourceGroup Outputs diff --git a/stdlib/.dagger/env/azure-resourcegroup/.gitignore b/stdlib/.dagger/env/azure-resourcegroup/.gitignore new file mode 100644 index 00000000..01ec19b0 --- /dev/null +++ b/stdlib/.dagger/env/azure-resourcegroup/.gitignore @@ -0,0 +1,2 @@ +# dagger state +state/** diff --git a/stdlib/.dagger/env/azure-resourcegroup/cue.mod/module.cue b/stdlib/.dagger/env/azure-resourcegroup/cue.mod/module.cue deleted file mode 100644 index f8af9cef..00000000 --- a/stdlib/.dagger/env/azure-resourcegroup/cue.mod/module.cue +++ /dev/null @@ -1 +0,0 @@ -module: "" diff --git a/stdlib/.dagger/env/azure-resourcegroup/cue.mod/pkg/.gitignore b/stdlib/.dagger/env/azure-resourcegroup/cue.mod/pkg/.gitignore deleted file mode 100644 index a572e9ee..00000000 --- a/stdlib/.dagger/env/azure-resourcegroup/cue.mod/pkg/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# dagger universe -alpha.dagger.io diff --git a/stdlib/.dagger/env/azure-resourcegroup/rg.cue b/stdlib/.dagger/env/azure-resourcegroup/rg.cue deleted file mode 100644 index 86b07df6..00000000 --- a/stdlib/.dagger/env/azure-resourcegroup/rg.cue +++ /dev/null @@ -1,17 +0,0 @@ -package rg - -import ( - "alpha.dagger.io/azure" - "alpha.dagger.io/azure/resourcegroup" - "alpha.dagger.io/random" -) - -suffix: random.#String & { - seed: "azrg" -} - -rg: resourcegroup.#ResourceGroup & { - config: azure.#Config - rgName: "rg-test-\(suffix.out)" - rgLocation: "eastus2" -} diff --git a/stdlib/.dagger/env/azure-resourcegroup/values.yaml b/stdlib/.dagger/env/azure-resourcegroup/values.yaml new file mode 100644 index 00000000..8edd915a --- /dev/null +++ b/stdlib/.dagger/env/azure-resourcegroup/values.yaml @@ -0,0 +1,23 @@ +plan: + package: ./azure/resourcegroup/tests +name: azure-resourcegroup +sops: + kms: [] + gcp_kms: [] + azure_kv: [] + hc_vault: [] + age: + - recipient: age1gxwmtwahzwdmrskhf90ppwlnze30lgpm056kuesrxzeuyclrwvpsupwtpk + enc: | + -----BEGIN AGE ENCRYPTED FILE----- + YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSAwcVNxbzdlRHczM3hoSlFB + OCtid2ZyNDZsMmRYeXRJM0hmY09rUWFjanpFClNjUnFXT09yb3BJMmJKNXN1MUIw + eTNIcmZKTG5YR0h6a0UxL0lIeFRBQkEKLS0tIHk4TFRYZkdmVGFWM3lWQ0pwcmx1 + TWlwSE9KTFlod21qbm5jQUdsZXVTT3cK7HMCg+rmRPy3d+uihLMPg7SvxVI7Xyr5 + Jv6BZJovEyX8PaB/dozzCwGMsGB4fALG2TRNbgskjR0LTGUgzv+yhQ== + -----END AGE ENCRYPTED FILE----- + lastmodified: "2021-08-11T13:13:45Z" + mac: ENC[AES256_GCM,data:lldSGzZoJV4V56chs0Iue+gCBqvwViRY4ZeY4MajyeNBTH6i/k3YXGEZ1lI4suXLyf4BABILMQz0Y34G9oPk8cBWgPx4ZP0iCpvVa/H06xVkBVfntym7p/GWkNsOGiU3KpdGwD/0LLdjDOmL3vKbxNrpS7RvvTgQQtI4+jXtKEc=,iv:vB6P7SPT77ZOEAjTyOO6oSWRWUUWTrC4ekgT5kXvofQ=,tag:ucfzyP9V6HIfIlI8pMDROg==,type:str] + pgp: [] + encrypted_suffix: secret + version: 3.7.1 diff --git a/stdlib/azure/azure.cue b/stdlib/azure/azure.cue index 23429454..e7cffd71 100644 --- a/stdlib/azure/azure.cue +++ b/stdlib/azure/azure.cue @@ -3,7 +3,8 @@ package azure import ( "alpha.dagger.io/dagger" - "alpha.dagger.io/dagger/op" + "alpha.dagger.io/docker" + "alpha.dagger.io/os" ) //Azure Config shared by all Azure packages @@ -23,22 +24,21 @@ import ( // Azure Config config: #Config - #up: [ - op.#FetchContainer & { - ref: "mcr.microsoft.com/azure-cli" - }, + // Container image + os.#Container & { + image: docker.#Pull & { + from: "mcr.microsoft.com/azure-cli" + } + always: true - op.#Exec & { - args: ["sh", "-c", - #""" - az login --service-principal -u "$(cat /run/secrets/appId)" -p "$(cat /run/secrets/password)" -t "$(cat /run/secrets/tenantId)" - az account set -s "$(cat /run/secrets/subscriptionId)" - """#, - ] - mount: "/run/secrets/appId": secret: config.appId - mount: "/run/secrets/password": secret: config.password - mount: "/run/secrets/tenantId": secret: config.tenantId - mount: "/run/secrets/subscriptionId": secret: config.subscriptionId - }, - ] + command: """ + az login --service-principal -u "$(cat /run/secrets/appId)" -p "$(cat /run/secrets/password)" -t "$(cat /run/secrets/tenantId)" + 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 + } } diff --git a/stdlib/azure/resourcegroup/rg.cue b/stdlib/azure/resourcegroup/rg.cue index 26a3ae96..0099ca6a 100644 --- a/stdlib/azure/resourcegroup/rg.cue +++ b/stdlib/azure/resourcegroup/rg.cue @@ -1,8 +1,8 @@ package resourcegroup import ( - "alpha.dagger.io/os" "alpha.dagger.io/azure" + "alpha.dagger.io/os" ) // Create a resource group @@ -21,9 +21,6 @@ import ( image: azure.#CLI & { "config": config } - // Path of the shell to execute - shell: path: "/bin/bash" - always: true command: """ diff --git a/stdlib/universe.bats b/stdlib/universe.bats index 54de3063..02760c06 100644 --- a/stdlib/universe.bats +++ b/stdlib/universe.bats @@ -185,6 +185,7 @@ setup() { assert_success } -# @test "azure-resourcegroup" { -# dagger -e azure-resourcegroup up -# } \ No newline at end of file +@test "azure-resourcegroup" { + skip "Azure CI infra not implemented yet - manually tested and working" + #dagger -e azure-resourcegroup up +} \ No newline at end of file From d74753bca71c1e0796696fb2dd83869d71cbf7da Mon Sep 17 00:00:00 2001 From: Sujay Pillai Date: Thu, 12 Aug 2021 01:37:17 +0800 Subject: [PATCH 3/5] Amending changes from @TomChv Signed-off-by: Sujay Pillai --- stdlib/azure/azure.cue | 29 ++++++++++++++++--------- stdlib/azure/resourcegroup/rg.cue | 21 +++++++++++++----- stdlib/azure/resourcegroup/tests/rg.cue | 6 ++--- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/stdlib/azure/azure.cue b/stdlib/azure/azure.cue index e7cffd71..53948ffd 100644 --- a/stdlib/azure/azure.cue +++ b/stdlib/azure/azure.cue @@ -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,21 +27,27 @@ 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: """ az login --service-principal -u "$(cat /run/secrets/appId)" -p "$(cat /run/secrets/password)" -t "$(cat /run/secrets/tenantId)" 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 + } } } diff --git a/stdlib/azure/resourcegroup/rg.cue b/stdlib/azure/resourcegroup/rg.cue index 0099ca6a..b2645b0b 100644 --- a/stdlib/azure/resourcegroup/rg.cue +++ b/stdlib/azure/resourcegroup/rg.cue @@ -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 } diff --git a/stdlib/azure/resourcegroup/tests/rg.cue b/stdlib/azure/resourcegroup/tests/rg.cue index ac5aaca8..dc2eda0b 100644 --- a/stdlib/azure/resourcegroup/tests/rg.cue +++ b/stdlib/azure/resourcegroup/tests/rg.cue @@ -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" } From a99fc52eeb4f4cca57baa932584b7182e03f2462 Mon Sep 17 00:00:00 2001 From: Sujay Pillai Date: Thu, 12 Aug 2021 01:44:03 +0800 Subject: [PATCH 4/5] Amending changes from @TomChv Signed-off-by: Sujay Pillai --- stdlib/azure/azure.cue | 4 ++-- stdlib/azure/resourcegroup/rg.cue | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/stdlib/azure/azure.cue b/stdlib/azure/azure.cue index 53948ffd..b98bef5d 100644 --- a/stdlib/azure/azure.cue +++ b/stdlib/azure/azure.cue @@ -35,14 +35,14 @@ let defaultVersion = "2.27.1@sha256:1e117183100c9fce099ebdc189d73e506e7b02d2b73d image: docker.#Pull & { from: "mcr.microsoft.com/azure-cli:\(version)" } - + always: true command: """ az login --service-principal -u "$(cat /run/secrets/appId)" -p "$(cat /run/secrets/password)" -t "$(cat /run/secrets/tenantId)" az account set -s "$(cat /run/secrets/subscriptionId)" """ - + secret: { "/run/secrets/appId": config.appId "/run/secrets/password": config.password diff --git a/stdlib/azure/resourcegroup/rg.cue b/stdlib/azure/resourcegroup/rg.cue index b2645b0b..5f2e7215 100644 --- a/stdlib/azure/resourcegroup/rg.cue +++ b/stdlib/azure/resourcegroup/rg.cue @@ -33,7 +33,7 @@ import ( """ env: { - AZURE_DEFAULTS_GROUP: rgName + AZURE_DEFAULTS_GROUP: rgName AZURE_DEFAULTS_LOCATION: rgLocation } } @@ -41,8 +41,8 @@ import ( // Resource Id id: ({ os.#File & { - from: ctr - path: "/resourceGroupId" - } + from: ctr + path: "/resourceGroupId" + } }).contents } From f979135961586b38a9d8f1d768de249297bd3731 Mon Sep 17 00:00:00 2001 From: Sujay Pillai Date: Thu, 12 Aug 2021 01:51:41 +0800 Subject: [PATCH 5/5] Amending changes from @TomChv Signed-off-by: Sujay Pillai --- docs/reference/universe/azure/README.md | 18 +++++---- .../reference/universe/azure/resourcegroup.md | 38 +++++++++++-------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/docs/reference/universe/azure/README.md b/docs/reference/universe/azure/README.md index 1f2e288d..fc887bbb 100644 --- a/docs/reference/universe/azure/README.md +++ b/docs/reference/universe/azure/README.md @@ -16,13 +16,17 @@ Azure Cli to be used by all Azure packages ### azure.#CLI Inputs -| Name | Type | Description | -| ------------- |:-------------: |:-------------: | -|*config.tenantId* | `dagger.#Secret` |AZURE tenant id | -|*config.subscriptionId* | `dagger.#Secret` |AZURE subscription id | -|*config.appId* | `dagger.#Secret` |AZURE app id for the service principal used | -|*config.password* | `dagger.#Secret` |AZURE password for the service principal used | -|*image.from* | `"mcr.microsoft.com/azure-cli"` |Remote ref (example: "index.docker.io/alpine:latest") | +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*config.tenantId* | `dagger.#Secret` |AZURE tenant id | +|*config.subscriptionId* | `dagger.#Secret` |AZURE subscription id | +|*config.appId* | `dagger.#Secret` |AZURE app id for the service principal used | +|*config.password* | `dagger.#Secret` |AZURE password for the service principal used | +|*image.from* | `"mcr.microsoft.com/azure-cli:2.27.1@sha256:1e117183100c9fce099ebdc189d73e506e7b02d2b73d767d3fc07caee72f9fb1"` |Remote ref (example: "index.docker.io/alpine:latest") | +|*secret."/run/secrets/appId"* | `dagger.#Secret` |- | +|*secret."/run/secrets/password"* | `dagger.#Secret` |- | +|*secret."/run/secrets/tenantId"* | `dagger.#Secret` |- | +|*secret."/run/secrets/subscriptionId"* | `dagger.#Secret` |- | ### azure.#CLI Outputs diff --git a/docs/reference/universe/azure/resourcegroup.md b/docs/reference/universe/azure/resourcegroup.md index 9de772be..d23a64c5 100644 --- a/docs/reference/universe/azure/resourcegroup.md +++ b/docs/reference/universe/azure/resourcegroup.md @@ -14,22 +14,28 @@ Create a resource group ### resourcegroup.#ResourceGroup Inputs -| Name | Type | Description | -| ------------- |:-------------: |:-------------: | -|*config.tenantId* | `dagger.#Secret` |AZURE tenant id | -|*config.subscriptionId* | `dagger.#Secret` |AZURE subscription id | -|*config.appId* | `dagger.#Secret` |AZURE app id for the service principal used | -|*config.password* | `dagger.#Secret` |AZURE password for the service principal used | -|*rgName* | `string` |ResourceGroup name | -|*rgLocation* | `string` |ResourceGroup location | -|*ctr.image.config.tenantId* | `dagger.#Secret` |AZURE tenant id | -|*ctr.image.config.subscriptionId* | `dagger.#Secret` |AZURE subscription id | -|*ctr.image.config.appId* | `dagger.#Secret` |AZURE app id for the service principal used | -|*ctr.image.config.password* | `dagger.#Secret` |AZURE password for the service principal used | -|*ctr.image.image.from* | `"mcr.microsoft.com/azure-cli"` |Remote ref (example: "index.docker.io/alpine:latest") | +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*config.tenantId* | `dagger.#Secret` |AZURE tenant id | +|*config.subscriptionId* | `dagger.#Secret` |AZURE subscription id | +|*config.appId* | `dagger.#Secret` |AZURE app id for the service principal used | +|*config.password* | `dagger.#Secret` |AZURE password for the service principal used | +|*rgName* | `string` |ResourceGroup name | +|*rgLocation* | `string` |ResourceGroup location | +|*ctr.image.config.tenantId* | `dagger.#Secret` |AZURE tenant id | +|*ctr.image.config.subscriptionId* | `dagger.#Secret` |AZURE subscription id | +|*ctr.image.config.appId* | `dagger.#Secret` |AZURE app id for the service principal used | +|*ctr.image.config.password* | `dagger.#Secret` |AZURE password for the service principal used | +|*ctr.image.image.from* | `"mcr.microsoft.com/azure-cli:2.27.1@sha256:1e117183100c9fce099ebdc189d73e506e7b02d2b73d767d3fc07caee72f9fb1"` |Remote ref (example: "index.docker.io/alpine:latest") | +|*ctr.image.secret."/run/secrets/appId"* | `dagger.#Secret` |- | +|*ctr.image.secret."/run/secrets/password"* | `dagger.#Secret` |- | +|*ctr.image.secret."/run/secrets/tenantId"* | `dagger.#Secret` |- | +|*ctr.image.secret."/run/secrets/subscriptionId"* | `dagger.#Secret` |- | +|*ctr.env.AZURE_DEFAULTS_GROUP* | `string` |- | +|*ctr.env.AZURE_DEFAULTS_LOCATION* | `string` |- | ### resourcegroup.#ResourceGroup Outputs -| Name | Type | Description | -| ------------- |:-------------: |:-------------: | -|*id* | `string` |Resource Id | +| Name | Type | Description | +| ------------- |:-------------: |:-------------: | +|*id* | `string` |ResourceGroup Id Resource Id |