Skip to content

Commit

Permalink
Tests and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
fraliv13 committed Feb 12, 2024
1 parent d50338a commit 7b6603e
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,54 @@ spec:
workspaceFriendlyName: Charisma
```

### AzurePowershellScript
`AzurePowershellScript` is a Custom Resource Definition (CRD) that represents an Azure PowerShell deployment script.

Definition can be found [here](./helm/crds/provisioning.totalsoft.ro_azurepowershellscripts.yaml)

#### Spec
The `AzurePowershellScript` spec has the following fields:

- `scriptContent`: The content of the PowerShell script to be executed.
- `scriptArguments`: The arguments to be passed to the PowerShell script. These should match the parameters defined in the scriptContent.
- `managedIdentity`: The Azure Resource Manager (ARM) identifier of the managed identity used to run the script.
- `domainRef`: The reference to the domain that the user belongs to.
- `platformRef`: The reference to the platform that the user belongs to.
- `forceUpdateTag`: Update this value to trigger the script even if the content or args are unchanged

Example:
```yaml
apiVersion: provisioning.totalsoft.ro/v1alpha1
kind: AzurePowerShellScript
metadata:
name: createresourcegroup
namespace: provisioning-test
spec:
domainRef: domain2
exports:
- scriptOutputs:
toConfigMap:
keyTemplate: MultiTenancy__Tenants__{{ .Tenant.Code }}__ScriptOutputs
managedIdentity: >-
/subscriptions/15b38e46-ef41-4f5b-bdba-7d9354568c2d/resourceGroups/global/providers/Microsoft.ManagedIdentity/userAssignedIdentities/scriptidentity
platformRef: provisioning.test
scriptContent: |-
param([string] $name)
$output = "RG name: {0}" -f $name
Write-Output $output
$DeploymentScriptOutputs = @{}
$DeploymentScriptOutputs['text'] = $output
New-AzResourceGroup $name "West Europe"
scriptArguments: "-name testrg-{{ .Platform }}-{{ .Tenant.Code }}"
target:
category: Tenant
```



### EntraUser

`EntraUser` is a Custom Resource Definition (CRD) that represents a user for Entra Id.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package pulumi

import (
"testing"

"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
provisioningv1 "totalsoft.ro/platform-controllers/pkg/apis/provisioning/v1alpha1"
)

func TestDeployAzurePowerShellScript(t *testing.T) {
t.Run("maximal entra user spec", func(t *testing.T) {
platform := "dev"
tenant := newTenant("tenant1", platform)
script := &provisioningv1.AzurePowerShellScript{
ObjectMeta: metav1.ObjectMeta{
Name: "my-pwsh-script",
},
Spec: provisioningv1.AzurePowerShellScriptSpec{
ScriptContent: "Write-Host 'Hello, World!'",
ManagedIdentity: "my-managed-identity",
ProvisioningMeta: provisioningv1.ProvisioningMeta{
DomainRef: "example-domain",
},
},
}

err := pulumi.RunErr(func(ctx *pulumi.Context) error {
script, err := deployAzurePowerShellScript(tenant, pulumi.String("rg").ToStringOutput(), script, []pulumi.Resource{}, ctx)
assert.NoError(t, err)
assert.NotNil(t, script)
return nil

}, pulumi.WithMocks("project", "stack", mocks(0)))
assert.NoError(t, err)
})
}

0 comments on commit 7b6603e

Please sign in to comment.