-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: SQS standard queues (experimental) (#1503)
* feat: SQS standard queues (experimental) This is the initial steel thread, and should be considered experimental at this stage. [#186768674](https://www.pivotaltracker.com/story/show/186768674) * feat: SQS resolve code review comments [#186768674](https://www.pivotaltracker.com/story/show/186768674)
- Loading branch information
Showing
13 changed files
with
329 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
version: 1 | ||
name: csb-aws-sqs | ||
id: 2198d694-bf85-11ee-a918-a7bdfa69a96d | ||
description: CSB AWS SQS | ||
display_name: CSB AWS SQS | ||
image_url: file://service-images/csb.png | ||
documentation_url: https://docs.vmware.com/en/Cloud-Service-Broker-for-VMware-Tanzu/index.html | ||
provider_display_name: VMware | ||
support_url: https://aws.amazon.com/sqs/ | ||
tags: [aws, sqs, beta] | ||
plan_updateable: true | ||
provision: | ||
user_inputs: | ||
- field_name: region | ||
type: string | ||
details: The region of AWS. | ||
default: us-west-2 | ||
constraints: | ||
examples: | ||
- us-west-2 | ||
- eu-west-1 | ||
pattern: ^[a-z][a-z0-9-]+$ | ||
prohibit_update: true | ||
- field_name: aws_access_key_id | ||
type: string | ||
details: AWS access key | ||
default: ${config("aws.access_key_id")} | ||
- field_name: aws_secret_access_key | ||
type: string | ||
details: AWS secret key | ||
default: ${config("aws.secret_access_key")} | ||
computed_inputs: | ||
- name: instance_name | ||
default: csb-sqs-${request.instance_id} | ||
overwrite: true | ||
type: string | ||
- name: labels | ||
default: ${json.marshal(request.default_labels)} | ||
overwrite: true | ||
type: object | ||
template_refs: | ||
main: terraform/sqs/provision/main.tf | ||
outputs: terraform/sqs/provision/outputs.tf | ||
provider: terraform/sqs/provision/providers.tf | ||
versions: terraform/sqs/provision/versions.tf | ||
variables: terraform/sqs/provision/variables.tf | ||
outputs: | ||
- field_name: arn | ||
type: string | ||
details: ARN for the queue | ||
- field_name: url | ||
type: string | ||
details: URL for the queue | ||
- field_name: name | ||
type: string | ||
details: name for the queue | ||
- field_name: region | ||
type: string | ||
details: AWS region for the queue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
package integration_test | ||
|
||
import ( | ||
"fmt" | ||
|
||
testframework "github.com/cloudfoundry/cloud-service-broker/brokerpaktestframework" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
. "github.com/onsi/gomega/gstruct" | ||
) | ||
|
||
const ( | ||
sqsServiceID = "2198d694-bf85-11ee-a918-a7bdfa69a96d" | ||
sqsServiceName = "csb-aws-sqs" | ||
sqsServiceDescription = "CSB AWS SQS" | ||
sqsServiceDisplayName = "CSB AWS SQS" | ||
sqsServiceSupportURL = "https://aws.amazon.com/sqs/" | ||
sqsServiceProviderDisplayName = "VMware" | ||
sqsCustomStandardPlanName = "custom-standard" | ||
sqsCustomStandardPlanID = "4c206ad6-bf89-11ee-8900-2f8e8940fc0d" | ||
) | ||
|
||
var customSQSPlans = []map[string]any{ | ||
customSQSPlan, | ||
} | ||
|
||
var customSQSPlan = map[string]any{ | ||
"name": sqsCustomStandardPlanName, | ||
"id": sqsCustomStandardPlanID, | ||
"description": "Custom SQS standard queue plan", | ||
"metadata": map[string]any{ | ||
"displayName": "custom-standard", | ||
}, | ||
} | ||
|
||
var _ = Describe("SQS", Label("SQS"), func() { | ||
BeforeEach(func() { | ||
Expect(mockTerraform.SetTFState([]testframework.TFStateValue{})).To(Succeed()) | ||
|
||
DeferCleanup(func() { | ||
Expect(mockTerraform.Reset()).To(Succeed()) | ||
}) | ||
}) | ||
|
||
It("should publish AWS SQS in the catalog", func() { | ||
catalog, err := broker.Catalog() | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
service := testframework.FindService(catalog, sqsServiceName) | ||
Expect(service.ID).To(Equal(sqsServiceID)) | ||
Expect(service.Description).To(Equal(sqsServiceDescription)) | ||
Expect(service.Tags).To(ConsistOf("aws", "sqs", "beta")) | ||
Expect(service.Metadata.DisplayName).To(Equal(sqsServiceDisplayName)) | ||
Expect(service.Metadata.DocumentationUrl).To(Equal(documentationURL)) | ||
Expect(service.Metadata.ImageUrl).To(ContainSubstring("data:image/png;base64,")) | ||
Expect(service.Metadata.SupportUrl).To(Equal(sqsServiceSupportURL)) | ||
Expect(service.Metadata.ProviderDisplayName).To(Equal(sqsServiceProviderDisplayName)) | ||
Expect(service.Plans).To( | ||
ConsistOf( | ||
MatchFields(IgnoreExtras, Fields{ | ||
Name: Equal(sqsCustomStandardPlanName), | ||
ID: Equal(sqsCustomStandardPlanID), | ||
}), | ||
), | ||
) | ||
}) | ||
|
||
Describe("provisioning", func() { | ||
DescribeTable("property constraints", | ||
func(params map[string]any, expectedErrorMsg string) { | ||
_, err := broker.Provision(sqsServiceName, sqsCustomStandardPlanName, params) | ||
|
||
Expect(err).To(MatchError(ContainSubstring(expectedErrorMsg))) | ||
}, | ||
Entry( | ||
"invalid region", | ||
map[string]any{"region": "-Asia-northeast1"}, | ||
"region: Does not match pattern '^[a-z][a-z0-9-]+$'", | ||
), | ||
) | ||
|
||
It("should provision a plan", func() { | ||
instanceID, err := broker.Provision(sqsServiceName, sqsCustomStandardPlanName, nil) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
Expect(mockTerraform.FirstTerraformInvocationVars()).To( | ||
SatisfyAll( | ||
HaveKeyWithValue("labels", MatchKeys(IgnoreExtras, Keys{ | ||
"pcf-instance-id": Equal(instanceID), | ||
"key1": Equal("value1"), | ||
"key2": Equal("value2"), | ||
})), | ||
HaveKeyWithValue("instance_name", fmt.Sprintf("csb-sqs-%s", instanceID)), | ||
HaveKeyWithValue("region", fakeRegion), | ||
HaveKeyWithValue("aws_access_key_id", awsAccessKeyID), | ||
HaveKeyWithValue("aws_secret_access_key", awsSecretAccessKey), | ||
), | ||
) | ||
}) | ||
|
||
It("should allow properties to be set on provision", func() { | ||
_, err := broker.Provision(sqsServiceName, sqsCustomStandardPlanName, map[string]any{ | ||
"region": "africa-north-4", | ||
"aws_access_key_id": "fake-aws-access-key-id", | ||
"aws_secret_access_key": "fake-aws-secret-access-key", | ||
}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
Expect(mockTerraform.FirstTerraformInvocationVars()).To( | ||
SatisfyAll( | ||
HaveKeyWithValue("region", "africa-north-4"), | ||
HaveKeyWithValue("aws_access_key_id", "fake-aws-access-key-id"), | ||
HaveKeyWithValue("aws_secret_access_key", "fake-aws-secret-access-key"), | ||
), | ||
) | ||
}) | ||
}) | ||
|
||
Describe("updating instance", func() { | ||
var instanceID string | ||
|
||
BeforeEach(func() { | ||
var err error | ||
instanceID, err = broker.Provision(sqsServiceName, sqsCustomStandardPlanName, nil) | ||
|
||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
|
||
DescribeTable("should prevent updating properties flagged as `prohibit_update` because it can result in the recreation of the service instance", | ||
func(prop string, value any) { | ||
err := broker.Update(instanceID, sqsServiceName, sqsCustomStandardPlanName, map[string]any{prop: value}) | ||
|
||
Expect(err).To(MatchError( | ||
ContainSubstring( | ||
"attempt to update parameter that may result in service instance re-creation and data loss", | ||
), | ||
)) | ||
|
||
const initialProvisionInvocation = 1 | ||
Expect(mockTerraform.ApplyInvocations()).To(HaveLen(initialProvisionInvocation)) | ||
}, | ||
Entry("update region", "region", "no-matter-what-region"), | ||
) | ||
|
||
DescribeTable( | ||
"some allowed updates", | ||
func(prop string, value any) { | ||
err := broker.Update(instanceID, sqsServiceName, sqsCustomStandardPlanName, map[string]any{prop: value}) | ||
|
||
Expect(err).NotTo(HaveOccurred()) | ||
}, | ||
Entry(nil, "aws_access_key_id", "fake-aws-access-key-id"), | ||
Entry(nil, "aws_secret_access_key", "fake-aws-secret-access-key"), | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package terraformtests | ||
|
||
import ( | ||
. "csbbrokerpakaws/terraform-tests/helpers" | ||
"fmt" | ||
"path" | ||
"time" | ||
|
||
tfjson "github.com/hashicorp/terraform-json" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
. "github.com/onsi/gomega/gstruct" | ||
) | ||
|
||
var _ = Describe("SQS", Label("SQS-terraform"), Ordered, func() { | ||
var ( | ||
name string | ||
plan tfjson.Plan | ||
terraformProvisionDir string | ||
defaultVars map[string]any | ||
) | ||
|
||
BeforeAll(func() { | ||
name = fmt.Sprintf("csb-tf-test-sqs-%d-%d", GinkgoRandomSeed(), time.Now().Unix()) | ||
|
||
terraformProvisionDir = path.Join(workingDir, "sqs/provision") | ||
Init(terraformProvisionDir) | ||
}) | ||
|
||
BeforeEach(func() { | ||
defaultVars = map[string]any{ | ||
"instance_name": name, | ||
"labels": map[string]string{"label1": "value1"}, | ||
"aws_access_key_id": awsAccessKeyID, | ||
"aws_secret_access_key": awsSecretAccessKey, | ||
"region": awsRegion, | ||
} | ||
}) | ||
|
||
Context("with default values", func() { | ||
BeforeAll(func() { | ||
plan = ShowPlan(terraformProvisionDir, buildVars(defaultVars, map[string]any{})) | ||
}) | ||
|
||
It("should create the right resources", func() { | ||
Expect(plan.ResourceChanges).To(HaveLen(1)) | ||
|
||
Expect(ResourceChangesTypes(plan)).To(ConsistOf( | ||
"aws_sqs_queue", | ||
)) | ||
}) | ||
|
||
It("should create an SQS queue with the correct properties", func() { | ||
Expect(AfterValuesForType(plan, "aws_sqs_queue")).To( | ||
MatchKeys(IgnoreExtras, Keys{ | ||
"name": Equal(name), | ||
"fifo_queue": BeFalse(), | ||
"tags": MatchAllKeys(Keys{ | ||
"label1": Equal("value1"), | ||
}), | ||
}), | ||
) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
resource "aws_sqs_queue" "queue" { | ||
name = var.instance_name | ||
fifo_queue = false | ||
tags = var.labels | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
output "arn" { value = aws_sqs_queue.queue.arn } | ||
output "url" { value = aws_sqs_queue.queue.id } | ||
output "name" { value = aws_sqs_queue.queue.name } | ||
output "region" { value = var.region } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
provider "aws" { | ||
region = var.region | ||
access_key = var.aws_access_key_id | ||
secret_key = var.aws_secret_access_key | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
variable "aws_access_key_id" { | ||
type = string | ||
sensitive = true | ||
} | ||
variable "aws_secret_access_key" { | ||
type = string | ||
sensitive = true | ||
} | ||
variable "region" { type = string } | ||
|
||
variable "instance_name" { type = string } | ||
variable "labels" { type = map(any) } |
Oops, something went wrong.