From 64538c20843e8a0ef5069cc9d5ae9e4ac610a79b Mon Sep 17 00:00:00 2001 From: vinayada1 <28875764+vinayada1@users.noreply.github.com> Date: Thu, 26 Oct 2023 13:43:25 -0700 Subject: [PATCH] Separate cloud/non-cloud tests --- .github/workflows/build.yaml | 231 ++++++++++++++++++ .github/workflows/functional-test.yaml | 8 +- build/test.mk | 9 + test/functional-cloud/README.md | 3 + .../resources/microsoftsql_test.go | 0 ...datastoresrp-resources-microsoft-sql.bicep | 0 .../shared/mechanics/aws_mechanics_test.go | 0 ...thcreateandwritepropertyupdate.step1.bicep | 0 ...thcreateandwritepropertyupdate.step2.bicep | 0 ...s-redeploy-withupdatedresource.step1.bicep | 0 ...s-redeploy-withupdatedresource.step2.bicep | 0 .../aws_multi_identifier_resource_test.go | 0 .../shared/resources/aws_s3_bucket_test.go | 0 .../resources/azure_connections_test.go | 0 .../shared/resources/extender_test.go | 105 ++++++++ .../resources/persistent_volume_test.go | 0 .../shared/resources/recipe_terraform_test.go | 134 ++++++++++ .../shared/resources/storage_test.go | 0 .../testdata/aws-multi-identifier.bicep | 0 .../testdata/aws-s3-bucket-existing.bicep | 0 .../resources/testdata/aws-s3-bucket.bicep | 0 ...rp-azure-connection-database-service.bicep | 31 +++ ...erp-resources-extender-aws-s3-recipe.bicep | 0 ...erp-resources-terraform-azurestorage.bicep | 0 ...rerp-resources-volume-azure-keyvault.bicep | 0 .../parameters/test-tls-cert.parameters.json | 12 + .../recipes/test-bicep-recipes/README.md | 11 + .../extenders-aws-s3-recipe.bicep | 0 .../recipes/test-terraform-recipes/README.md | 41 ++++ .../azure-storage/main.tf | 0 .../azure-storage/output.tf | 0 .../azure-storage/variables.tf | 0 .../ucp/aws_credential_test.go | 11 +- .../ucp/aws_test.go | 5 +- .../ucp/azure_credential_test.go | 11 +- .../shared/resources/extender_test.go | 79 ------ .../shared/resources/recipe_terraform_test.go | 50 ---- 37 files changed, 596 insertions(+), 145 deletions(-) create mode 100644 test/functional-cloud/README.md rename test/{functional => functional-cloud}/datastoresrp/resources/microsoftsql_test.go (100%) rename test/{functional => functional-cloud}/datastoresrp/resources/testdata/datastoresrp-resources-microsoft-sql.bicep (100%) rename test/{functional => functional-cloud}/shared/mechanics/aws_mechanics_test.go (100%) rename test/{functional => functional-cloud}/shared/mechanics/testdata/aws-mechanics-redeploy-withcreateandwritepropertyupdate.step1.bicep (100%) rename test/{functional => functional-cloud}/shared/mechanics/testdata/aws-mechanics-redeploy-withcreateandwritepropertyupdate.step2.bicep (100%) rename test/{functional => functional-cloud}/shared/mechanics/testdata/aws-mechanics-redeploy-withupdatedresource.step1.bicep (100%) rename test/{functional => functional-cloud}/shared/mechanics/testdata/aws-mechanics-redeploy-withupdatedresource.step2.bicep (100%) rename test/{functional => functional-cloud}/shared/resources/aws_multi_identifier_resource_test.go (100%) rename test/{functional => functional-cloud}/shared/resources/aws_s3_bucket_test.go (100%) rename test/{functional => functional-cloud}/shared/resources/azure_connections_test.go (100%) create mode 100644 test/functional-cloud/shared/resources/extender_test.go rename test/{functional => functional-cloud}/shared/resources/persistent_volume_test.go (100%) create mode 100644 test/functional-cloud/shared/resources/recipe_terraform_test.go rename test/{functional => functional-cloud}/shared/resources/storage_test.go (100%) rename test/{functional => functional-cloud}/shared/resources/testdata/aws-multi-identifier.bicep (100%) rename test/{functional => functional-cloud}/shared/resources/testdata/aws-s3-bucket-existing.bicep (100%) rename test/{functional => functional-cloud}/shared/resources/testdata/aws-s3-bucket.bicep (100%) create mode 100644 test/functional-cloud/shared/resources/testdata/corerp-azure-connection-database-service.bicep rename test/{functional => functional-cloud}/shared/resources/testdata/corerp-resources-extender-aws-s3-recipe.bicep (100%) rename test/{functional => functional-cloud}/shared/resources/testdata/corerp-resources-terraform-azurestorage.bicep (100%) rename test/{functional => functional-cloud}/shared/resources/testdata/corerp-resources-volume-azure-keyvault.bicep (100%) create mode 100644 test/functional-cloud/shared/resources/testdata/parameters/test-tls-cert.parameters.json create mode 100644 test/functional-cloud/shared/resources/testdata/recipes/test-bicep-recipes/README.md rename test/{functional => functional-cloud}/shared/resources/testdata/recipes/test-bicep-recipes/extenders-aws-s3-recipe.bicep (100%) create mode 100644 test/functional-cloud/shared/resources/testdata/recipes/test-terraform-recipes/README.md rename test/{functional => functional-cloud}/shared/resources/testdata/recipes/test-terraform-recipes/azure-storage/main.tf (100%) rename test/{functional => functional-cloud}/shared/resources/testdata/recipes/test-terraform-recipes/azure-storage/output.tf (100%) rename test/{functional => functional-cloud}/shared/resources/testdata/recipes/test-terraform-recipes/azure-storage/variables.tf (100%) rename test/{functional => functional-cloud}/ucp/aws_credential_test.go (92%) rename test/{functional => functional-cloud}/ucp/aws_test.go (95%) rename test/{functional => functional-cloud}/ucp/azure_credential_test.go (93%) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 0b7043f71b1..a8aea6d5878 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -55,6 +55,15 @@ env: # URL to get source code for building the image IMAGE_SRC: https://github.com/radius-project/radius + # KinD cluster version + KIND_VER: 'v0.20.0' + + # Dapr version + DAPR_VER: '1.11.0' + + # Kubectl version + KUBECTL_VER: 'v1.25.0' + jobs: build-and-push-cli: name: Build ${{ matrix.target_os }}_${{ matrix.target_arch }} binaries @@ -221,7 +230,229 @@ jobs: if: github.ref == 'refs/heads/main' && matrix.target_os == 'windows' run: | oras push ${{ env.CONTAINER_REGISTRY }}/rad/${{ matrix.target_os }}-${{ matrix.target_arch }}:latest ./dist/${{ matrix.target_os}}_${{ matrix.target_arch}}/release/rad.exe --annotation "org.opencontainers.image.source=${{ env.IMAGE_SRC }}" + tests: + name: Run ${{ matrix.name }} functional tests that do not require cloud resources + needs: build-and-push-cli + strategy: + fail-fast: true + matrix: + os: [ubuntu-latest] + name: [ucp,kubernetes,shared,msgrp,daprrp,samples] + include: + # datastorerp functional tests need the larger VM. + - os: ubuntu-latest-m + name: datastoresrp + runs-on: ${{ matrix.os }} + env: + UNIQUE_ID: ${{ needs.build.outputs.UNIQUE_ID }} + REL_VERSION: ${{ needs.build.outputs.REL_VERSION }} + CHECKOUT_REPO: ${{ needs.build.outputs.CHECKOUT_REPO }} + CHECKOUT_REF: ${{ needs.build.outputs.CHECKOUT_REF }} + PR_NUMBER: ${{ needs.build.outputs.PR_NUMBER }} + AZURE_TEST_RESOURCE_GROUP: radtest-${{ needs.build.outputs.UNIQUE_ID }}-${{ matrix.name }} + RAD_CLI_ARTIFACT_NAME: ${{ needs.build.outputs.RAD_CLI_ARTIFACT_NAME }} + BICEP_RECIPE_TAG_VERSION: ${{ needs.build.outputs.REL_VERSION }} + DE_IMAGE: ${{ needs.build.outputs.DE_IMAGE }} + DE_TAG: ${{ needs.build.outputs.DE_TAG }} + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + repository: ${{ env.CHECKOUT_REPO }} + ref: ${{ env.CHECKOUT_REF }} + - name: Checkout samples repo + uses: actions/checkout@v3 + if: matrix.name == 'samples' + with: + repository: radius-project/samples + ref: refs/heads/edge + token: ${{ secrets.GH_RAD_CI_BOT_PAT }} + path: samples + - name: Set up Go ${{ env.GOVER }} + uses: actions/setup-go@v3 + with: + go-version: ${{ env.GOVER }} + - name: Get Go Cache path + id: go-cache-paths + run: | + echo "go-build=$(go env GOCACHE)" >> $GITHUB_OUTPUT + echo "go-mod=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT + - uses: actions/cache@v3 + with: + path: | + ${{ steps.go-cache-paths.outputs.go-build }} + ${{ steps.go-cache-paths.outputs.go-mod }} + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: Download rad CLI + uses: actions/download-artifact@v3 + with: + name: ${{ env.RAD_CLI_ARTIFACT_NAME }} + path: bin + - name: Login to Azure + uses: azure/login@v1 + with: + creds: '{"clientId":"${{ secrets.INTEGRATION_TEST_SP_APP_ID }}","clientSecret":"${{ secrets.INTEGRATION_TEST_SP_PASSWORD }}","subscriptionId":"${{ secrets.INTEGRATION_TEST_SUBSCRIPTION_ID }}","tenantId":"${{ secrets.INTEGRATION_TEST_TENANT_ID }}"}' + - uses: marocchino/sticky-pull-request-comment@v2 + continue-on-error: true + with: + header: teststatus-${{ github.run_id }} + number: ${{ env.PR_NUMBER }} + append: true + message: | + :hourglass: Starting ${{ matrix.name }} functional tests... + - name: Create KinD cluster + run: | + curl -sSLo "kind" "https://github.com/kubernetes-sigs/kind/releases/download/${{ env.KIND_VER }}/kind-linux-amd64" + chmod +x ./kind + + # Populate the following environment variables for Azure workload identity from secrets. + # AZURE_OIDC_ISSUER_PUBLIC_KEY + # AZURE_OIDC_ISSUER_PRIVATE_KEY + # AZURE_OIDC_ISSUER + eval "export $(echo "${{ secrets.FUNCTEST_AZURE_OIDC_JSON }}" | jq -r 'to_entries | map("\(.key)=\(.value)") | @sh')" + AUTHKEY=$(echo -n "${{ github.actor }}:${{ secrets.GH_RAD_CI_BOT_PAT }}" | base64) + echo "{\"auths\":{\"ghcr.io\":{\"auth\":\"${AUTHKEY}\"}}}" > "./ghcr_secret.json" + + # Create KinD cluster with OIDC Issuer keys + echo $AZURE_OIDC_ISSUER_PUBLIC_KEY | base64 -d > sa.pub + echo $AZURE_OIDC_ISSUER_PRIVATE_KEY | base64 -d > sa.key + cat <> $POD_STATE_LOG_FILENAME + kubectl get pods -A >> $POD_STATE_LOG_FILENAME + echo "kubectl describe pods -A" >> $POD_STATE_LOG_FILENAME + kubectl describe pods -A >> $POD_STATE_LOG_FILENAME + - name: Upload container logs + if: always() + uses: actions/upload-artifact@v3 + with: + name: ${{ matrix.name }}_container_logs + path: ./${{ env.RADIUS_CONTAINER_LOG_BASE }} + - uses: marocchino/sticky-pull-request-comment@v2 + if: success() && env.PR_NUMBER != '' + continue-on-error: true + with: + header: teststatus-${{ github.run_id }} + number: ${{ env.PR_NUMBER }} + append: true + message: | + :white_check_mark: ${{ matrix.name }} functional tests succeeded + - uses: marocchino/sticky-pull-request-comment@v2 + if: failure() && env.PR_NUMBER != '' + continue-on-error: true + with: + header: teststatus-${{ github.run_id }} + number: ${{ env.PR_NUMBER }} + append: true + message: | + :x: ${{ matrix.name }} functional test failed. Please check [the logs](${{ env.ACTION_LINK }}) for more details build-and-push-images: name: Build and publish container images runs-on: ubuntu-latest diff --git a/.github/workflows/functional-test.yaml b/.github/workflows/functional-test.yaml index 915020e564d..d870b443b97 100644 --- a/.github/workflows/functional-test.yaml +++ b/.github/workflows/functional-test.yaml @@ -277,13 +277,13 @@ jobs: message: | :x: Test recipe publishing failed tests: - name: Run ${{ matrix.name }} functional tests + name: Run ${{ matrix.name }} functional tests that require cloud resources needs: build strategy: fail-fast: true matrix: os: [ubuntu-latest] - name: [ucp,kubernetes,shared,msgrp,daprrp,samples] + name: [ucp,shared] include: # datastorerp functional tests need the larger VM. - os: ubuntu-latest-m @@ -482,7 +482,7 @@ jobs: - name: Publish Terraform test recipes run: | make publish-test-terraform-recipes - - name: Run functional tests + - name: Run functional tests that require cloud resources run: | # Ensure rad cli is in path before running tests. export PATH=$GITHUB_WORKSPACE/bin:$PATH @@ -501,7 +501,7 @@ jobs: # AZURE_MSSQL_PASSWORD eval "export $(echo "${{ secrets.FUNCTEST_PREPROVISIONED_RESOURCE_JSON }}" | jq -r 'to_entries | map("\(.key)=\(.value)") | @sh')" - make test-functional-${{ matrix.name }} + make test-functional-${{ matrix.name }}-cloud env: DOCKER_REGISTRY: ${{ env.CONTAINER_REGISTRY }} TEST_TIMEOUT: ${{ env.FUNCTIONALTEST_TIMEOUT }} diff --git a/build/test.mk b/build/test.mk index 53b23697e93..ff7e4e0bf2b 100644 --- a/build/test.mk +++ b/build/test.mk @@ -66,6 +66,9 @@ test-functional-kubernetes: ## Runs Kubernetes functional tests test-functional-shared: ## Runs shared functional tests CGO_ENABLED=1 $(GOTEST_TOOL) ./test/functional/shared/... -timeout ${TEST_TIMEOUT} -v -parallel 10 $(GOTEST_OPTS) +test-functional-shared-cloud: ## Runs shared functional tests that require cloud resources + CGO_ENABLED=1 $(GOTEST_TOOL) ./test/functional-cloud/shared/... -timeout ${TEST_TIMEOUT} -v -parallel 10 $(GOTEST_OPTS) + test-functional-msgrp: ## Runs Messaging RP functional tests CGO_ENABLED=1 $(GOTEST_TOOL) ./test/functional/messagingrp/... -timeout ${TEST_TIMEOUT} -v -parallel 2 $(GOTEST_OPTS) @@ -75,12 +78,18 @@ test-functional-daprrp: ## Runs Dapr RP functional tests test-functional-datastoresrp: ## Runs Datastores RP functional tests CGO_ENABLED=1 $(GOTEST_TOOL) ./test/functional/datastoresrp/... -timeout ${TEST_TIMEOUT} -v -parallel 3 $(GOTEST_OPTS) +test-functional-datastoresrp-cloud: ## Runs Datastores RP functional tests that require cloud resources + CGO_ENABLED=1 $(GOTEST_TOOL) ./test/functional-cloud/datastoresrp/... -timeout ${TEST_TIMEOUT} -v -parallel 3 $(GOTEST_OPTS) + test-functional-samples: ## Runs Samples functional tests CGO_ENABLED=1 $(GOTEST_TOOL) ./test/functional/samples/... -timeout ${TEST_TIMEOUT} -v -parallel 5 $(GOTEST_OPTS) test-functional-ucp: ## Runs UCP functional tests CGO_ENABLED=1 $(GOTEST_TOOL) ./test/functional/ucp/... -timeout ${TEST_TIMEOUT} -v -parallel 5 $(GOTEST_OPTS) +test-functional-ucp-cloud: ## Runs UCP functional tests that require cloud resources + CGO_ENABLED=1 $(GOTEST_TOOL) ./test/functional-cloud/ucp/... -timeout ${TEST_TIMEOUT} -v -parallel 5 $(GOTEST_OPTS) + test-validate-bicep: ## Validates that all .bicep files compile cleanly BICEP_PATH="${HOME}/.rad/bin/rad-bicep" ./build/validate-bicep.sh diff --git a/test/functional-cloud/README.md b/test/functional-cloud/README.md new file mode 100644 index 00000000000..dfc9c96b3ee --- /dev/null +++ b/test/functional-cloud/README.md @@ -0,0 +1,3 @@ +* [Writing functional tests](../../docs/contributing/contributing-code/contributing-code-tests/writing-functional-tests.md) + +* [Running functional tests](../../docs/contributing/contributing-code/contributing-code-tests/running-functional-tests.md) diff --git a/test/functional/datastoresrp/resources/microsoftsql_test.go b/test/functional-cloud/datastoresrp/resources/microsoftsql_test.go similarity index 100% rename from test/functional/datastoresrp/resources/microsoftsql_test.go rename to test/functional-cloud/datastoresrp/resources/microsoftsql_test.go diff --git a/test/functional/datastoresrp/resources/testdata/datastoresrp-resources-microsoft-sql.bicep b/test/functional-cloud/datastoresrp/resources/testdata/datastoresrp-resources-microsoft-sql.bicep similarity index 100% rename from test/functional/datastoresrp/resources/testdata/datastoresrp-resources-microsoft-sql.bicep rename to test/functional-cloud/datastoresrp/resources/testdata/datastoresrp-resources-microsoft-sql.bicep diff --git a/test/functional/shared/mechanics/aws_mechanics_test.go b/test/functional-cloud/shared/mechanics/aws_mechanics_test.go similarity index 100% rename from test/functional/shared/mechanics/aws_mechanics_test.go rename to test/functional-cloud/shared/mechanics/aws_mechanics_test.go diff --git a/test/functional/shared/mechanics/testdata/aws-mechanics-redeploy-withcreateandwritepropertyupdate.step1.bicep b/test/functional-cloud/shared/mechanics/testdata/aws-mechanics-redeploy-withcreateandwritepropertyupdate.step1.bicep similarity index 100% rename from test/functional/shared/mechanics/testdata/aws-mechanics-redeploy-withcreateandwritepropertyupdate.step1.bicep rename to test/functional-cloud/shared/mechanics/testdata/aws-mechanics-redeploy-withcreateandwritepropertyupdate.step1.bicep diff --git a/test/functional/shared/mechanics/testdata/aws-mechanics-redeploy-withcreateandwritepropertyupdate.step2.bicep b/test/functional-cloud/shared/mechanics/testdata/aws-mechanics-redeploy-withcreateandwritepropertyupdate.step2.bicep similarity index 100% rename from test/functional/shared/mechanics/testdata/aws-mechanics-redeploy-withcreateandwritepropertyupdate.step2.bicep rename to test/functional-cloud/shared/mechanics/testdata/aws-mechanics-redeploy-withcreateandwritepropertyupdate.step2.bicep diff --git a/test/functional/shared/mechanics/testdata/aws-mechanics-redeploy-withupdatedresource.step1.bicep b/test/functional-cloud/shared/mechanics/testdata/aws-mechanics-redeploy-withupdatedresource.step1.bicep similarity index 100% rename from test/functional/shared/mechanics/testdata/aws-mechanics-redeploy-withupdatedresource.step1.bicep rename to test/functional-cloud/shared/mechanics/testdata/aws-mechanics-redeploy-withupdatedresource.step1.bicep diff --git a/test/functional/shared/mechanics/testdata/aws-mechanics-redeploy-withupdatedresource.step2.bicep b/test/functional-cloud/shared/mechanics/testdata/aws-mechanics-redeploy-withupdatedresource.step2.bicep similarity index 100% rename from test/functional/shared/mechanics/testdata/aws-mechanics-redeploy-withupdatedresource.step2.bicep rename to test/functional-cloud/shared/mechanics/testdata/aws-mechanics-redeploy-withupdatedresource.step2.bicep diff --git a/test/functional/shared/resources/aws_multi_identifier_resource_test.go b/test/functional-cloud/shared/resources/aws_multi_identifier_resource_test.go similarity index 100% rename from test/functional/shared/resources/aws_multi_identifier_resource_test.go rename to test/functional-cloud/shared/resources/aws_multi_identifier_resource_test.go diff --git a/test/functional/shared/resources/aws_s3_bucket_test.go b/test/functional-cloud/shared/resources/aws_s3_bucket_test.go similarity index 100% rename from test/functional/shared/resources/aws_s3_bucket_test.go rename to test/functional-cloud/shared/resources/aws_s3_bucket_test.go diff --git a/test/functional/shared/resources/azure_connections_test.go b/test/functional-cloud/shared/resources/azure_connections_test.go similarity index 100% rename from test/functional/shared/resources/azure_connections_test.go rename to test/functional-cloud/shared/resources/azure_connections_test.go diff --git a/test/functional-cloud/shared/resources/extender_test.go b/test/functional-cloud/shared/resources/extender_test.go new file mode 100644 index 00000000000..954b0d24d80 --- /dev/null +++ b/test/functional-cloud/shared/resources/extender_test.go @@ -0,0 +1,105 @@ +/* +Copyright 2023 The Radius Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package resource_test + +import ( + "fmt" + "testing" + + "os" + + "github.com/radius-project/radius/test/functional" + "github.com/radius-project/radius/test/functional/shared" + "github.com/radius-project/radius/test/step" + "github.com/radius-project/radius/test/validation" +) + +func Test_Extender_RecipeAWS(t *testing.T) { + t.Skip("Skipping until we resolve https://github.com/radius-project/radius/issues/6535") + awsAccountID := os.Getenv("AWS_ACCOUNT_ID") + awsRegion := os.Getenv("AWS_REGION") + // Error the test if the required environment variables are not set + // for running locally set the environment variables + if awsAccountID == "" || awsRegion == "" { + t.Error("This test needs the env variables AWS_ACCOUNT_ID and AWS_REGION to be set") + } + + template := "testdata/corerp-resources-extender-aws-s3-recipe.bicep" + name := "corerp-resources-extenders-aws-s3-recipe" + appName := "corerp-resources-extenders-aws-s3-recipe-app" + bucketName := functional.GenerateS3BucketName() + bucketID := fmt.Sprintf("/planes/aws/aws/accounts/%s/regions/%s/providers/AWS.S3/Bucket/%s", awsAccountID, awsRegion, bucketName) + creationTimestamp := functional.GetCreationTimestamp() + + test := shared.NewRPTest(t, name, []shared.TestStep{ + { + Executor: step.NewDeployExecutor( + template, + "bucketName="+bucketName, + "creationTimestamp="+creationTimestamp, + functional.GetAWSAccountId(), + functional.GetAWSRegion(), + functional.GetBicepRecipeRegistry(), + functional.GetBicepRecipeVersion(), + ), + RPResources: &validation.RPResourceSet{ + Resources: []validation.RPResource{ + { + Name: "corerp-resources-extenders-aws-s3-recipe-env", + Type: validation.EnvironmentsResource, + }, + { + Name: "corerp-resources-extenders-aws-s3-recipe-app", + Type: validation.ApplicationsResource, + }, + { + Name: "corerp-resources-extenders-aws-s3-recipe", + Type: validation.ExtendersResource, + App: appName, + OutputResources: []validation.OutputResourceResponse{ + { + ID: bucketID, + }, + }, + }, + }, + }, + AWSResources: &validation.AWSResourceSet{ + Resources: []validation.AWSResource{ + { + Name: bucketName, + Type: validation.AWSS3BucketResourceType, + Identifier: bucketName, + Properties: map[string]any{ + "BucketName": bucketName, + "Tags": []any{ + map[string]any{ + "Key": "RadiusCreationTimestamp", + "Value": creationTimestamp, + }, + }, + }, + SkipDeletion: true, // will be deleted by the recipe + }, + }, + }, + SkipObjectValidation: true, + }, + }) + + test.Test(t) +} diff --git a/test/functional/shared/resources/persistent_volume_test.go b/test/functional-cloud/shared/resources/persistent_volume_test.go similarity index 100% rename from test/functional/shared/resources/persistent_volume_test.go rename to test/functional-cloud/shared/resources/persistent_volume_test.go diff --git a/test/functional-cloud/shared/resources/recipe_terraform_test.go b/test/functional-cloud/shared/resources/recipe_terraform_test.go new file mode 100644 index 00000000000..5ffc0a8d21e --- /dev/null +++ b/test/functional-cloud/shared/resources/recipe_terraform_test.go @@ -0,0 +1,134 @@ +/* +Copyright 2023 The Radius Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package resource_test + +// This file contains tests for Terraform recipes functionality - covering general behaviors that should +// be consistent across all resource types. These tests mostly use the extender resource type and mostly +// avoid cloud resources to avoid unnecessary coupling and reliability issues. +// +// Tests in this file should only use cloud resources if absolutely necessary. +// +// Tests in this file should be kept *roughly* in sync with recipe_bicep_test and any other drivers. + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + corev1 "k8s.io/api/core/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + "github.com/radius-project/radius/pkg/recipes" + "github.com/radius-project/radius/pkg/recipes/terraform/config/backends" + "github.com/radius-project/radius/test/functional" + "github.com/radius-project/radius/test/functional/shared" + "github.com/radius-project/radius/test/step" + "github.com/radius-project/radius/test/validation" +) + +var ( + secretNamespace = "radius-system" + secretPrefix = "tfstate-default-" +) + +// Test_TerraformRecipe_Redis covers the following terraform recipe scenario: +// +// - Create an extender resource using a Terraform recipe that deploys Redis on Kubernetes. +// - The recipe deployment creates a Kubernetes deployment and a Kubernetes service. + +// Test_TerraformRecipe_AzureStorage creates an Extender resource consuming a Terraform recipe that deploys an Azure blob storage instance. +func Test_TerraformRecipe_AzureStorage(t *testing.T) { + template := "testdata/corerp-resources-terraform-azurestorage.bicep" + name := "corerp-resources-terraform-azstorage" + appName := "corerp-resources-terraform-azstorage-app" + envName := "corerp-resources-terraform-azstorage-env" + + test := shared.NewRPTest(t, name, []shared.TestStep{ + { + Executor: step.NewDeployExecutor(template, functional.GetTerraformRecipeModuleServerURL(), "appName="+appName), + RPResources: &validation.RPResourceSet{ + Resources: []validation.RPResource{ + { + Name: envName, + Type: validation.EnvironmentsResource, + }, + { + Name: appName, + Type: validation.ApplicationsResource, + }, + { + Name: name, + Type: validation.ExtendersResource, + App: appName, + }, + }, + }, + SkipObjectValidation: true, + PostStepVerify: func(ctx context.Context, t *testing.T, test shared.RPTest) { + resourceID := "/planes/radius/local/resourcegroups/kind-radius/providers/Applications.Core/extenders/" + name + secretSuffix, err := getSecretSuffix(resourceID, envName, appName) + require.NoError(t, err) + + secret, err := test.Options.K8sClient.CoreV1().Secrets(secretNamespace). + Get(ctx, secretPrefix+secretSuffix, metav1.GetOptions{}) + require.NoError(t, err) + require.Equal(t, secretNamespace, secret.Namespace) + require.Equal(t, secretPrefix+secretSuffix, secret.Name) + }, + }, + }) + + test.PostDeleteVerify = func(ctx context.Context, t *testing.T, test shared.RPTest) { + resourceID := "/planes/radius/local/resourcegroups/kind-radius/providers/Applications.Core/extenders/" + name + testSecretDeletion(t, ctx, test, appName, envName, resourceID) + } + + test.Test(t) +} + +func testSecretDeletion(t *testing.T, ctx context.Context, test shared.RPTest, appName, envName, resourceID string) { + secretSuffix, err := getSecretSuffix(resourceID, envName, appName) + require.NoError(t, err) + + secret, err := test.Options.K8sClient.CoreV1().Secrets(secretNamespace). + Get(ctx, secretPrefix+secretSuffix, metav1.GetOptions{}) + require.Error(t, err) + require.True(t, apierrors.IsNotFound(err)) + require.Equal(t, secret, &corev1.Secret{}) +} + +func getSecretSuffix(resourceID, envName, appName string) (string, error) { + envID := "/planes/radius/local/resourcegroups/kind-radius/providers/Applications.Core/environments/" + envName + appID := "/planes/radius/local/resourcegroups/kind-radius/providers/Applications.Core/applications/" + appName + + resourceRecipe := recipes.ResourceMetadata{ + EnvironmentID: envID, + ApplicationID: appID, + ResourceID: resourceID, + Parameters: nil, + } + + backend := backends.NewKubernetesBackend(nil) + secretMap, err := backend.BuildBackend(&resourceRecipe) + if err != nil { + return "", err + } + kubernetes := secretMap["kubernetes"].(map[string]any) + + return kubernetes["secret_suffix"].(string), nil +} diff --git a/test/functional/shared/resources/storage_test.go b/test/functional-cloud/shared/resources/storage_test.go similarity index 100% rename from test/functional/shared/resources/storage_test.go rename to test/functional-cloud/shared/resources/storage_test.go diff --git a/test/functional/shared/resources/testdata/aws-multi-identifier.bicep b/test/functional-cloud/shared/resources/testdata/aws-multi-identifier.bicep similarity index 100% rename from test/functional/shared/resources/testdata/aws-multi-identifier.bicep rename to test/functional-cloud/shared/resources/testdata/aws-multi-identifier.bicep diff --git a/test/functional/shared/resources/testdata/aws-s3-bucket-existing.bicep b/test/functional-cloud/shared/resources/testdata/aws-s3-bucket-existing.bicep similarity index 100% rename from test/functional/shared/resources/testdata/aws-s3-bucket-existing.bicep rename to test/functional-cloud/shared/resources/testdata/aws-s3-bucket-existing.bicep diff --git a/test/functional/shared/resources/testdata/aws-s3-bucket.bicep b/test/functional-cloud/shared/resources/testdata/aws-s3-bucket.bicep similarity index 100% rename from test/functional/shared/resources/testdata/aws-s3-bucket.bicep rename to test/functional-cloud/shared/resources/testdata/aws-s3-bucket.bicep diff --git a/test/functional-cloud/shared/resources/testdata/corerp-azure-connection-database-service.bicep b/test/functional-cloud/shared/resources/testdata/corerp-azure-connection-database-service.bicep new file mode 100644 index 00000000000..0dde82220d3 --- /dev/null +++ b/test/functional-cloud/shared/resources/testdata/corerp-azure-connection-database-service.bicep @@ -0,0 +1,31 @@ +import radius as radius + +param magpieimage string + +param environment string + +param cosmosmongodbresourceid string + +resource app 'Applications.Core/applications@2023-10-01-preview' = { + name: 'corerp-azure-connection-database-service' + location: 'global' + properties: { + environment: environment + } +} + +resource store 'Applications.Core/containers@2023-10-01-preview' = { + name: 'db-service' + location: 'global' + properties: { + application: app.id + container: { + image: magpieimage + } + connections: { + databaseresource: { + source: cosmosmongodbresourceid + } + } + } +} diff --git a/test/functional/shared/resources/testdata/corerp-resources-extender-aws-s3-recipe.bicep b/test/functional-cloud/shared/resources/testdata/corerp-resources-extender-aws-s3-recipe.bicep similarity index 100% rename from test/functional/shared/resources/testdata/corerp-resources-extender-aws-s3-recipe.bicep rename to test/functional-cloud/shared/resources/testdata/corerp-resources-extender-aws-s3-recipe.bicep diff --git a/test/functional/shared/resources/testdata/corerp-resources-terraform-azurestorage.bicep b/test/functional-cloud/shared/resources/testdata/corerp-resources-terraform-azurestorage.bicep similarity index 100% rename from test/functional/shared/resources/testdata/corerp-resources-terraform-azurestorage.bicep rename to test/functional-cloud/shared/resources/testdata/corerp-resources-terraform-azurestorage.bicep diff --git a/test/functional/shared/resources/testdata/corerp-resources-volume-azure-keyvault.bicep b/test/functional-cloud/shared/resources/testdata/corerp-resources-volume-azure-keyvault.bicep similarity index 100% rename from test/functional/shared/resources/testdata/corerp-resources-volume-azure-keyvault.bicep rename to test/functional-cloud/shared/resources/testdata/corerp-resources-volume-azure-keyvault.bicep diff --git a/test/functional-cloud/shared/resources/testdata/parameters/test-tls-cert.parameters.json b/test/functional-cloud/shared/resources/testdata/parameters/test-tls-cert.parameters.json new file mode 100644 index 00000000000..23dc99fbb20 --- /dev/null +++ b/test/functional-cloud/shared/resources/testdata/parameters/test-tls-cert.parameters.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "tlscrt": { + "value": "-----BEGIN CERTIFICATE-----\nMIIFljCCA34CCQCClM1GARh19zANBgk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recipes/README.md b/test/functional-cloud/shared/resources/testdata/recipes/test-bicep-recipes/README.md new file mode 100644 index 00000000000..a307c1ba02b --- /dev/null +++ b/test/functional-cloud/shared/resources/testdata/recipes/test-bicep-recipes/README.md @@ -0,0 +1,11 @@ +# Test Recipes + +The recipes in this folder are published as part of the PR process to: + +> `ghcr.io/radius-project/dev/test/functional/shared/recipes/:pr-` + +This is important because it allows us to make changes to the recipes, and test them in the same PR that contains the change. + +## Non-recipes bicep files + +Any Bicep file starting with `_` will be skipped during publishing. Use this as a convention to create shared modules that are not published as recipes. For example `_redis_kubernetes.bicep` would not be published. \ No newline at end of file diff --git a/test/functional/shared/resources/testdata/recipes/test-bicep-recipes/extenders-aws-s3-recipe.bicep b/test/functional-cloud/shared/resources/testdata/recipes/test-bicep-recipes/extenders-aws-s3-recipe.bicep similarity index 100% rename from test/functional/shared/resources/testdata/recipes/test-bicep-recipes/extenders-aws-s3-recipe.bicep rename to test/functional-cloud/shared/resources/testdata/recipes/test-bicep-recipes/extenders-aws-s3-recipe.bicep diff --git a/test/functional-cloud/shared/resources/testdata/recipes/test-terraform-recipes/README.md b/test/functional-cloud/shared/resources/testdata/recipes/test-terraform-recipes/README.md new file mode 100644 index 00000000000..11cb976509f --- /dev/null +++ b/test/functional-cloud/shared/resources/testdata/recipes/test-terraform-recipes/README.md @@ -0,0 +1,41 @@ +# Test Terraform Recipes + +The recipes in this folder are published as part of the PR process to a web server running inside the Kubernetes cluster. + +This is important because it allows us to make changes to the recipes, and test them in the same PR that contains the change. + +## Structure + +Each directory should contain a Terraform module. The module will be zipped and uploaded to the cluster. Then it will be accessible to terraform using a URL like: + +```txt +http://tf-module-server.radius-test-tf-module-server.svc.cluster.local/.zip +``` + +This can be used in [Terraform](https://developer.hashicorp.com/terraform/language/modules/sources#fetching-archives-over-http) as the `source` attribute of a module. + +This URL is only accessible inside the cluster. + +## Testing + +If you need to verify the content, use: + +```txt +kubectl port-forward svc/tf-module-server 8999:80 -n radius-test-tf-module-server +``` + +Then you can access the recipe download at: + +```txt +http://localhost:8999/.zip +``` + +---- + +Or reference a module from Terraform: + +```hcl +module "testing" { + source = "http://localhost:8999/.zip" +} +``` \ No newline at end of file diff --git a/test/functional/shared/resources/testdata/recipes/test-terraform-recipes/azure-storage/main.tf b/test/functional-cloud/shared/resources/testdata/recipes/test-terraform-recipes/azure-storage/main.tf similarity index 100% rename from test/functional/shared/resources/testdata/recipes/test-terraform-recipes/azure-storage/main.tf rename to test/functional-cloud/shared/resources/testdata/recipes/test-terraform-recipes/azure-storage/main.tf diff --git a/test/functional/shared/resources/testdata/recipes/test-terraform-recipes/azure-storage/output.tf b/test/functional-cloud/shared/resources/testdata/recipes/test-terraform-recipes/azure-storage/output.tf similarity index 100% rename from test/functional/shared/resources/testdata/recipes/test-terraform-recipes/azure-storage/output.tf rename to test/functional-cloud/shared/resources/testdata/recipes/test-terraform-recipes/azure-storage/output.tf diff --git a/test/functional/shared/resources/testdata/recipes/test-terraform-recipes/azure-storage/variables.tf b/test/functional-cloud/shared/resources/testdata/recipes/test-terraform-recipes/azure-storage/variables.tf similarity index 100% rename from test/functional/shared/resources/testdata/recipes/test-terraform-recipes/azure-storage/variables.tf rename to test/functional-cloud/shared/resources/testdata/recipes/test-terraform-recipes/azure-storage/variables.tf diff --git a/test/functional/ucp/aws_credential_test.go b/test/functional-cloud/ucp/aws_credential_test.go similarity index 92% rename from test/functional/ucp/aws_credential_test.go rename to test/functional-cloud/ucp/aws_credential_test.go index 35b3788beba..0e8156a1c1e 100644 --- a/test/functional/ucp/aws_credential_test.go +++ b/test/functional-cloud/ucp/aws_credential_test.go @@ -26,11 +26,12 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" ucp "github.com/radius-project/radius/pkg/ucp/api/v20231001preview" + ucptest "github.com/radius-project/radius/test/functional/ucp" "github.com/stretchr/testify/require" ) func Test_AWS_Credential_Operations(t *testing.T) { - test := NewUCPTest(t, "Test_AWS_Credential_Operations", func(t *testing.T, url string, roundTripper http.RoundTripper) { + test := ucptest.NewUCPTest(t, "Test_AWS_Credential_Operations", func(t *testing.T, url string, roundTripper http.RoundTripper) { resourceTypePath := "/planes/aws/awstest/providers/System.AWS/credentials" resourceURL := fmt.Sprintf("%s%s/default?api-version=%s", url, resourceTypePath, ucp.Version) collectionURL := fmt.Sprintf("%s%s?api-version=%s", url, resourceTypePath, ucp.Version) @@ -74,7 +75,7 @@ func runAWSCredentialTests(t *testing.T, resourceUrl string, collectionUrl strin func createAWSTestCredential(t *testing.T, roundTripper http.RoundTripper, url string, credential ucp.AwsCredentialResource) { body, err := json.Marshal(credential) require.NoError(t, err) - createRequest, err := NewUCPRequest(http.MethodPut, url, bytes.NewBuffer(body)) + createRequest, err := ucptest.NewUCPRequest(http.MethodPut, url, bytes.NewBuffer(body)) require.NoError(t, err) res, err := roundTripper.RoundTrip(createRequest) @@ -85,7 +86,7 @@ func createAWSTestCredential(t *testing.T, roundTripper http.RoundTripper, url s } func getAWSTestCredential(t *testing.T, roundTripper http.RoundTripper, url string) (ucp.AwsCredentialResource, int) { - getCredentialRequest, err := NewUCPRequest(http.MethodGet, url, nil) + getCredentialRequest, err := ucptest.NewUCPRequest(http.MethodGet, url, nil) require.NoError(t, err) result, err := roundTripper.RoundTrip(getCredentialRequest) @@ -104,7 +105,7 @@ func getAWSTestCredential(t *testing.T, roundTripper http.RoundTripper, url stri } func deleteAWSTestCredential(t *testing.T, roundTripper http.RoundTripper, url string) (int, error) { - deleteCredentialRequest, err := NewUCPRequest(http.MethodDelete, url, nil) + deleteCredentialRequest, err := ucptest.NewUCPRequest(http.MethodDelete, url, nil) require.NoError(t, err) res, err := roundTripper.RoundTrip(deleteCredentialRequest) @@ -112,7 +113,7 @@ func deleteAWSTestCredential(t *testing.T, roundTripper http.RoundTripper, url s } func listAWSTestCredential(t *testing.T, roundTripper http.RoundTripper, url string) []ucp.AwsCredentialResource { - listCredentialRequest, err := NewUCPRequest(http.MethodGet, url, nil) + listCredentialRequest, err := ucptest.NewUCPRequest(http.MethodGet, url, nil) require.NoError(t, err) res, err := roundTripper.RoundTrip(listCredentialRequest) diff --git a/test/functional/ucp/aws_test.go b/test/functional-cloud/ucp/aws_test.go similarity index 95% rename from test/functional/ucp/aws_test.go rename to test/functional-cloud/ucp/aws_test.go index 854676e4b5c..fd640f159ee 100644 --- a/test/functional/ucp/aws_test.go +++ b/test/functional-cloud/ucp/aws_test.go @@ -34,6 +34,7 @@ import ( "github.com/radius-project/radius/pkg/ucp/api/v20231001preview" "github.com/radius-project/radius/pkg/ucp/aws" "github.com/radius-project/radius/pkg/ucp/frontend/controller/awsproxy" + ucptest "github.com/radius-project/radius/test/functional/ucp" "github.com/radius-project/radius/test/validation" "github.com/stretchr/testify/require" ) @@ -50,7 +51,7 @@ func Test_AWS_DeleteResource(t *testing.T) { bucketName := generateS3BucketName() setupTestAWSResource(t, ctx, bucketName) - test := NewUCPTest(t, "Test_AWS_DeleteResource", func(t *testing.T, url string, roundTripper http.RoundTripper) { + test := ucptest.NewUCPTest(t, "Test_AWS_DeleteResource", func(t *testing.T, url string, roundTripper http.RoundTripper) { resourceID, err := validation.GetResourceIdentifier(ctx, s3BucketResourceType, bucketName) require.NoError(t, err) @@ -112,7 +113,7 @@ func Test_AWS_ListResources(t *testing.T) { var bucketName = generateS3BucketName() setupTestAWSResource(t, ctx, bucketName) - test := NewUCPTest(t, "Test_AWS_ListResources", func(t *testing.T, url string, roundTripper http.RoundTripper) { + test := ucptest.NewUCPTest(t, "Test_AWS_ListResources", func(t *testing.T, url string, roundTripper http.RoundTripper) { resourceID, err := validation.GetResourceIdentifier(ctx, s3BucketResourceType, bucketName) require.NoError(t, err) diff --git a/test/functional/ucp/azure_credential_test.go b/test/functional-cloud/ucp/azure_credential_test.go similarity index 93% rename from test/functional/ucp/azure_credential_test.go rename to test/functional-cloud/ucp/azure_credential_test.go index 45e127001b8..341c2f14ad3 100644 --- a/test/functional/ucp/azure_credential_test.go +++ b/test/functional-cloud/ucp/azure_credential_test.go @@ -26,11 +26,12 @@ import ( "github.com/radius-project/radius/pkg/to" ucp "github.com/radius-project/radius/pkg/ucp/api/v20231001preview" + ucptest "github.com/radius-project/radius/test/functional/ucp" "github.com/stretchr/testify/require" ) func Test_Azure_Credential_Operations(t *testing.T) { - test := NewUCPTest(t, "Test_Azure_Credential_Operations", func(t *testing.T, url string, roundTripper http.RoundTripper) { + test := ucptest.NewUCPTest(t, "Test_Azure_Credential_Operations", func(t *testing.T, url string, roundTripper http.RoundTripper) { resourceTypePath := "/planes/azure/azuretest/providers/System.Azure/credentials" resourceURL := fmt.Sprintf("%s%s/default?api-version=%s", url, resourceTypePath, ucp.Version) collectionURL := fmt.Sprintf("%s%s?api-version=%s", url, resourceTypePath, ucp.Version) @@ -72,7 +73,7 @@ func runAzureCredentialTests(t *testing.T, resourceUrl string, collectionUrl str func createAzureTestCredential(t *testing.T, roundTripper http.RoundTripper, url string, credential ucp.AzureCredentialResource) { body, err := json.Marshal(credential) require.NoError(t, err) - createRequest, err := NewUCPRequest(http.MethodPut, url, bytes.NewBuffer(body)) + createRequest, err := ucptest.NewUCPRequest(http.MethodPut, url, bytes.NewBuffer(body)) require.NoError(t, err) res, err := roundTripper.RoundTrip(createRequest) @@ -83,7 +84,7 @@ func createAzureTestCredential(t *testing.T, roundTripper http.RoundTripper, url } func getAzureTestCredential(t *testing.T, roundTripper http.RoundTripper, url string) (ucp.AzureCredentialResource, int) { - getCredentialRequest, err := NewUCPRequest(http.MethodGet, url, nil) + getCredentialRequest, err := ucptest.NewUCPRequest(http.MethodGet, url, nil) require.NoError(t, err) result, err := roundTripper.RoundTrip(getCredentialRequest) @@ -102,7 +103,7 @@ func getAzureTestCredential(t *testing.T, roundTripper http.RoundTripper, url st } func deleteAzureTestCredential(t *testing.T, roundTripper http.RoundTripper, url string) (int, error) { - deleteCredentialRequest, err := NewUCPRequest(http.MethodDelete, url, nil) + deleteCredentialRequest, err := ucptest.NewUCPRequest(http.MethodDelete, url, nil) require.NoError(t, err) res, err := roundTripper.RoundTrip(deleteCredentialRequest) @@ -110,7 +111,7 @@ func deleteAzureTestCredential(t *testing.T, roundTripper http.RoundTripper, url } func listAzureTestCredential(t *testing.T, roundTripper http.RoundTripper, url string) []ucp.AzureCredentialResource { - listCredentialRequest, err := NewUCPRequest(http.MethodGet, url, nil) + listCredentialRequest, err := ucptest.NewUCPRequest(http.MethodGet, url, nil) require.NoError(t, err) res, err := roundTripper.RoundTrip(listCredentialRequest) diff --git a/test/functional/shared/resources/extender_test.go b/test/functional/shared/resources/extender_test.go index 31b10205454..1d3229cd7b1 100644 --- a/test/functional/shared/resources/extender_test.go +++ b/test/functional/shared/resources/extender_test.go @@ -17,11 +17,8 @@ limitations under the License. package resource_test import ( - "fmt" "testing" - "os" - "github.com/radius-project/radius/test/functional" "github.com/radius-project/radius/test/functional/shared" "github.com/radius-project/radius/test/step" @@ -96,79 +93,3 @@ func Test_Extender_Recipe(t *testing.T) { test.Test(t) } - -func Test_Extender_RecipeAWS(t *testing.T) { - t.Skip("Skipping until we resolve https://github.com/radius-project/radius/issues/6535") - awsAccountID := os.Getenv("AWS_ACCOUNT_ID") - awsRegion := os.Getenv("AWS_REGION") - // Error the test if the required environment variables are not set - // for running locally set the environment variables - if awsAccountID == "" || awsRegion == "" { - t.Error("This test needs the env variables AWS_ACCOUNT_ID and AWS_REGION to be set") - } - - template := "testdata/corerp-resources-extender-aws-s3-recipe.bicep" - name := "corerp-resources-extenders-aws-s3-recipe" - appName := "corerp-resources-extenders-aws-s3-recipe-app" - bucketName := functional.GenerateS3BucketName() - bucketID := fmt.Sprintf("/planes/aws/aws/accounts/%s/regions/%s/providers/AWS.S3/Bucket/%s", awsAccountID, awsRegion, bucketName) - creationTimestamp := functional.GetCreationTimestamp() - - test := shared.NewRPTest(t, name, []shared.TestStep{ - { - Executor: step.NewDeployExecutor( - template, - "bucketName="+bucketName, - "creationTimestamp="+creationTimestamp, - functional.GetAWSAccountId(), - functional.GetAWSRegion(), - functional.GetBicepRecipeRegistry(), - functional.GetBicepRecipeVersion(), - ), - RPResources: &validation.RPResourceSet{ - Resources: []validation.RPResource{ - { - Name: "corerp-resources-extenders-aws-s3-recipe-env", - Type: validation.EnvironmentsResource, - }, - { - Name: "corerp-resources-extenders-aws-s3-recipe-app", - Type: validation.ApplicationsResource, - }, - { - Name: "corerp-resources-extenders-aws-s3-recipe", - Type: validation.ExtendersResource, - App: appName, - OutputResources: []validation.OutputResourceResponse{ - { - ID: bucketID, - }, - }, - }, - }, - }, - AWSResources: &validation.AWSResourceSet{ - Resources: []validation.AWSResource{ - { - Name: bucketName, - Type: validation.AWSS3BucketResourceType, - Identifier: bucketName, - Properties: map[string]any{ - "BucketName": bucketName, - "Tags": []any{ - map[string]any{ - "Key": "RadiusCreationTimestamp", - "Value": creationTimestamp, - }, - }, - }, - SkipDeletion: true, // will be deleted by the recipe - }, - }, - }, - SkipObjectValidation: true, - }, - }) - - test.Test(t) -} diff --git a/test/functional/shared/resources/recipe_terraform_test.go b/test/functional/shared/resources/recipe_terraform_test.go index 9cfac5845a0..b98d3f0780d 100644 --- a/test/functional/shared/resources/recipe_terraform_test.go +++ b/test/functional/shared/resources/recipe_terraform_test.go @@ -213,56 +213,6 @@ func Test_TerraformRecipe_Context(t *testing.T) { test.Test(t) } -// Test_TerraformRecipe_AzureStorage creates an Extender resource consuming a Terraform recipe that deploys an Azure blob storage instance. -func Test_TerraformRecipe_AzureStorage(t *testing.T) { - template := "testdata/corerp-resources-terraform-azurestorage.bicep" - name := "corerp-resources-terraform-azstorage" - appName := "corerp-resources-terraform-azstorage-app" - envName := "corerp-resources-terraform-azstorage-env" - - test := shared.NewRPTest(t, name, []shared.TestStep{ - { - Executor: step.NewDeployExecutor(template, functional.GetTerraformRecipeModuleServerURL(), "appName="+appName), - RPResources: &validation.RPResourceSet{ - Resources: []validation.RPResource{ - { - Name: envName, - Type: validation.EnvironmentsResource, - }, - { - Name: appName, - Type: validation.ApplicationsResource, - }, - { - Name: name, - Type: validation.ExtendersResource, - App: appName, - }, - }, - }, - SkipObjectValidation: true, - PostStepVerify: func(ctx context.Context, t *testing.T, test shared.RPTest) { - resourceID := "/planes/radius/local/resourcegroups/kind-radius/providers/Applications.Core/extenders/" + name - secretSuffix, err := getSecretSuffix(resourceID, envName, appName) - require.NoError(t, err) - - secret, err := test.Options.K8sClient.CoreV1().Secrets(secretNamespace). - Get(ctx, secretPrefix+secretSuffix, metav1.GetOptions{}) - require.NoError(t, err) - require.Equal(t, secretNamespace, secret.Namespace) - require.Equal(t, secretPrefix+secretSuffix, secret.Name) - }, - }, - }) - - test.PostDeleteVerify = func(ctx context.Context, t *testing.T, test shared.RPTest) { - resourceID := "/planes/radius/local/resourcegroups/kind-radius/providers/Applications.Core/extenders/" + name - testSecretDeletion(t, ctx, test, appName, envName, resourceID) - } - - test.Test(t) -} - // Test_TerraformRecipe_ParametersAndOutputs Validates input parameters correctly set and output values/secrets are populated. func Test_TerraformRecipe_ParametersAndOutputs(t *testing.T) { template := "testdata/corerp-resources-terraform-recipe-terraform.bicep"