add sqs-queue
parent
efdf8ab43b
commit
0fb7156dbe
|
@ -981,9 +981,13 @@ func TestDriftctlRun_Middlewares(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "test sqs queue policy expander middleware",
|
name: "test sqs queue policy expander middleware",
|
||||||
stateResources: []resource.Resource{
|
stateResources: []resource.Resource{
|
||||||
&aws.AwsSqsQueue{
|
&resource.AbstractResource{
|
||||||
Id: "foo",
|
Id: "foo",
|
||||||
Policy: awssdk.String("{\"policy\":\"bar\"}"),
|
Type: aws.AwsSqsQueueResourceType,
|
||||||
|
Attrs: &resource.Attributes{
|
||||||
|
"id": "foo",
|
||||||
|
"policy": "{\"policy\":\"bar\"}",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
remoteResources: []resource.Resource{
|
remoteResources: []resource.Resource{
|
||||||
|
@ -998,18 +1002,21 @@ func TestDriftctlRun_Middlewares(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
mocks: func(factory resource.ResourceFactory) {
|
mocks: func(factory resource.ResourceFactory) {
|
||||||
foo := cty.ObjectVal(map[string]cty.Value{
|
factory.(*terraform.MockResourceFactory).On("CreateAbstractResource", "aws_sqs_queue_policy", "foo", mock.MatchedBy(func(input map[string]interface{}) bool {
|
||||||
"id": cty.StringVal("foo"),
|
|
||||||
"queue_url": cty.StringVal("foo"),
|
|
||||||
"policy": cty.StringVal("{\"policy\":\"bar\"}"),
|
|
||||||
})
|
|
||||||
factory.(*terraform.MockResourceFactory).On("CreateResource", mock.MatchedBy(func(input map[string]interface{}) bool {
|
|
||||||
return matchByAttributes(input, map[string]interface{}{
|
return matchByAttributes(input, map[string]interface{}{
|
||||||
"id": "foo",
|
"id": "foo",
|
||||||
"queue_url": "foo",
|
"queue_url": "foo",
|
||||||
"policy": awssdk.String("{\"policy\":\"bar\"}"),
|
"policy": "{\"policy\":\"bar\"}",
|
||||||
})
|
})
|
||||||
}), "aws_sqs_queue_policy").Times(1).Return(&foo, nil)
|
})).Times(1).Return(&resource.AbstractResource{
|
||||||
|
Id: "foo",
|
||||||
|
Type: aws.AwsSqsQueuePolicyResourceType,
|
||||||
|
Attrs: &resource.Attributes{
|
||||||
|
"id": "foo",
|
||||||
|
"queue_url": "foo",
|
||||||
|
"policy": "{\"policy\":\"bar\"}",
|
||||||
|
},
|
||||||
|
}, nil)
|
||||||
},
|
},
|
||||||
assert: func(result *test.ScanResult, err error) {
|
assert: func(result *test.ScanResult, err error) {
|
||||||
result.AssertManagedCount(1)
|
result.AssertManagedCount(1)
|
||||||
|
|
|
@ -1,40 +1,42 @@
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"Arn": "arn:aws:sqs:eu-west-3:047081014315:bar.fifo",
|
|
||||||
"ContentBasedDeduplication": true,
|
|
||||||
"DelaySeconds": 0,
|
|
||||||
"FifoQueue": true,
|
|
||||||
"Id": "https://sqs.eu-west-3.amazonaws.com/047081014315/bar.fifo",
|
"Id": "https://sqs.eu-west-3.amazonaws.com/047081014315/bar.fifo",
|
||||||
"KmsDataKeyReusePeriodSeconds": 300,
|
"Type": "aws_sqs_queue",
|
||||||
"KmsMasterKeyId": "",
|
"Attrs": {
|
||||||
"MaxMessageSize": 262144,
|
"arn": "arn:aws:sqs:eu-west-3:047081014315:bar.fifo",
|
||||||
"MessageRetentionSeconds": 345600,
|
"content_based_deduplication": true,
|
||||||
"Name": "bar.fifo",
|
"delay_seconds": 0,
|
||||||
"NamePrefix": null,
|
"fifo_queue": true,
|
||||||
"Policy": null,
|
"id": "https://sqs.eu-west-3.amazonaws.com/047081014315/bar.fifo",
|
||||||
"ReceiveWaitTimeSeconds": 0,
|
"kms_data_key_reuse_period_seconds": 300,
|
||||||
"RedrivePolicy": "",
|
"kms_master_key_id": "",
|
||||||
"Tags": {},
|
"max_message_size": 262144,
|
||||||
"VisibilityTimeoutSeconds": 30,
|
"message_retention_seconds": 345600,
|
||||||
"CtyVal": {}
|
"name": "bar.fifo",
|
||||||
|
"policy": "",
|
||||||
|
"receive_wait_time_seconds": 0,
|
||||||
|
"redrive_policy": "",
|
||||||
|
"visibility_timeout_seconds": 30
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Arn": "arn:aws:sqs:eu-west-3:047081014315:foo",
|
|
||||||
"ContentBasedDeduplication": false,
|
|
||||||
"DelaySeconds": 0,
|
|
||||||
"FifoQueue": false,
|
|
||||||
"Id": "https://sqs.eu-west-3.amazonaws.com/047081014315/foo",
|
"Id": "https://sqs.eu-west-3.amazonaws.com/047081014315/foo",
|
||||||
"KmsDataKeyReusePeriodSeconds": 300,
|
"Type": "aws_sqs_queue",
|
||||||
"KmsMasterKeyId": "",
|
"Attrs": {
|
||||||
"MaxMessageSize": 262144,
|
"arn": "arn:aws:sqs:eu-west-3:047081014315:foo",
|
||||||
"MessageRetentionSeconds": 345600,
|
"content_based_deduplication": false,
|
||||||
"Name": "foo",
|
"delay_seconds": 0,
|
||||||
"NamePrefix": null,
|
"fifo_queue": false,
|
||||||
"Policy": null,
|
"id": "https://sqs.eu-west-3.amazonaws.com/047081014315/foo",
|
||||||
"ReceiveWaitTimeSeconds": 0,
|
"kms_data_key_reuse_period_seconds": 300,
|
||||||
"RedrivePolicy": "",
|
"kms_master_key_id": "",
|
||||||
"Tags": {},
|
"max_message_size": 262144,
|
||||||
"VisibilityTimeoutSeconds": 30,
|
"message_retention_seconds": 345600,
|
||||||
"CtyVal": {}
|
"name": "foo",
|
||||||
|
"policy": "",
|
||||||
|
"receive_wait_time_seconds": 0,
|
||||||
|
"redrive_policy": "",
|
||||||
|
"visibility_timeout_seconds": 30
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
|
@ -29,15 +29,16 @@ func (m AwsSqsQueuePolicyExpander) Execute(_, resourcesFromState *[]resource.Res
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
queue, _ := res.(*aws.AwsSqsQueue)
|
queue, _ := res.(*resource.AbstractResource)
|
||||||
newList = append(newList, res)
|
newList = append(newList, res)
|
||||||
|
|
||||||
if queue.Policy == nil {
|
policy, exist := queue.Attrs.Get("policy")
|
||||||
|
if !exist || policy == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.hasPolicyAttached(queue, resourcesFromState) {
|
if m.hasPolicyAttached(queue, resourcesFromState) {
|
||||||
queue.Policy = nil
|
queue.Attrs.SafeDelete([]string{"policy"})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,36 +51,22 @@ func (m AwsSqsQueuePolicyExpander) Execute(_, resourcesFromState *[]resource.Res
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *AwsSqsQueuePolicyExpander) handlePolicy(queue *aws.AwsSqsQueue, results *[]resource.Resource) error {
|
func (m *AwsSqsQueuePolicyExpander) handlePolicy(queue *resource.AbstractResource, results *[]resource.Resource) error {
|
||||||
|
policy, _ := queue.Attrs.Get("policy")
|
||||||
|
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"queue_url": queue.Id,
|
"queue_url": queue.Id,
|
||||||
"id": queue.Id,
|
"id": queue.Id,
|
||||||
"policy": queue.Policy,
|
"policy": policy,
|
||||||
}
|
|
||||||
ctyVal, err := m.resourceFactory.CreateResource(data, "aws_sqs_queue_policy")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
schema, exist := m.resourceSchemaRepository.GetSchema("aws_ebs_volume")
|
|
||||||
ctyAttr := resource.ToResourceAttributes(ctyVal)
|
|
||||||
ctyAttr.SanitizeDefaultsV3()
|
|
||||||
if exist && schema.NormalizeFunc != nil {
|
|
||||||
schema.NormalizeFunc(ctyAttr)
|
|
||||||
}
|
|
||||||
|
|
||||||
newPolicy := &resource.AbstractResource{
|
|
||||||
Id: queue.Id,
|
|
||||||
Type: aws.AwsSqsQueuePolicyResourceType,
|
|
||||||
Attrs: ctyAttr,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newPolicy := m.resourceFactory.CreateAbstractResource("aws_sqs_queue_policy", queue.Id, data)
|
||||||
*results = append(*results, newPolicy)
|
*results = append(*results, newPolicy)
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.WithFields(logrus.Fields{
|
||||||
"id": newPolicy.TerraformId(),
|
"id": newPolicy.TerraformId(),
|
||||||
}).Debug("Created new policy from sqs queue")
|
}).Debug("Created new policy from sqs queue")
|
||||||
|
|
||||||
queue.Policy = nil
|
queue.Attrs.SafeDelete([]string{"policy"})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +74,7 @@ func (m *AwsSqsQueuePolicyExpander) handlePolicy(queue *aws.AwsSqsQueue, results
|
||||||
// It is mandatory since it's possible to have a aws_sqs_queue with an inline policy
|
// It is mandatory since it's possible to have a aws_sqs_queue with an inline policy
|
||||||
// AND a aws_sqs_queue_policy resource at the same time. At the end, on the AWS console,
|
// AND a aws_sqs_queue_policy resource at the same time. At the end, on the AWS console,
|
||||||
// the aws_sqs_queue_policy will be used.
|
// the aws_sqs_queue_policy will be used.
|
||||||
func (m *AwsSqsQueuePolicyExpander) hasPolicyAttached(queue *aws.AwsSqsQueue, resourcesFromState *[]resource.Resource) bool {
|
func (m *AwsSqsQueuePolicyExpander) hasPolicyAttached(queue *resource.AbstractResource, resourcesFromState *[]resource.Resource) bool {
|
||||||
for _, res := range *resourcesFromState {
|
for _, res := range *resourcesFromState {
|
||||||
if res.TerraformType() == aws.AwsSqsQueuePolicyResourceType &&
|
if res.TerraformType() == aws.AwsSqsQueuePolicyResourceType &&
|
||||||
res.TerraformId() == queue.Id {
|
res.TerraformId() == queue.Id {
|
||||||
|
|
|
@ -4,10 +4,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
awssdk "github.com/aws/aws-sdk-go/aws"
|
|
||||||
"github.com/aws/aws-sdk-go/aws/awsutil"
|
"github.com/aws/aws-sdk-go/aws/awsutil"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
"github.com/zclconf/go-cty/cty"
|
|
||||||
|
|
||||||
"github.com/cloudskiff/driftctl/pkg/resource"
|
"github.com/cloudskiff/driftctl/pkg/resource"
|
||||||
"github.com/cloudskiff/driftctl/pkg/resource/aws"
|
"github.com/cloudskiff/driftctl/pkg/resource/aws"
|
||||||
|
@ -27,15 +25,22 @@ func TestAwsSqsQueuePolicyExpander_Execute(t *testing.T) {
|
||||||
{
|
{
|
||||||
"Inline policy, no aws_sqs_queue_policy attached",
|
"Inline policy, no aws_sqs_queue_policy attached",
|
||||||
[]resource.Resource{
|
[]resource.Resource{
|
||||||
&aws.AwsSqsQueue{
|
&resource.AbstractResource{
|
||||||
Id: "foo",
|
Id: "foo",
|
||||||
Policy: awssdk.String("{\"Id\":\"MYINLINESQSPOLICY\",\"Statement\":[{\"Action\":\"sqs:SendMessage\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Resource\":\"arn:aws:sqs:eu-west-3:047081014315:foo\",\"Sid\":\"Stmt1611769527792\"}],\"Version\":\"2012-10-17\"}"),
|
Type: aws.AwsSqsQueueResourceType,
|
||||||
|
Attrs: &resource.Attributes{
|
||||||
|
"id": "foo",
|
||||||
|
"policy": "{\"Id\":\"MYINLINESQSPOLICY\",\"Statement\":[{\"Action\":\"sqs:SendMessage\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Resource\":\"arn:aws:sqs:eu-west-3:047081014315:foo\",\"Sid\":\"Stmt1611769527792\"}],\"Version\":\"2012-10-17\"}",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[]resource.Resource{
|
[]resource.Resource{
|
||||||
&aws.AwsSqsQueue{
|
&resource.AbstractResource{
|
||||||
Id: "foo",
|
Id: "foo",
|
||||||
Policy: nil,
|
Type: aws.AwsSqsQueueResourceType,
|
||||||
|
Attrs: &resource.Attributes{
|
||||||
|
"id": "foo",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
&resource.AbstractResource{
|
&resource.AbstractResource{
|
||||||
Id: "foo",
|
Id: "foo",
|
||||||
|
@ -48,74 +53,166 @@ func TestAwsSqsQueuePolicyExpander_Execute(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
func(factory *terraform.MockResourceFactory) {
|
func(factory *terraform.MockResourceFactory) {
|
||||||
|
factory.On("CreateAbstractResource", "aws_sqs_queue_policy", "foo", mock.MatchedBy(func(input map[string]interface{}) bool {
|
||||||
foo := cty.ObjectVal(map[string]cty.Value{
|
|
||||||
"queue_url": cty.StringVal("foo"),
|
|
||||||
"id": cty.StringVal("foo"),
|
|
||||||
"policy": cty.StringVal("{\"Id\":\"MYINLINESQSPOLICY\",\"Statement\":[{\"Action\":\"sqs:SendMessage\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Resource\":\"arn:aws:sqs:eu-west-3:047081014315:foo\",\"Sid\":\"Stmt1611769527792\"}],\"Version\":\"2012-10-17\"}"),
|
|
||||||
})
|
|
||||||
|
|
||||||
factory.On("CreateResource", mock.MatchedBy(func(input map[string]interface{}) bool {
|
|
||||||
return input["id"] == "foo"
|
return input["id"] == "foo"
|
||||||
}), "aws_sqs_queue_policy").Once().Return(&foo, nil)
|
})).Once().Return(&resource.AbstractResource{
|
||||||
|
Id: "foo",
|
||||||
|
Type: aws.AwsSqsQueuePolicyResourceType,
|
||||||
|
Attrs: &resource.Attributes{
|
||||||
|
"queue_url": "foo",
|
||||||
|
"id": "foo",
|
||||||
|
"policy": "{\"Id\":\"MYINLINESQSPOLICY\",\"Statement\":[{\"Action\":\"sqs:SendMessage\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Resource\":\"arn:aws:sqs:eu-west-3:047081014315:foo\",\"Sid\":\"Stmt1611769527792\"}],\"Version\":\"2012-10-17\"}",
|
||||||
|
},
|
||||||
|
}, nil)
|
||||||
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"No inline policy, aws_sqs_queue_policy attached",
|
"No inline policy, aws_sqs_queue_policy attached",
|
||||||
[]resource.Resource{
|
[]resource.Resource{
|
||||||
&aws.AwsSqsQueue{
|
&resource.AbstractResource{
|
||||||
Id: "foo",
|
Id: "foo",
|
||||||
Policy: nil,
|
Type: aws.AwsSqsQueueResourceType,
|
||||||
|
Attrs: &resource.Attributes{
|
||||||
|
"id": "foo",
|
||||||
},
|
},
|
||||||
&aws.AwsSqsQueuePolicy{
|
},
|
||||||
|
&resource.AbstractResource{
|
||||||
Id: "foo",
|
Id: "foo",
|
||||||
QueueUrl: awssdk.String("foo"),
|
Type: aws.AwsSqsQueuePolicyResourceType,
|
||||||
Policy: awssdk.String("{\"Id\":\"MYSQSPOLICY\",\"Statement\":[{\"Action\":\"sqs:SendMessage\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Resource\":\"arn:aws:sqs:eu-west-3:047081014315:foo\",\"Sid\":\"Stmt1611769527792\"}],\"Version\":\"2012-10-17\"}"),
|
Attrs: &resource.Attributes{
|
||||||
|
"id": "foo",
|
||||||
|
"queue_url": "foo",
|
||||||
|
"policy": "{\"Id\":\"MYSQSPOLICY\",\"Statement\":[{\"Action\":\"sqs:SendMessage\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Resource\":\"arn:aws:sqs:eu-west-3:047081014315:foo\",\"Sid\":\"Stmt1611769527792\"}],\"Version\":\"2012-10-17\"}",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[]resource.Resource{
|
[]resource.Resource{
|
||||||
&aws.AwsSqsQueue{
|
&resource.AbstractResource{
|
||||||
Id: "foo",
|
Id: "foo",
|
||||||
Policy: nil,
|
Type: aws.AwsSqsQueueResourceType,
|
||||||
|
Attrs: &resource.Attributes{
|
||||||
|
"id": "foo",
|
||||||
},
|
},
|
||||||
&aws.AwsSqsQueuePolicy{
|
},
|
||||||
|
&resource.AbstractResource{
|
||||||
Id: "foo",
|
Id: "foo",
|
||||||
QueueUrl: awssdk.String("foo"),
|
Type: aws.AwsSqsQueuePolicyResourceType,
|
||||||
Policy: awssdk.String("{\"Id\":\"MYSQSPOLICY\",\"Statement\":[{\"Action\":\"sqs:SendMessage\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Resource\":\"arn:aws:sqs:eu-west-3:047081014315:foo\",\"Sid\":\"Stmt1611769527792\"}],\"Version\":\"2012-10-17\"}"),
|
Attrs: &resource.Attributes{
|
||||||
|
"id": "foo",
|
||||||
|
"queue_url": "foo",
|
||||||
|
"policy": "{\"Id\":\"MYSQSPOLICY\",\"Statement\":[{\"Action\":\"sqs:SendMessage\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Resource\":\"arn:aws:sqs:eu-west-3:047081014315:foo\",\"Sid\":\"Stmt1611769527792\"}],\"Version\":\"2012-10-17\"}",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}, func(factory *terraform.MockResourceFactory) {
|
}, func(factory *terraform.MockResourceFactory) {
|
||||||
factory.On("CreateResource", mock.Anything, "aws_sqs_queue_policy").Once().Return(nil, nil)
|
factory.On("CreateResource", mock.Anything, "aws_sqs_queue_policy").Once().Return(nil, nil)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Inline policy and aws_sqs_queue_policy",
|
"Inline policy duplicate aws_sqs_queue_policy",
|
||||||
[]resource.Resource{
|
[]resource.Resource{
|
||||||
&aws.AwsSqsQueue{
|
&resource.AbstractResource{
|
||||||
Id: "foo",
|
Id: "foo",
|
||||||
Policy: awssdk.String("{\"Id\":\"MYINLINESQSPOLICY\",\"Statement\":[{\"Action\":\"sqs:SendMessage\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Resource\":\"arn:aws:sqs:eu-west-3:047081014315:foo\",\"Sid\":\"Stmt1611769527792\"}],\"Version\":\"2012-10-17\"}"),
|
Type: aws.AwsSqsQueueResourceType,
|
||||||
|
Attrs: &resource.Attributes{
|
||||||
|
"id": "foo",
|
||||||
|
"policy": "{\"Id\":\"MYSQSPOLICY\",\"Statement\":[{\"Action\":\"sqs:SendMessage\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Resource\":\"arn:aws:sqs:eu-west-3:047081014315:foo\",\"Sid\":\"Stmt1611769527792\"}],\"Version\":\"2012-10-17\"}",
|
||||||
},
|
},
|
||||||
&aws.AwsSqsQueuePolicy{
|
},
|
||||||
|
&resource.AbstractResource{
|
||||||
Id: "foo",
|
Id: "foo",
|
||||||
QueueUrl: awssdk.String("foo"),
|
Type: aws.AwsSqsQueuePolicyResourceType,
|
||||||
Policy: awssdk.String("{\"Id\":\"MYSQSPOLICY\",\"Statement\":[{\"Action\":\"sqs:SendMessage\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Resource\":\"arn:aws:sqs:eu-west-3:047081014315:foo\",\"Sid\":\"Stmt1611769527792\"}],\"Version\":\"2012-10-17\"}"),
|
Attrs: &resource.Attributes{
|
||||||
|
"id": "foo",
|
||||||
|
"queue_url": "foo",
|
||||||
|
"policy": "{\"Id\":\"MYSQSPOLICY\",\"Statement\":[{\"Action\":\"sqs:SendMessage\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Resource\":\"arn:aws:sqs:eu-west-3:047081014315:foo\",\"Sid\":\"Stmt1611769527792\"}],\"Version\":\"2012-10-17\"}",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[]resource.Resource{
|
[]resource.Resource{
|
||||||
&aws.AwsSqsQueue{
|
&resource.AbstractResource{
|
||||||
Id: "foo",
|
Id: "foo",
|
||||||
Policy: nil,
|
Type: aws.AwsSqsQueueResourceType,
|
||||||
|
Attrs: &resource.Attributes{
|
||||||
|
"id": "foo",
|
||||||
},
|
},
|
||||||
&aws.AwsSqsQueuePolicy{
|
},
|
||||||
|
&resource.AbstractResource{
|
||||||
Id: "foo",
|
Id: "foo",
|
||||||
QueueUrl: awssdk.String("foo"),
|
Type: aws.AwsSqsQueuePolicyResourceType,
|
||||||
Policy: awssdk.String("{\"Id\":\"MYSQSPOLICY\",\"Statement\":[{\"Action\":\"sqs:SendMessage\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Resource\":\"arn:aws:sqs:eu-west-3:047081014315:foo\",\"Sid\":\"Stmt1611769527792\"}],\"Version\":\"2012-10-17\"}"),
|
Attrs: &resource.Attributes{
|
||||||
|
"id": "foo",
|
||||||
|
"queue_url": "foo",
|
||||||
|
"policy": "{\"Id\":\"MYSQSPOLICY\",\"Statement\":[{\"Action\":\"sqs:SendMessage\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Resource\":\"arn:aws:sqs:eu-west-3:047081014315:foo\",\"Sid\":\"Stmt1611769527792\"}],\"Version\":\"2012-10-17\"}",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
func(factory *terraform.MockResourceFactory) {
|
func(factory *terraform.MockResourceFactory) {
|
||||||
factory.On("CreateResource", mock.Anything, "aws_sqs_queue_policy").Once().Return(nil, nil)
|
factory.On("CreateResource", mock.Anything, "aws_sqs_queue_policy").Once().Return(nil, nil)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"Inline policy and aws_sqs_queue_policy",
|
||||||
|
[]resource.Resource{
|
||||||
|
&resource.AbstractResource{
|
||||||
|
Id: "foo",
|
||||||
|
Type: aws.AwsSqsQueueResourceType,
|
||||||
|
Attrs: &resource.Attributes{
|
||||||
|
"id": "foo",
|
||||||
|
"policy": "{\"Id\":\"MYINLINESQSPOLICY\",\"Statement\":[{\"Action\":\"sqs:SendMessage\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Resource\":\"arn:aws:sqs:eu-west-3:047081014315:foo\",\"Sid\":\"Stmt1611769527792\"}],\"Version\":\"2012-10-17\"}",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
&resource.AbstractResource{
|
||||||
|
Id: "bar",
|
||||||
|
Type: aws.AwsSqsQueuePolicyResourceType,
|
||||||
|
Attrs: &resource.Attributes{
|
||||||
|
"id": "bar",
|
||||||
|
"queue_url": "foo",
|
||||||
|
"policy": "{\"Id\":\"MYSQSPOLICY\",\"Statement\":[{\"Action\":\"sqs:SendMessage\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Resource\":\"arn:aws:sqs:eu-west-3:047081014315:foo\",\"Sid\":\"Stmt1611769527792\"}],\"Version\":\"2012-10-17\"}",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
[]resource.Resource{
|
||||||
|
&resource.AbstractResource{
|
||||||
|
Id: "foo",
|
||||||
|
Type: aws.AwsSqsQueueResourceType,
|
||||||
|
Attrs: &resource.Attributes{
|
||||||
|
"id": "foo",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
&resource.AbstractResource{
|
||||||
|
Id: "bar",
|
||||||
|
Type: aws.AwsSqsQueuePolicyResourceType,
|
||||||
|
Attrs: &resource.Attributes{
|
||||||
|
"id": "bar",
|
||||||
|
"queue_url": "foo",
|
||||||
|
"policy": "{\"Id\":\"MYSQSPOLICY\",\"Statement\":[{\"Action\":\"sqs:SendMessage\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Resource\":\"arn:aws:sqs:eu-west-3:047081014315:foo\",\"Sid\":\"Stmt1611769527792\"}],\"Version\":\"2012-10-17\"}",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
&resource.AbstractResource{
|
||||||
|
Id: "foo",
|
||||||
|
Type: aws.AwsSqsQueuePolicyResourceType,
|
||||||
|
Attrs: &resource.Attributes{
|
||||||
|
"id": "foo",
|
||||||
|
"queue_url": "foo",
|
||||||
|
"policy": "{\"Id\":\"MYINLINESQSPOLICY\",\"Statement\":[{\"Action\":\"sqs:SendMessage\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Resource\":\"arn:aws:sqs:eu-west-3:047081014315:foo\",\"Sid\":\"Stmt1611769527792\"}],\"Version\":\"2012-10-17\"}",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
func(factory *terraform.MockResourceFactory) {
|
||||||
|
factory.On("CreateAbstractResource", "aws_sqs_queue_policy", "foo", mock.MatchedBy(func(input map[string]interface{}) bool {
|
||||||
|
return input["id"] == "foo"
|
||||||
|
})).Once().Return(&resource.AbstractResource{
|
||||||
|
Id: "foo",
|
||||||
|
Type: aws.AwsSqsQueuePolicyResourceType,
|
||||||
|
Attrs: &resource.Attributes{
|
||||||
|
"id": "foo",
|
||||||
|
"queue_url": "foo",
|
||||||
|
"policy": "{\"Id\":\"MYINLINESQSPOLICY\",\"Statement\":[{\"Action\":\"sqs:SendMessage\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Resource\":\"arn:aws:sqs:eu-west-3:047081014315:foo\",\"Sid\":\"Stmt1611769527792\"}],\"Version\":\"2012-10-17\"}",
|
||||||
|
},
|
||||||
|
}, nil)
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|
|
@ -67,7 +67,7 @@ var refactoredResources = []string{
|
||||||
"aws_sns_topic",
|
"aws_sns_topic",
|
||||||
"aws_sns_topic_policy",
|
"aws_sns_topic_policy",
|
||||||
"aws_sns_topic_subscription",
|
"aws_sns_topic_subscription",
|
||||||
// "aws_sqs_queue",
|
"aws_sqs_queue",
|
||||||
"aws_sqs_queue_policy",
|
"aws_sqs_queue_policy",
|
||||||
"aws_subnet",
|
"aws_subnet",
|
||||||
"aws_vpc",
|
"aws_vpc",
|
||||||
|
|
Loading…
Reference in New Issue