Skip to content

Commit e93ca20

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

File tree

5 files changed

+69
-1
lines changed

5 files changed

+69
-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: 49 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,33 @@ 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+
secrets: {
38+
tenant_id: {
39+
source: secretstore.id
40+
key: 'tenantID'
41+
}
42+
}
43+
} ]
44+
}
45+
}
46+
env: {
47+
ARM_USE_AKS_WORKLOAD_IDENTITY: 'true'
48+
ARM_USE_CLI: 'false'
49+
}
50+
envSecrets: {
51+
ARM_CLIENT_ID: {
52+
source: secretstore.id
53+
key: 'clientID'
54+
}
55+
}
56+
}
2457
recipes: {
2558
'Applications.Core/extenders': {
2659
default: {
@@ -56,3 +89,19 @@ resource webapp 'Applications.Core/extenders@2023-10-01-preview' = {
5689
environment: env.id
5790
}
5891
}
92+
93+
resource secretstore 'Applications.Core/secretStores@2023-10-01-preview' = {
94+
name: 'corerp-resources-terraform-azrg-secretstore'
95+
properties: {
96+
resource: 'corerp-resources-terraform-azrg/secretstore'
97+
type: 'generic'
98+
data: {
99+
tenantID: {
100+
value: tenantID
101+
}
102+
clientID: {
103+
value: clientID
104+
}
105+
}
106+
}
107+
}

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

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

11+
provider "azurerm" {
12+
features {}
13+
}
14+
1015
resource "azurerm_resource_group" "test_rg" {
1116
name = var.name
1217
location = var.location

0 commit comments

Comments
 (0)