Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/aws_msk_sasl_scram_secret: New Resource #15302

Merged
merged 7 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions aws/data_source_aws_msk_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func dataSourceAwsMskCluster() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"bootstrap_brokers_sasl_scram": {
Type: schema.TypeString,
Computed: true,
},
"cluster_name": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -101,6 +105,7 @@ func dataSourceAwsMskClusterRead(d *schema.ResourceData, meta interface{}) error
d.Set("arn", aws.StringValue(cluster.ClusterArn))
d.Set("bootstrap_brokers", aws.StringValue(bootstrapBrokersoOutput.BootstrapBrokerString))
d.Set("bootstrap_brokers_tls", aws.StringValue(bootstrapBrokersoOutput.BootstrapBrokerStringTls))
d.Set("bootstrap_brokers_sasl_scram", aws.StringValue(bootstrapBrokersoOutput.BootstrapBrokerStringSaslScram))
d.Set("cluster_name", aws.StringValue(cluster.ClusterName))
d.Set("kafka_version", aws.StringValue(cluster.CurrentBrokerSoftwareInfo.KafkaVersion))
d.Set("number_of_broker_nodes", aws.Int64Value(cluster.NumberOfBrokerNodes))
Expand Down
1 change: 1 addition & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ func Provider() *schema.Provider {
"aws_media_store_container_policy": resourceAwsMediaStoreContainerPolicy(),
"aws_msk_cluster": resourceAwsMskCluster(),
"aws_msk_configuration": resourceAwsMskConfiguration(),
"aws_msk_sasl_scram_secret": resourceAwsMskScramSecret(),
anGie44 marked this conversation as resolved.
Show resolved Hide resolved
"aws_nat_gateway": resourceAwsNatGateway(),
"aws_network_acl": resourceAwsNetworkAcl(),
"aws_default_network_acl": resourceAwsDefaultNetworkAcl(),
Expand Down
52 changes: 50 additions & 2 deletions aws/resource_aws_msk_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func resourceAwsMskCluster() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"bootstrap_brokers_sasl_scram": {
Type: schema.TypeString,
Computed: true,
},
"broker_node_group_info": {
Type: schema.TypeList,
Required: true,
Expand Down Expand Up @@ -106,6 +110,19 @@ func resourceAwsMskCluster() *schema.Resource {
},
},
},
"sasl": {
dblooman marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeList,
Optional: true,
anGie44 marked this conversation as resolved.
Show resolved Hide resolved
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"scram": {
Type: schema.TypeBool,
Optional: true,
},
},
},
ConflictsWith: []string{"client_authentication.0.tls"},
},
},
},
},
Expand Down Expand Up @@ -439,6 +456,7 @@ func resourceAwsMskClusterRead(d *schema.ResourceData, meta interface{}) error {
d.Set("arn", aws.StringValue(cluster.ClusterArn))
d.Set("bootstrap_brokers", aws.StringValue(brokerOut.BootstrapBrokerString))
d.Set("bootstrap_brokers_tls", aws.StringValue(brokerOut.BootstrapBrokerStringTls))
d.Set("bootstrap_brokers_sasl_scram", aws.StringValue(brokerOut.BootstrapBrokerStringSaslScram))

if err := d.Set("broker_node_group_info", flattenMskBrokerNodeGroupInfo(cluster.BrokerNodeGroupInfo)); err != nil {
return fmt.Errorf("error setting broker_node_group_info: %s", err)
Expand Down Expand Up @@ -629,7 +647,8 @@ func expandMskClusterClientAuthentication(l []interface{}) *kafka.ClientAuthenti
m := l[0].(map[string]interface{})

ca := &kafka.ClientAuthentication{
Tls: expandMskClusterTls(m["tls"].([]interface{})),
Tls: expandMskClusterTls(m["tls"].([]interface{})),
Sasl: expandMskClusterScram(m["sasl"].([]interface{})),
}

return ca
Expand Down Expand Up @@ -699,6 +718,22 @@ func expandMskClusterTls(l []interface{}) *kafka.Tls {
return tls
}

func expandMskClusterScram(l []interface{}) *kafka.Sasl {
if len(l) == 0 || l[0] == nil {
return nil
}

m := l[0].(map[string]interface{})
anGie44 marked this conversation as resolved.
Show resolved Hide resolved

sasl := &kafka.Sasl{
Scram: &kafka.Scram{
Enabled: aws.Bool(m["scram"].(bool)),
},
}

return sasl
}

func expandMskOpenMonitoring(l []interface{}) *kafka.OpenMonitoringInfo {
if len(l) == 0 || l[0] == nil {
return nil
Expand Down Expand Up @@ -858,7 +893,8 @@ func flattenMskClientAuthentication(ca *kafka.ClientAuthentication) []map[string
}

m := map[string]interface{}{
"tls": flattenMskTls(ca.Tls),
"tls": flattenMskTls(ca.Tls),
"sasl": flattenMskSasl(ca.Sasl),
}

return []map[string]interface{}{m}
Expand Down Expand Up @@ -915,6 +951,18 @@ func flattenMskTls(tls *kafka.Tls) []map[string]interface{} {
return []map[string]interface{}{m}
}

func flattenMskSasl(sasl *kafka.Sasl) []map[string]interface{} {
if sasl == nil {
return []map[string]interface{}{}
}

m := map[string]interface{}{
"scram": aws.Bool(true),
}

return []map[string]interface{}{m}
}

func flattenMskOpenMonitoring(e *kafka.OpenMonitoring) []map[string]interface{} {
if e == nil {
return []map[string]interface{}{}
Expand Down
79 changes: 79 additions & 0 deletions aws/resource_aws_msk_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,37 @@ func TestAccAWSMskCluster_ClientAuthentication_Tls_CertificateAuthorityArns(t *t
})
}

func TestAccAWSMskCluster_ClientAuthentication_Sasl_Scram(t *testing.T) {
var cluster1 kafka.ClusterInfo
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_msk_cluster.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSMsk(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckMskClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccMskClusterConfigClientAuthenticationSaslScram(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckMskClusterExists(resourceName, &cluster1),
resource.TestCheckResourceAttr(resourceName, "client_authentication.#", "1"),
resource.TestCheckResourceAttr(resourceName, "client_authentication.0.sasl.0.scram", "1"),
anGie44 marked this conversation as resolved.
Show resolved Hide resolved
anGie44 marked this conversation as resolved.
Show resolved Hide resolved
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"bootstrap_brokers", // API may mutate ordering and selection of brokers to return
"bootstrap_brokers_tls", // API may mutate ordering and selection of brokers to return
},
},
},
})
}

func TestAccAWSMskCluster_ConfigurationInfo_Revision(t *testing.T) {

var cluster1, cluster2 kafka.ClusterInfo
Expand Down Expand Up @@ -792,6 +823,54 @@ resource "aws_msk_cluster" "test" {
`, rName)
}

func testAccMskClusterConfigClientAuthenticationSaslScram(rName string) string {
return testAccMskClusterBaseConfig() + fmt.Sprintf(`
resource "aws_secretsmanager_secret" "test" {
name = "AmazonMSK_test"
kms_key_id = aws_kms_key.test.key_id
}

resource "aws_secretsmanager_secret_version" "test" {
secret_id = aws_secretsmanager_secret.test.id
secret_string = jsonencode({ username = "%s", password = "foobar" })
}

resource "aws_kms_key" "test" {
description = "test"
}

resource "aws_msk_sasl_scram_secret" "test" {
cluster_arn = aws_msk_cluster.test.arn
secret_arn_list = [aws_secretsmanager_secret.test.arn]
}

resource "aws_msk_cluster" "test" {
cluster_name = %[1]q
kafka_version = "2.2.1"
number_of_broker_nodes = 3

broker_node_group_info {
client_subnets = [aws_subnet.example_subnet_az1.id, aws_subnet.example_subnet_az2.id, aws_subnet.example_subnet_az3.id]
ebs_volume_size = 10
instance_type = "kafka.m5.large"
security_groups = [aws_security_group.example_sg.id]
}

client_authentication {
sasl {
scram = true
}
}

encryption_info {
encryption_in_transit {
client_broker = "TLS"
}
}
}
`, rName)
}

func testAccMskClusterConfigConfigurationInfoRevision1(rName string) string {
return testAccMskClusterBaseConfig() + fmt.Sprintf(`
resource "aws_msk_configuration" "test" {
Expand Down
Loading