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

Initial add of MSK resources #6809

Closed
wants to merge 12 commits into from
Closed

Conversation

jrefi
Copy link

@jrefi jrefi commented Dec 11, 2018

Fixes #6653

Changes proposed in this pull request:

  • Add aws_msk_cluster resource to support Managed Streams for Kafka.

TODO:

  • Bubble up cluster connection info to output
  • [x ] Flesh out acceptance tests
  • Handle resource updates (currently not supported in MSK API)

Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccAWSMskCluster'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./... -v -parallel 20 -run=TestAccAWSMskCluster -timeout 120m
?   	github.com/terraform-providers/terraform-provider-aws	[no test files]
=== RUN   TestAccAWSMskClusterDataSource
=== PAUSE TestAccAWSMskClusterDataSource
=== RUN   TestAccAWSMskCluster_basic
=== PAUSE TestAccAWSMskCluster_basic
=== RUN   TestAccAWSMskCluster_encryptAtRest
=== PAUSE TestAccAWSMskCluster_encryptAtRest
=== RUN   TestAccAWSMskCluster_brokerMonitoring
=== PAUSE TestAccAWSMskCluster_brokerMonitoring
=== CONT  TestAccAWSMskClusterDataSource
=== CONT  TestAccAWSMskCluster_brokerMonitoring
=== CONT  TestAccAWSMskCluster_encryptAtRest
=== CONT  TestAccAWSMskCluster_basic
--- PASS: TestAccAWSMskCluster_brokerMonitoring (912.39s)
--- PASS: TestAccAWSMskClusterDataSource (917.71s)
--- PASS: TestAccAWSMskCluster_basic (922.73s)
--- PASS: TestAccAWSMskCluster_encryptAtRest (1005.67s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	1005.689s

Example Resource configuration:

resource "aws_msk_cluster" "test_cluster" {
	name = "terraform-msk-test-%d"
	broker_count = 3
	broker_instance_type = "kafka.m5.large"
	broker_volume_size = 10
	broker_security_groups =["${aws_security_group.test_sg_a.id}"]
	client_subnets = ["${aws_subnet.test_subnet_a.id}", "${aws_subnet.test_subnet_b.id}", "${aws_subnet.test_subnet_c.id}"]
}

@ghost ghost added size/M Managed by automation to categorize the size of a PR. provider Pertains to the provider itself, rather than any interaction with AWS. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. size/XL Managed by automation to categorize the size of a PR. and removed size/M Managed by automation to categorize the size of a PR. labels Dec 11, 2018
@bflad bflad added new-resource Introduces a new resource. service/kafka Issues and PRs that pertain to the kafka service. labels Dec 11, 2018
@bflad
Copy link
Contributor

bflad commented Dec 11, 2018

Related: #6655

@jrefi jrefi changed the title Initial add of MSK reources Initial add of MSK resources Dec 12, 2018
aws/config.go Outdated Show resolved Hide resolved
Copy link
Contributor

@tomelliff tomelliff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good to me, particularly for a first contribution but there's a few things I picked up on in a short review.

}

