Skip to content

Commit 3a49b5b

Browse files
committed
Add custom Azure provider configuration for Terraform Azure test
Signed-off-by: Karishma Chawla <[email protected]>
1 parent ace1b99 commit 3a49b5b

File tree

5 files changed

+68
-1
lines changed

5 files changed

+68
-1
lines changed

.github/workflows/functional-test-cloud.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,8 @@ jobs:
784784
BICEP_RECIPE_TAG_VERSION: ${{ env.BICEP_RECIPE_TAG_VERSION }}
785785
GH_TOKEN: ${{ steps.get_installation_token.outputs.token }}
786786
GOTESTSUM_OPTS: "--junitfile ./dist/functional_test/results.xml"
787+
AZURE_CLIENT_ID: ${{ secrets.AZURE_SP_TESTS_APPID }}
788+
AZURE_TENANT_ID: ${{ secrets.AZURE_SP_TESTS_TENANTID }}
787789

788790
- name: Process Functional Test Results
789791
uses: ./.github/actions/process-test-results

pkg/recipes/terraform/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ func (cfg *TerraformConfig) Save(ctx context.Context, workingDir string) error {
9595
return fmt.Errorf("error marshalling JSON: %w", err)
9696
}
9797

98+
// Log the generated JSON for temporary debugging
99+
logger.Info("Generated Terraform JSON config:")
100+
logger.Info(buf.String()) // Log the JSON content
101+
98102
logger.Info(fmt.Sprintf("Writing Terraform JSON config to file: %s", getMainConfigFilePath(workingDir)))
99103
if err := os.WriteFile(getMainConfigFilePath(workingDir), buf.Bytes(), modeConfigFile); err != nil {
100104
return fmt.Errorf("error creating file: %w", err)

test/functional-portable/corerp/cloud/resources/recipe_terraform_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,17 @@ func Test_TerraformRecipe_AzureResourceGroup(t *testing.T) {
5050
appName := "corerp-resources-terraform-azrg-app"
5151
envName := "corerp-resources-terraform-azrg-env"
5252

53+
// if os.Getenv("AZURE_CLIENT_ID") == "" || os.Getenv("AZURE_TENANT_ID") == "" {
54+
// t.Error("AZURE_CLIENT_ID and AZURE_TENANT_ID environment variables must be set to run this test.")
55+
// }
56+
// clientID := os.Getenv("AZURE_CLIENT_ID")
57+
// tenantID := os.Getenv("AZURE_TENANT_ID")
58+
clientID := "03b9a63f-18de-4256-b063-a6b722ac80fc"
59+
tenantID := "72f988bf-86f1-41af-91ab-2d7cd011db47"
60+
5361
test := rp.NewRPTest(t, name, []rp.TestStep{
5462
{
55-
Executor: step.NewDeployExecutor(template, testutil.GetTerraformRecipeModuleServerURL(), "appName="+appName),
63+
Executor: step.NewDeployExecutor(template, testutil.GetTerraformRecipeModuleServerURL(), "appName="+appName, "clientID="+clientID, "tenantID="+tenantID),
5664
RPResources: &validation.RPResourceSet{
5765
Resources: []validation.RPResource{
5866
{

test/functional-portable/corerp/cloud/resources/testdata/corerp-resources-terraform-azurerg.bicep

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ param moduleServer string
88
@description('Name of the Radius Application.')
99
param appName string
1010

11+
@description('Client ID for Azure.')
12+
param clientID string
13+
14+
@description('Tenant ID for Azure.')
15+
param tenantID string
16+
1117
resource env 'Applications.Core/environments@2023-10-01-preview' = {
1218
name: 'corerp-resources-terraform-azrg-env'
1319
properties: {
@@ -21,6 +27,35 @@ resource env 'Applications.Core/environments@2023-10-01-preview' = {
2127
scope: resourceGroup().id
2228
}
2329
}
30+
recipeConfig: {
31+
terraform: {
32+
providers: {
33+
azurerm: [ {
34+
alias: 'azure-test'
35+
features: {}
36+
subscription_id: subscription().subscriptionId
37+
use_oidc: true
38+
oidc_token_file_path: '/var/run/secrets/azure/tokens/azure-identity-token'
39+
use_azure_cli: false
40+
secrets: {
41+
tenant_id: {
42+
source: secretstore.id
43+
key: 'tenantID'
44+
}
45+
}
46+
} ]
47+
}
48+
}
49+
// env: {
50+
// ARM_USE_AKS_WORKLOAD_IDENTITY: 'true'
51+
// }
52+
envSecrets: {
53+
ARM_CLIENT_ID: {
54+
source: secretstore.id
55+
key: 'clientID'
56+
}
57+
}
58+
}
2459
recipes: {
2560
'Applications.Core/extenders': {
2661
default: {
@@ -56,3 +91,19 @@ resource webapp 'Applications.Core/extenders@2023-10-01-preview' = {
5691
environment: env.id
5792
}
5893
}
94+
95+
resource secretstore 'Applications.Core/secretStores@2023-10-01-preview' = {
96+
name: 'corerp-resources-terraform-azrg-secretstore'
97+
properties: {
98+
resource: 'corerp-resources-terraform-azrg/secretstore'
99+
type: 'generic'
100+
data: {
101+
tenantID: {
102+
value: tenantID
103+
}
104+
clientID: {
105+
value: clientID
106+
}
107+
}
108+
}
109+
}

test/testrecipes/test-terraform-recipes/azure-rg/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ terraform {
33
azurerm = {
44
source = "hashicorp/azurerm"
55
version = "~> 3.114.0"
6+
configuration_aliases = [azurerm.azure-test]
67
}
78
}
89
}
910

1011
resource "azurerm_resource_group" "test_rg" {
12+
provider = azurerm.azure-test
1113
name = var.name
1214
location = var.location
1315
}

0 commit comments

Comments
 (0)