From 5908aa628eaebbd078b4ef159031d5e1214dc86f Mon Sep 17 00:00:00 2001 From: Sujay Pillai Date: Wed, 11 Aug 2021 01:20:16 +0800 Subject: [PATCH] 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