diff --git a/test/functional/corerp/mechanics/aws_mechanics_test.go b/test/functional/corerp/mechanics/aws_mechanics_test.go index 0380ece817..83440eb587 100644 --- a/test/functional/corerp/mechanics/aws_mechanics_test.go +++ b/test/functional/corerp/mechanics/aws_mechanics_test.go @@ -17,42 +17,50 @@ import ( func Test_AWSRedeployWithUpdatedResourceUpdatesResource(t *testing.T) { templateFmt := "testdata/aws-mechanics-redeploy-withupdatedresource.step%d.bicep" - name := "ms" + uuid.New().String() + name := "radiusfunctionaltestbucket-" + uuid.New().String() test := corerp.NewCoreRPTest(t, name, []corerp.TestStep{ { - Executor: step.NewDeployExecutor(fmt.Sprintf(templateFmt, 1), "streamName="+name), + Executor: step.NewDeployExecutor(fmt.Sprintf(templateFmt, 1), "bucketName="+name), SkipKubernetesOutputResourceValidation: true, SkipObjectValidation: true, AWSResources: &validation.AWSResourceSet{ Resources: []validation.AWSResource{ { Name: name, - Type: validation.KinesisResourceType, + Type: validation.AWSS3BucketResourceType, Identifier: name, Properties: map[string]any{ - "Name": name, - "RetentionPeriodHours": float64(168), - "ShardCount": float64(3), + "BucketName": name, + "Tags": []any{ + map[string]any{ + "Key": "testKey", + "Value": "testValue", + }, + }, }, }, }, }, }, { - Executor: step.NewDeployExecutor(fmt.Sprintf(templateFmt, 2), "streamName="+name), + Executor: step.NewDeployExecutor(fmt.Sprintf(templateFmt, 2), "bucketName="+name), SkipKubernetesOutputResourceValidation: true, SkipObjectValidation: true, AWSResources: &validation.AWSResourceSet{ Resources: []validation.AWSResource{ { Name: name, - Type: validation.KinesisResourceType, + Type: validation.AWSS3BucketResourceType, Identifier: name, Properties: map[string]any{ - "Name": name, - "RetentionPeriodHours": float64(48), - "ShardCount": float64(3), + "BucketName": name, + "Tags": []any{ + map[string]any{ + "Key": "testKey", + "Value": "testValue2", + }, + }, }, }, }, @@ -76,7 +84,7 @@ func Test_AWSRedeployWithCreateAndWriteOnlyPropertyUpdate(t *testing.T) { Resources: []validation.AWSResource{ { Name: name, - Type: validation.DBInstanceResourceType, + Type: validation.AWSRDSDBInstanceResourceType, Identifier: name, Properties: map[string]any{ "Endpoint": map[string]any{ @@ -95,7 +103,7 @@ func Test_AWSRedeployWithCreateAndWriteOnlyPropertyUpdate(t *testing.T) { Resources: []validation.AWSResource{ { Name: name, - Type: validation.DBInstanceResourceType, + Type: validation.AWSRDSDBInstanceResourceType, Identifier: name, Properties: map[string]any{ "Endpoint": map[string]any{ diff --git a/test/functional/corerp/mechanics/testdata/aws-mechanics-redeploy-withupdatedresource.step1.bicep b/test/functional/corerp/mechanics/testdata/aws-mechanics-redeploy-withupdatedresource.step1.bicep index 0f6cc425ab..a37c968f81 100644 --- a/test/functional/corerp/mechanics/testdata/aws-mechanics-redeploy-withupdatedresource.step1.bicep +++ b/test/functional/corerp/mechanics/testdata/aws-mechanics-redeploy-withupdatedresource.step1.bicep @@ -1,12 +1,16 @@ import aws as aws -param streamName string +param bucketName string -resource stream 'AWS.Kinesis/Stream@default' = { - alias: streamName +resource bucket 'AWS.S3/Bucket@default' = { + alias: bucketName properties: { - Name: streamName - RetentionPeriodHours: 168 - ShardCount: 3 + BucketName: bucketName + Tags: [ + { + Key: 'testKey' + Value: 'testValue' + } + ] } } diff --git a/test/functional/corerp/mechanics/testdata/aws-mechanics-redeploy-withupdatedresource.step2.bicep b/test/functional/corerp/mechanics/testdata/aws-mechanics-redeploy-withupdatedresource.step2.bicep index 604fd2e7ce..525eb06388 100644 --- a/test/functional/corerp/mechanics/testdata/aws-mechanics-redeploy-withupdatedresource.step2.bicep +++ b/test/functional/corerp/mechanics/testdata/aws-mechanics-redeploy-withupdatedresource.step2.bicep @@ -1,12 +1,16 @@ import aws as aws -param streamName string +param bucketName string -resource stream 'AWS.Kinesis/Stream@default' = { - alias: streamName +resource bucket 'AWS.S3/Bucket@default' = { + alias: bucketName properties: { - Name: streamName - RetentionPeriodHours: 48 - ShardCount: 3 + BucketName: bucketName + Tags: [ + { + Key: 'testKey' + Value: 'testValue2' + } + ] } } diff --git a/test/functional/corerp/resources/aws_kinesis_stream_test.go b/test/functional/corerp/resources/aws_kinesis_stream_test.go deleted file mode 100644 index 20950ed472..0000000000 --- a/test/functional/corerp/resources/aws_kinesis_stream_test.go +++ /dev/null @@ -1,108 +0,0 @@ -// ------------------------------------------------------------ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -// ------------------------------------------------------------ - -package resource_test - -import ( - "context" - "testing" - - "github.com/google/uuid" - "github.com/project-radius/radius/pkg/kubernetes" - "github.com/project-radius/radius/test/functional" - "github.com/project-radius/radius/test/functional/corerp" - "github.com/project-radius/radius/test/step" - "github.com/project-radius/radius/test/validation" - "github.com/stretchr/testify/require" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" -) - -func Test_AWS_KinesisStream(t *testing.T) { - template := "testdata/aws-kinesis.bicep" - name := "ms" + uuid.New().String() - - test := corerp.NewCoreRPTest(t, name, []corerp.TestStep{ - { - Executor: step.NewDeployExecutor(template, "streamName="+name), - SkipKubernetesOutputResourceValidation: true, - SkipObjectValidation: true, - AWSResources: &validation.AWSResourceSet{ - Resources: []validation.AWSResource{ - { - Name: name, - Type: validation.KinesisResourceType, - Identifier: name, - }, - }, - }, - }, - }) - - test.Test(t) -} - -func Test_KinesisStreamExisting(t *testing.T) { - template := "testdata/aws-kinesis.bicep" - templateExisting := "testdata/aws-kinesis-existing.bicep" - name := "ms" + uuid.New().String() - appNamespace := "default-aws-kinesis-existing-app" - - test := corerp.NewCoreRPTest(t, name, []corerp.TestStep{ - { - Executor: step.NewDeployExecutor(template, "streamName="+name), - SkipKubernetesOutputResourceValidation: true, - SkipObjectValidation: true, - AWSResources: &validation.AWSResourceSet{ - Resources: []validation.AWSResource{ - { - Name: name, - Type: validation.KinesisResourceType, - Identifier: name, - }, - }, - }, - }, - { - Executor: step.NewDeployExecutor(templateExisting, "streamName="+name, functional.GetMagpieImage()), - CoreRPResources: &validation.CoreRPResourceSet{ - Resources: []validation.CoreRPResource{ - { - Name: "aws-kinesis-existing-app", - Type: validation.ApplicationsResource, - }, - { - Name: "aws-ctnr", - Type: validation.ContainersResource, - App: "aws-kinesis-existing-app", - }, - }, - }, - K8sObjects: &validation.K8sObjectSet{ - Namespaces: map[string][]validation.K8sObject{ - appNamespace: { - validation.NewK8sPodForResource("aws-kinesis-existing-app", "aws-ctnr"), - }, - }, - }, - PostStepVerify: func(ctx context.Context, t *testing.T, ct corerp.CoreRPTest) { - labelset := kubernetes.MakeSelectorLabels("aws-kinesis-existing-app", "aws-ctnr") - - deployments, err := ct.Options.K8sClient.AppsV1().Deployments(appNamespace).List(context.Background(), metav1.ListOptions{ - LabelSelector: labels.SelectorFromSet(labelset).String(), - }) - require.NoError(t, err, "failed to list deployments") - require.Len(t, deployments.Items, 1, "expected 1 deployment") - deployment := deployments.Items[0] - envVar := deployment.Spec.Template.Spec.Containers[0].Env[0] - require.Equal(t, "TEST", envVar.Name, "expected env var to be updated") - require.Equal(t, name, envVar.Value, "expected env var to be updated") - }, - }, - }) - - test.Test(t) - -} diff --git a/test/functional/corerp/resources/aws_multi_identifier_resource_test.go b/test/functional/corerp/resources/aws_multi_identifier_resource_test.go index c66ef7aadc..14977e50b6 100644 --- a/test/functional/corerp/resources/aws_multi_identifier_resource_test.go +++ b/test/functional/corerp/resources/aws_multi_identifier_resource_test.go @@ -29,12 +29,12 @@ func Test_AWS_MultiIdentifier_Resource(t *testing.T) { Resources: []validation.AWSResource{ { Name: logGroupName, - Type: validation.LogGroupResourceType, + Type: validation.AWSLogsLogGroupResourceType, Identifier: logGroupName, }, { Name: filterName, - Type: validation.MetricFilterResourceType, + Type: validation.AWSLogsMetricFilterResourceType, Identifier: logGroupName + "|" + filterName, }, }, diff --git a/test/functional/corerp/resources/aws_s3_bucket_test.go b/test/functional/corerp/resources/aws_s3_bucket_test.go new file mode 100644 index 0000000000..4bce40ec6e --- /dev/null +++ b/test/functional/corerp/resources/aws_s3_bucket_test.go @@ -0,0 +1,111 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. +// ------------------------------------------------------------ + +package resource_test + +import ( + "testing" + + "github.com/google/uuid" + "github.com/project-radius/radius/test/functional/corerp" + "github.com/project-radius/radius/test/step" + "github.com/project-radius/radius/test/validation" +) + +func Test_AWS_S3Bucket(t *testing.T) { + template := "testdata/aws-s3-bucket.bicep" + name := generateS3BucketName() + + test := corerp.NewCoreRPTest(t, name, []corerp.TestStep{ + { + Executor: step.NewDeployExecutor(template, "bucketName="+name), + SkipKubernetesOutputResourceValidation: true, + SkipObjectValidation: true, + AWSResources: &validation.AWSResourceSet{ + Resources: []validation.AWSResource{ + { + Name: name, + Type: validation.AWSS3BucketResourceType, + Identifier: name, + Properties: map[string]any{ + "BucketName": name, + "Tags": []any{ + map[string]any{ + "Key": "testKey", + "Value": "testValue", + }, + }, + }, + }, + }, + }, + }, + }) + + test.Test(t) +} + +func Test_AWS_S3Bucket_Existing(t *testing.T) { + template := "testdata/aws-s3-bucket.bicep" + templateExisting := "testdata/aws-s3-bucket-existing.bicep" + name := generateS3BucketName() + + test := corerp.NewCoreRPTest(t, name, []corerp.TestStep{ + { + Executor: step.NewDeployExecutor(template, "bucketName="+name), + SkipKubernetesOutputResourceValidation: true, + SkipObjectValidation: true, + AWSResources: &validation.AWSResourceSet{ + Resources: []validation.AWSResource{ + { + Name: name, + Type: validation.AWSS3BucketResourceType, + Identifier: name, + Properties: map[string]any{ + "BucketName": name, + "Tags": []any{ + map[string]any{ + "Key": "testKey", + "Value": "testValue", + }, + }, + }, + }, + }, + }, + }, + // The following step deploys an existing resource and validates that it retrieves the same + // resource as was deployed above + { + Executor: step.NewDeployExecutor(templateExisting, "bucketName="+name), + SkipKubernetesOutputResourceValidation: true, + SkipObjectValidation: true, + AWSResources: &validation.AWSResourceSet{ + Resources: []validation.AWSResource{ + { + Name: name, + Type: validation.AWSS3BucketResourceType, + Identifier: name, + Properties: map[string]any{ + "BucketName": name, + "Tags": []any{ + map[string]any{ + "Key": "testKey", + "Value": "testValue", + }, + }, + }, + }, + }, + }, + }, + }) + + test.Test(t) +} + +func generateS3BucketName() string { + return "radiusfunctionaltestbucket-" + uuid.New().String() +} diff --git a/test/functional/corerp/resources/testdata/aws-kinesis-existing.bicep b/test/functional/corerp/resources/testdata/aws-kinesis-existing.bicep deleted file mode 100644 index 7e4622fd5e..0000000000 --- a/test/functional/corerp/resources/testdata/aws-kinesis-existing.bicep +++ /dev/null @@ -1,53 +0,0 @@ -import aws as aws - -param streamName string - -import radius as radius - -@description('Specifies the location for resources.') -param location string = 'global' - -@description('Specifies the image of the container resource.') -param magpieimage string - -@description('Specifies the port of the container resource.') -param port int = 3000 - -@description('Specifies the environment for resources.') -param environment string - -resource stream 'AWS.Kinesis/Stream@default' existing = { - alias: streamName - properties: { - Name: streamName - } -} - -resource app 'Applications.Core/applications@2022-03-15-privatepreview' = { - name: 'aws-kinesis-existing-app' - location: location - properties: { - environment: environment - } -} - -resource container 'Applications.Core/containers@2022-03-15-privatepreview' = { - name: 'aws-ctnr' - location: location - properties: { - application: app.id - container: { - image: magpieimage - env: { - TEST: stream.properties.Name - } - ports: { - web: { - containerPort: port - } - } - } - connections: {} - } -} - diff --git a/test/functional/corerp/resources/testdata/aws-kinesis.bicep b/test/functional/corerp/resources/testdata/aws-kinesis.bicep deleted file mode 100644 index 0f6cc425ab..0000000000 --- a/test/functional/corerp/resources/testdata/aws-kinesis.bicep +++ /dev/null @@ -1,12 +0,0 @@ -import aws as aws - -param streamName string - -resource stream 'AWS.Kinesis/Stream@default' = { - alias: streamName - properties: { - Name: streamName - RetentionPeriodHours: 168 - ShardCount: 3 - } -} diff --git a/test/functional/corerp/resources/testdata/aws-s3-bucket-existing.bicep b/test/functional/corerp/resources/testdata/aws-s3-bucket-existing.bicep new file mode 100644 index 0000000000..b4bc4cd954 --- /dev/null +++ b/test/functional/corerp/resources/testdata/aws-s3-bucket-existing.bicep @@ -0,0 +1,12 @@ +import aws as aws + +param bucketName string + +resource bucket 'AWS.S3/Bucket@default' existing = { + alias: bucketName + properties: { + BucketName: bucketName + } +} + +output var string = bucket.properties.BucketName diff --git a/test/functional/corerp/resources/testdata/aws-s3-bucket.bicep b/test/functional/corerp/resources/testdata/aws-s3-bucket.bicep new file mode 100644 index 0000000000..a37c968f81 --- /dev/null +++ b/test/functional/corerp/resources/testdata/aws-s3-bucket.bicep @@ -0,0 +1,16 @@ +import aws as aws + +param bucketName string + +resource bucket 'AWS.S3/Bucket@default' = { + alias: bucketName + properties: { + BucketName: bucketName + Tags: [ + { + Key: 'testKey' + Value: 'testValue' + } + ] + } +} diff --git a/test/functional/ucp/aws_test.go b/test/functional/ucp/aws_test.go index 8d5aa97ff3..4b2e997234 100644 --- a/test/functional/ucp/aws_test.go +++ b/test/functional/ucp/aws_test.go @@ -26,18 +26,19 @@ import ( "github.com/stretchr/testify/require" ) -var resourceType = "AWS::Kinesis::Stream" +var ( + s3BucketResourceType = "AWS.S3/Bucket" + awsS3BucketResourceType = "AWS::S3::Bucket" +) func Test_AWS_DeleteResource(t *testing.T) { - var streamName = "my-stream" + uuid.NewString() ctx := context.Background() - setupTestAWSResource(t, ctx, streamName) - test := NewUCPTest(t, "Test_AWS_DeleteResource", func(t *testing.T, url string, roundTripper http.RoundTripper) { - ctx := context.Background() + bucketName := generateS3BucketName() + setupTestAWSResource(t, ctx, bucketName) - // Call UCP Delete AWS Resource API - resourceID := validation.GetResourceIdentifier(ctx, t, "AWS.Kinesis/Stream", streamName) + test := NewUCPTest(t, "Test_AWS_DeleteResource", func(t *testing.T, url string, roundTripper http.RoundTripper) { + resourceID := validation.GetResourceIdentifier(ctx, t, s3BucketResourceType, bucketName) // Construct resource collection url resourceIDParts := strings.Split(resourceID, "/") @@ -46,7 +47,7 @@ func Test_AWS_DeleteResource(t *testing.T) { deleteURL := fmt.Sprintf("%s%s/:delete?api-version=%s", url, resourceID, v20220901privatepreview.Version) deleteRequestBody := map[string]any{ "properties": map[string]any{ - "Name": streamName, + "BucketName": bucketName, }, } deleteBody, err := json.Marshal(deleteRequestBody) @@ -85,20 +86,20 @@ func Test_AWS_DeleteResource(t *testing.T) { } require.True(t, deleteSucceeded) }) - test.Test(t) + test.Test(t) } func Test_AWS_ListResources(t *testing.T) { - var streamName = "my-stream" + uuid.NewString() ctx := context.Background() - setupTestAWSResource(t, ctx, streamName) + + var bucketName = generateS3BucketName() + setupTestAWSResource(t, ctx, bucketName) test := NewUCPTest(t, "Test_AWS_ListResources", func(t *testing.T, url string, roundTripper http.RoundTripper) { - // Call UCP Delete AWS Resource API - resourceID := validation.GetResourceIdentifier(ctx, t, "AWS.Kinesis/Stream", streamName) + resourceID := validation.GetResourceIdentifier(ctx, t, s3BucketResourceType, bucketName) - // Remove the stream name from the to form the post URL and add the stream name to the body + // Construct resource collection url resourceIDParts := strings.Split(resourceID, "/") resourceIDParts = resourceIDParts[:len(resourceIDParts)-1] resourceID = strings.Join(resourceIDParts, "/") @@ -132,15 +133,14 @@ func setupTestAWSResource(t *testing.T, ctx context.Context, resourceName string require.NoError(t, err) var awsClient aws.AWSCloudControlClient = cloudcontrol.NewFromConfig(cfg) desiredState := map[string]any{ - "Name": resourceName, - "RetentionPeriodHours": 180, - "ShardCount": 4, + "BucketName": resourceName, + "AccessControl": "PublicRead", } desiredStateBytes, err := json.Marshal(desiredState) require.NoError(t, err) response, err := awsClient.CreateResource(ctx, &cloudcontrol.CreateResourceInput{ - TypeName: &resourceType, + TypeName: &awsS3BucketResourceType, DesiredState: awsgo.String(string(desiredStateBytes)), }) require.NoError(t, err) @@ -151,7 +151,7 @@ func setupTestAWSResource(t *testing.T, ctx context.Context, resourceName string // seems to fail if the resource does not exist _, err := awsClient.GetResource(ctx, &cloudcontrol.GetResourceInput{ Identifier: &resourceName, - TypeName: &resourceType, + TypeName: &awsS3BucketResourceType, }) if aws.IsAWSResourceNotFound(err) { return @@ -159,7 +159,7 @@ func setupTestAWSResource(t *testing.T, ctx context.Context, resourceName string // Just in case delete fails deleteOutput, err := awsClient.DeleteResource(ctx, &cloudcontrol.DeleteResourceInput{ Identifier: &resourceName, - TypeName: &resourceType, + TypeName: &awsS3BucketResourceType, }) require.NoError(t, err) @@ -178,3 +178,7 @@ func waitForSuccess(t *testing.T, ctx context.Context, awsClient aws.AWSCloudCon }, maxWaitTime) require.NoError(t, err) } + +func generateS3BucketName() string { + return "ucpfunctionaltestbucket-" + uuid.NewString() +} diff --git a/test/validation/aws.go b/test/validation/aws.go index dcc4470ee0..6a268784a1 100644 --- a/test/validation/aws.go +++ b/test/validation/aws.go @@ -22,11 +22,11 @@ import ( ) const ( - KinesisResourceType = "AWS.Kinesis/Stream" - MemoryDBResourceType = "AWS.MemoryDB/Cluster" - DBInstanceResourceType = "AWS.RDS/DBInstance" - MetricFilterResourceType = "AWS.Logs/MetricFilter" - LogGroupResourceType = "AWS.Logs/LogGroup" + AWSS3BucketResourceType = "AWS.S3/Bucket" + AWSMemoryDBClusterResourceType = "AWS.MemoryDB/Cluster" + AWSRDSDBInstanceResourceType = "AWS.RDS/DBInstance" + AWSLogsMetricFilterResourceType = "AWS.Logs/MetricFilter" + AWSLogsLogGroupResourceType = "AWS.Logs/LogGroup" ) type AWSResource struct {