func resourceAwsMskClusterUpdate(d *schema.ResourceData, meta interface{}) error {
// TODO: Figure out update as API calls not yet implemented
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the API doesn't provide update calls then you need to ditch this and just use ForceNew on everything for now. If AWS eventually adds updating a MSK cluster then someone will be able to update this resource to support updates.

As an example, here's the ECS task definition resource before tagging was added (making it no longer just an immutable resource): https://github.com/terraform-providers/terraform-provider-aws/blob/f7c0899ca731c70659eb6b8e40ea520d095ffb1c/aws/resource_aws_ecs_task_definition.go

aws/data_source_aws_mks_cluster.go Outdated Show resolved Hide resolved
aws/resource_aws_msk_cluster.go Outdated Show resolved Hide resolved
aws/resource_aws_msk_cluster.go Outdated Show resolved Hide resolved
aws/resource_aws_msk_cluster.go Outdated Show resolved Hide resolved
aws/resource_aws_msk_cluster.go Outdated Show resolved Hide resolved
Delete: resourceAwsMskClusterDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing a test for this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what this actually does or how to test it. Didnt see an example elsewhere in the codebase.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomelliff there is only this issue before merging to master?

d.Set("arn", state.arn)
d.Set("status", state.status)
d.Set("creation_timestamp", state.creationTimestamp)
d.Set("encrypt_rest_arn", state.encryptRestArn)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've used encrypt_rest_key in the schema here but set this to encrypt_rest_arn which is what you're using elsewhere. Personally I find the encryptRestArn to be slightly confusing without any mention that it's the KMS key ARN and had to check the source to see that that was the case so I'd switch everything over to encrypt_rest_key or some variant on that.

Also it might help to add an acceptance test for this data source even if you are just exercising the same method as the read on the resource just to catch mistakes in the schema like this.

aws/data_source_aws_mks_cluster.go Outdated Show resolved Hide resolved
aws/data_source_aws_mks_cluster.go Outdated Show resolved Hide resolved
@jrefi
Copy link
Author

jrefi commented Jan 4, 2019

@tomelliff Thanks for the feedback. As this is my first contribution, I'm still trying to figure out how the whole system works. Your comments are very helpful.

I am a little ignorant about how ForceNew works. Is the user warned before action is taken? I'm concerned about the possibility of data loss occurring if the user changes something minor on their cluster.

@tomelliff
Copy link
Contributor

The plan will show a +- against the resource to show that it needs to be destroyed and recreated. There is also a (forces new resource) against any changing attributes that cause Terraform to force a rebuild and it's a very common pattern across a wide set of resources so shouldn't come across as a surprise to the user.

Of course if you set everything as ForceNew and build it you should be able to see the results for yourself.

@ghost ghost added the documentation Introduces or discusses updates to documentation. label Jan 23, 2019
* `broker_count` - (Required) Number of broker nodes you want to create in each Availability Zone.
* `broker_instance_type` - (Required) Instance type for brokers from the m5 family. e.g. kafka.m5.large
* `broker_volume_size` - (Required) The size of the drive in GiBs.
* `broker_security_groups` - (Optional) Security groups to attach to broker nodes.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

required

Delete: resourceAwsMskClusterDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomelliff there is only this issue before merging to master?

@gavinmbell
Copy link

👍 this would be a great thing to have. I fully support this endeavor as I have a project coming on line that would be able to leverage this immediately.

@kesensoy
Copy link

@gavinmbell I agree, we need to find out how we can encourage the final reviews (like from @mrf and @tomelliff) before this becomes a dead PR. I've also tried posting in the IRC room to no avail.

@landondao1
Copy link

+1 This is a really great feature. After AWS went live with MSK, I was pretty excited. I'm an SUPER excited to see this get implemented into terraform to make automated deployments work with MSK.

Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jrefi 👋 Thanks for submitting this. Please see the below initial feedback and let us know if you have any questions or do not have time to implement the items.

@@ -159,6 +159,7 @@ type Config struct {
EsEndpoint string
ElbEndpoint string
IamEndpoint string
KafkaEndpoint string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some additional configuration steps required to support customizing service endpoints. We have opted to allow customizing all endpoints (#8096) so this change should be removed from this pull request. 👍

@@ -937,6 +939,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
config.ElbEndpoint = endpoints["elb"].(string)
config.EsEndpoint = endpoints["es"].(string)
config.IamEndpoint = endpoints["iam"].(string)
config.KafkaEndpoint = endpoints["kafka"].(string)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted above, this change should be removed from this pull request.

},
"broker_node_group_info": {
Type: schema.TypeString,
Optional: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: true should be removed/replaced with only Computed: true for this and all the below attributes since they are not configurable to influence the data source lookup.

Config: config,
Check: resource.ComposeTestCheckFunc(
testAccCheckMskClusterExists("aws_msk_cluster.test_cluster", &cluster),
resource.TestCheckResourceAttrSet("data.aws_msk_cluster.test_cluster", "arn"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data source testing should preferably use resource.TestCheckResourceAttrPair() to ensure values match between the resource and data source, e.g.

Suggested change
resource.TestCheckResourceAttrSet("data.aws_msk_cluster.test_cluster", "arn"),
resource.TestCheckResourceAttrPair("data.aws_msk_cluster.test_cluster", "arn", "aws_msk_cluster.test_cluster", "arn"),

This should be done for all data source attribute checks.

resource "aws_subnet" "test_subnet_a" {
vpc_id = "${aws_vpc.test_vpc.id}"
cidr_block = "10.1.1.0/24"
availability_zone = "us-east-1a"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The acceptance testing framework for the provider runs in us-west-2 by default:

https://github.com/terraform-providers/terraform-provider-aws/blob/ffa6d70f31746ea626abe6a7d3a4398a9a77e4ef/aws/provider_test.go#L180-L186

Hardcoded availability zones should instead be replaced with the aws_availability_zones data source.

---
layout: "aws"
page_title: "AWS: aws_msk_cluster"
sidebar_current: "docs-aws-resource-msk-cluster"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This documentation page is missing a sidebar link in a new MSK Resources section of website/aws.erb


## Attributes Reference

See the [`aws_msk_cluster` resource](/docs/providers/aws/r/msk_cluster.html) for details on the returned attributes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data source attributes can easily become out of sync with their resource counterpart since they require a separate schema definition and appropriate d.Set() calls. We prefer to list out the attributes separately.

* `broker_instance_type` - (Required) Instance type for brokers from the m5 family. e.g. kafka.m5.large
* `broker_volume_size` - (Required) The size of the drive in GiBs.
* `broker_security_groups` - (Required) Security groups to attach to broker nodes.
* `encrypt_rest_arn` - (Optional)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This argument is missing documentation.

},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(60 * time.Minute),
Update: schema.DefaultTimeout(120 * time.Minute),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This resource does not implement the Update function so this should be removed.

* `encrypt_rest_key` - The AWS KMS key used for data encryption.
* `zookeeper_connect` - Connection string for Zookeeper.
* `bootstrap_brokers` - A list of brokers that a client application can use to bootstrap.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation for the customizable timeouts is missing:

Suggested change
## Timeouts
`aws_msk_cluster` provides the following [Timeouts](/docs/configuration/resources.html#timeouts) configuration options:
* `create` - (Default `60m`) How long to wait for cluster creation.
* `delete` - (Default `120m`) How long to wait for cluster deletion.

@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Mar 29, 2019
@kesensoy
Copy link

@bflad thank you for the review! I would undertake a lot of the simple fixes myself but I don't want to mess anything up without go knowledge or a working testing env. I'll see if @jrefi still wants to take this one across the finish line!

@ghost ghost removed the waiting-response Maintainers are waiting on response from community or contributor. label Mar 29, 2019
@dthtvwls
Copy link

dthtvwls commented Apr 3, 2019

@jrefi If you are low on time/resources, please let me know I would be happy to take a handoff from you and address feedback myself.

@jrefi
Copy link
Author

jrefi commented Apr 3, 2019

@dthtvwls Thanks. Yeah, actually my organization has decided that MSK is not yet a viable option for us and thus this is no longer a priority. If you don't mind cleaning the PR up, I would greatly appreciate it.

@kesensoy
Copy link

kesensoy commented Apr 4, 2019

@dthtvwls Please let us know if you will be able to get this merged, else I will continue to search for more contributors! If anyone wants to be reminded of how much people are eagerly awaiting this feature, it is the second most 'reacted to' issue on the platform right now :) #6653

@dthtvwls
Copy link

dthtvwls commented Apr 5, 2019

@kesensoy I will certainly do what I can. I am working through @bflad's feedback on my own fork. Not really sure of the preferred way to handle the changes here though. Should I create a new PR? If anyone can say, please do, thanks.

@bflad
Copy link
Contributor

bflad commented Apr 5, 2019

@dthtvwls a new PR is totally fine (preserving the previous authors commits where possible) 👍

@dthtvwls
Copy link

@bflad I just left a review. One more question before I make the new PR. Thanks

dthtvwls added a commit to dthtvwls/terraform-provider-aws that referenced this pull request Apr 17, 2019
@dthtvwls dthtvwls mentioned this pull request Apr 17, 2019
@dthtvwls
Copy link

Please see #8357 which now supersedes this request.

ewbankkit pushed a commit to ewbankkit/terraform-provider-aws that referenced this pull request Apr 30, 2019
@bflad
Copy link
Contributor

bflad commented May 22, 2019

We just merged in #8635 which will release with version 2.12.0 of the Terraform AWS Provider. Thanks @jrefi and @dthtvwls for your efforts here!

@bflad bflad closed this May 22, 2019
@ghost
Copy link

ghost commented Mar 30, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. new-resource Introduces a new resource. provider Pertains to the provider itself, rather than any interaction with AWS. service/kafka Issues and PRs that pertain to the kafka service. size/XL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Managed Streaming for Kafka
10 participants