@@ -81,15 +81,15 @@ func testCaseKafkaPlaintext(t *testing.T, nameSuffix string) *resource.TestCase
81
81
CheckDestroy : CheckDestroyStreamConnection ,
82
82
Steps : []resource.TestStep {
83
83
{
84
- Config : dataSourcesConfig + configureKafka (projectID , instanceName , connectionName , "user" , "rawpassword" , "localhost:9092,localhost:9092" , "earliest" , "" , false ),
84
+ Config : dataSourcesConfig + configureKafka (fmt . Sprintf ( "%q" , projectID ) , instanceName , connectionName , "user" , "rawpassword" , "localhost:9092,localhost:9092" , "earliest" , "" , false ),
85
85
Check : resource .ComposeAggregateTestCheckFunc (
86
86
checkKafkaAttributes (resourceName , instanceName , connectionName , "user" , "rawpassword" , "localhost:9092,localhost:9092" , "earliest" , networkingTypePublic , false , true ),
87
87
checkKafkaAttributes (dataSourceName , instanceName , connectionName , "user" , "rawpassword" , "localhost:9092,localhost:9092" , "earliest" , networkingTypePublic , false , false ),
88
88
streamConnectionsAttributeChecks (pluralDataSourceName , nil , nil ),
89
89
),
90
90
},
91
91
{
92
- Config : dataSourcesWithPagination + configureKafka (projectID , instanceName , connectionName , "user2" , "otherpassword" , "localhost:9093" , "latest" , kafkaNetworkingPublic , false ),
92
+ Config : dataSourcesWithPagination + configureKafka (fmt . Sprintf ( "%q" , projectID ) , instanceName , connectionName , "user2" , "otherpassword" , "localhost:9093" , "latest" , kafkaNetworkingPublic , false ),
93
93
Check : resource .ComposeAggregateTestCheckFunc (
94
94
checkKafkaAttributes (resourceName , instanceName , connectionName , "user2" , "otherpassword" , "localhost:9093" , "latest" , networkingTypePublic , false , true ),
95
95
checkKafkaAttributes (dataSourceName , instanceName , connectionName , "user2" , "otherpassword" , "localhost:9093" , "latest" , networkingTypePublic , false , false ),
@@ -113,8 +113,8 @@ func TestAccStreamRSStreamConnection_kafkaNetworkingVPC(t *testing.T) {
113
113
vpcID = os .Getenv ("AWS_VPC_ID" )
114
114
vpcCIDRBlock = os .Getenv ("AWS_VPC_CIDR_BLOCK" )
115
115
awsAccountID = os .Getenv ("AWS_ACCOUNT_ID" )
116
- containerRegion = os .Getenv ("AWS_REGION" )
117
- peerRegion = conversion .MongoDBRegionToAWSRegion ( containerRegion )
116
+ peerRegion = os .Getenv ("AWS_REGION" )
117
+ containerRegion = conversion .AWSRegionToMongoDBRegion ( peerRegion )
118
118
providerName = "AWS"
119
119
networkPeeringConfig = configNetworkPeeringAWS (projectID , providerName , vpcID , awsAccountID , vpcCIDRBlock , containerRegion , peerRegion )
120
120
)
@@ -125,7 +125,7 @@ func TestAccStreamRSStreamConnection_kafkaNetworkingVPC(t *testing.T) {
125
125
CheckDestroy : CheckDestroyStreamConnection ,
126
126
Steps : []resource.TestStep {
127
127
{
128
- Config : networkPeeringConfig + configureKafka (projectID , instanceName , "kafka-conn-vpc" , "user" , "rawpassword" , "localhost:9092" , "earliest" , kafkaNetworkingVPC , true ),
128
+ Config : networkPeeringConfig + configureKafka ("mongodbatlas_network_peering.test.project_id" , instanceName , "kafka-conn-vpc" , "user" , "rawpassword" , "localhost:9092" , "earliest" , kafkaNetworkingVPC , true ),
129
129
Check : checkKafkaAttributes (resourceName , instanceName , "kafka-conn-vpc" , "user" , "rawpassword" , "localhost:9092" , "earliest" , networkingTypeVPC , true , true ),
130
130
},
131
131
{
@@ -145,8 +145,8 @@ func TestAccStreamRSStreamConnection_kafkaSSL(t *testing.T) {
145
145
vpcID = os .Getenv ("AWS_VPC_ID" )
146
146
vpcCIDRBlock = os .Getenv ("AWS_VPC_CIDR_BLOCK" )
147
147
awsAccountID = os .Getenv ("AWS_ACCOUNT_ID" )
148
- containerRegion = os .Getenv ("AWS_REGION" )
149
- peerRegion = conversion .MongoDBRegionToAWSRegion ( containerRegion )
148
+ peerRegion = os .Getenv ("AWS_REGION" )
149
+ containerRegion = conversion .AWSRegionToMongoDBRegion ( peerRegion )
150
150
providerName = "AWS"
151
151
networkPeeringConfig = configNetworkPeeringAWS (projectID , providerName , vpcID , awsAccountID , vpcCIDRBlock , containerRegion , peerRegion )
152
152
)
@@ -156,15 +156,15 @@ func TestAccStreamRSStreamConnection_kafkaSSL(t *testing.T) {
156
156
CheckDestroy : CheckDestroyStreamConnection ,
157
157
Steps : []resource.TestStep {
158
158
{
159
- Config : fmt .Sprintf ("%s\n %s" , configureKafka (projectID , instanceName , "kafka-conn-ssl" , "user" , "rawpassword" , "localhost:9092" , "earliest" , kafkaNetworkingPublic , true ), dataSourceConfig ),
159
+ Config : fmt .Sprintf ("%s\n %s" , configureKafka (fmt . Sprintf ( "%q" , projectID ) , instanceName , "kafka-conn-ssl" , "user" , "rawpassword" , "localhost:9092" , "earliest" , kafkaNetworkingPublic , true ), dataSourceConfig ),
160
160
Check : resource .ComposeAggregateTestCheckFunc (
161
161
checkKafkaAttributes (resourceName , instanceName , "kafka-conn-ssl" , "user" , "rawpassword" , "localhost:9092" , "earliest" , networkingTypePublic , true , true ),
162
162
checkKafkaAttributes (dataSourceName , instanceName , "kafka-conn-ssl" , "user" , "rawpassword" , "localhost:9092" , "earliest" , networkingTypePublic , true , false ),
163
163
),
164
164
},
165
165
// cannot change networking access type once set
166
166
{
167
- Config : networkPeeringConfig + configureKafka (projectID , instanceName , "kafka-conn-ssl" , "user" , "rawpassword" , "localhost:9092" , "earliest" , kafkaNetworkingVPC , true ),
167
+ Config : networkPeeringConfig + configureKafka ("mongodbatlas_network_peering.test.project_id" , instanceName , "kafka-conn-ssl" , "user" , "rawpassword" , "localhost:9092" , "earliest" , kafkaNetworkingVPC , true ),
168
168
ExpectError : regexp .MustCompile ("STREAM_NETWORKING_ACCESS_TYPE_CANNOT_BE_MODIFIED" ),
169
169
},
170
170
{
@@ -321,7 +321,7 @@ func TestAccStreamPrivatelinkEndpoint_streamConnection(t *testing.T) {
321
321
Config : fmt .Sprintf (`
322
322
%[1]s
323
323
%[2]s
324
- ` , privatelinkConfig , configureKafka (projectID , instanceName , "kafka-conn-privatelink" , "user" , "rawpassword" , "localhost:9092" , "earliest" , kafkaNetworkingPrivatelink , true )),
324
+ ` , privatelinkConfig , configureKafka (fmt . Sprintf ( "%q" , projectID ) , instanceName , "kafka-conn-privatelink" , "user" , "rawpassword" , "localhost:9092" , "earliest" , kafkaNetworkingPrivatelink , true )),
325
325
Check : checkKafkaAttributes (resourceName , instanceName , "kafka-conn-privatelink" , "user" , "rawpassword" , "localhost:9092" , "earliest" , networkingTypePrivatelink , true , true ),
326
326
},
327
327
{
@@ -337,19 +337,19 @@ func TestAccStreamPrivatelinkEndpoint_streamConnection(t *testing.T) {
337
337
338
338
func TestAccStreamRSStreamConnection_AWSLambda (t * testing.T ) {
339
339
var (
340
- projectID = os .Getenv ("MONGODB_ATLAS_ASP_PROJECT_EAR_PE_ID" )
341
- instanceName = acc .RandomStreamInstanceName () // Using the ASP projectID, so must create its own stream instance
342
- connectionName = acc .RandomName ()
343
- roleArn = os .Getenv ("MONGODB_ATLAS_ASP_PROJECT_AWS_ROLE_ARN" )
340
+ projectID , instanceName = acc .ProjectIDExecutionWithStreamInstance (t )
341
+ awsIAMRoleName = acc .RandomIAMRole ()
342
+ connectionName = acc .RandomName ()
344
343
)
345
344
resource .ParallelTest (t , resource.TestCase {
346
345
PreCheck : func () { acc .PreCheckBasic (t ) },
346
+ ExternalProviders : acc .ExternalProvidersOnlyAWS (),
347
347
ProtoV6ProviderFactories : acc .TestAccProviderV6Factories ,
348
348
CheckDestroy : CheckDestroyStreamConnection ,
349
349
Steps : []resource.TestStep {
350
350
{
351
- Config : configureAWSLambda (projectID , instanceName , connectionName , roleArn ),
352
- Check : checkAWSLambdaAttributes (resourceName , instanceName , connectionName , roleArn ),
351
+ Config : configureAWSLambda (projectID , instanceName , connectionName , awsIAMRoleName ),
352
+ Check : checkAWSLambdaAttributes (resourceName , instanceName , connectionName ),
353
353
},
354
354
{
355
355
ResourceName : resourceName ,
@@ -361,7 +361,7 @@ func TestAccStreamRSStreamConnection_AWSLambda(t *testing.T) {
361
361
})
362
362
}
363
363
364
- func configureKafka (projectID , instanceName , connectionName , username , password , bootstrapServers , configValue , networkingConfig string , useSSL bool ) string {
364
+ func configureKafka (projectRef , instanceName , connectionName , username , password , bootstrapServers , configValue , networkingConfig string , useSSL bool ) string {
365
365
securityConfig := `
366
366
security = {
367
367
protocol = "SASL_PLAINTEXT"
@@ -376,7 +376,7 @@ func configureKafka(projectID, instanceName, connectionName, username, password,
376
376
}
377
377
return fmt .Sprintf (`
378
378
resource "mongodbatlas_stream_connection" "test" {
379
- project_id = %[1]q
379
+ project_id = %[1]s
380
380
instance_name = %[2]q
381
381
connection_name = %[3]q
382
382
type = "Kafka"
@@ -392,7 +392,7 @@ func configureKafka(projectID, instanceName, connectionName, username, password,
392
392
%[8]s
393
393
%[9]s
394
394
}
395
- ` , projectID , instanceName , connectionName , username , password , bootstrapServers , configValue , networkingConfig , securityConfig )
395
+ ` , projectRef , instanceName , connectionName , username , password , bootstrapServers , configValue , networkingConfig , securityConfig )
396
396
}
397
397
398
398
func configureSampleStream (projectID , instanceName , sampleName string ) string {
@@ -581,33 +581,65 @@ func configNetworkPeeringAWS(projectID, providerName, vpcID, awsAccountID, vpcCI
581
581
` , projectID , providerName , vpcID , awsAccountID , vpcCIDRBlock , awsRegionContainer , awsRegionPeer )
582
582
}
583
583
584
- func configureAWSLambda (projectID , instanceName , connectionName , roleArn string ) string {
585
- streamInstanceConfig := acc .StreamInstanceConfig (projectID , instanceName , "VIRGINIA_USA" , "AWS" )
584
+ func configureAWSLambda (projectID , instanceName , connectionName , awsIamRoleName string ) string {
585
+ config := fmt .Sprintf (`
586
+ resource "aws_iam_role" "test_role" {
587
+ name = %[4]q
588
+
589
+ assume_role_policy = jsonencode({
590
+ "Version" : "2012-10-17",
591
+ "Statement" : [
592
+ {
593
+ "Effect" : "Allow",
594
+ "Principal" : {
595
+ "AWS" : "${mongodbatlas_cloud_provider_access_setup.setup_only.aws_config[0].atlas_aws_account_arn}"
596
+ },
597
+ "Action" : "sts:AssumeRole",
598
+ "Condition" : {
599
+ "StringEquals" : {
600
+ "sts:ExternalId" : "${mongodbatlas_cloud_provider_access_setup.setup_only.aws_config[0].atlas_assumed_role_external_id}"
601
+ }
602
+ }
603
+ }
604
+ ]
605
+ })
606
+ }
586
607
587
- return fmt .Sprintf (`
588
- %[1]s
608
+ resource "mongodbatlas_cloud_provider_access_setup" "setup_only" {
609
+ project_id = %[1]q
610
+ provider_name = "AWS"
611
+ }
612
+
613
+ resource "mongodbatlas_cloud_provider_access_authorization" "auth_role" {
614
+ project_id = %[1]q
615
+ role_id = mongodbatlas_cloud_provider_access_setup.setup_only.role_id
616
+
617
+ aws {
618
+ iam_assumed_role_arn = aws_iam_role.test_role.arn
619
+ }
620
+ }
589
621
590
622
resource "mongodbatlas_stream_connection" "test" {
591
- project_id = mongodbatlas_stream_instance.test.project_id
592
- instance_name = mongodbatlas_stream_instance.test.instance_name
593
- connection_name = %[2 ]q
623
+ project_id = %[1]q
624
+ instance_name = %[2]q
625
+ connection_name = %[3 ]q
594
626
type = "AWSLambda"
595
627
aws = {
596
- role_arn = %[3]q
628
+ role_arn = mongodbatlas_cloud_provider_access_authorization.auth_role.aws[0].iam_assumed_role_arn
597
629
}
598
630
}
599
- ` , streamInstanceConfig , connectionName , roleArn )
631
+ ` , projectID , instanceName , connectionName , awsIamRoleName )
632
+ return config
600
633
}
601
634
602
- func checkAWSLambdaAttributes (
603
- resourceName , instanceName , connectionName , roleArn string ) resource.TestCheckFunc {
635
+ func checkAWSLambdaAttributes (resourceName , instanceName , connectionName string ) resource.TestCheckFunc {
604
636
resourceChecks := []resource.TestCheckFunc {
605
637
checkStreamConnectionExists (),
606
638
resource .TestCheckResourceAttrSet (resourceName , "project_id" ),
607
639
resource .TestCheckResourceAttr (resourceName , "instance_name" , instanceName ),
608
640
resource .TestCheckResourceAttr (resourceName , "connection_name" , connectionName ),
609
641
resource .TestCheckResourceAttr (resourceName , "type" , "AWSLambda" ),
610
- resource .TestCheckResourceAttr (resourceName , "aws.role_arn" , roleArn ),
642
+ resource .TestCheckResourceAttrSet (resourceName , "aws.role_arn" ),
611
643
}
612
644
return resource .ComposeAggregateTestCheckFunc (resourceChecks ... )
613
645
}
0 commit comments