-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
provider/aws: Elastic Beanstalk Application Version #5770
provider/aws: Elastic Beanstalk Application Version #5770
Conversation
s3Location := elasticbeanstalk.S3Location{ | ||
S3Bucket: aws.String(bucket), | ||
S3Key: aws.String(key), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If bucket
is optional, what happens here if the User omits it from the config? I assume a failure in the CreateApplicationVersion
call. We need to conditionally added this, if that is the case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to make bucket and key required for the reasons discussed below on the documentation note.
This is a great start! I added some comments that need addressed before we merge. Regarding your comments on tests: you're correct, we can do those things, however testing time is less of a focus for us now that we have our acceptance tests running nightly. We may cross that bridge in the future though, and I appreciate your thoughts/consideration there 😄 Thanks! |
@catsby Thanks for the feedback! I should be able to get to all of this today. |
I may have come across a small issue for some common use cases. In our case we create a unique application version per release, so we aren't really sharing versions across multiple environments. In this case, we don't have any issues because after we create the new application version, the old one can get cleaned up by Terraform. Where this causes problems is a situation like this: Version "A" is deployed to development and production - No issues here yet A couple ideas on dealing with this issue:
|
I've used Elastic Beanstalk extensively in our organization, personally authored a deployment framework for managing the packaging and deprecation of application versions. The challenge in our organization is that we have multiple environments per stack - so simply deleting the last The solution we came up with was programmatic, we had to derive the environment name from the application version name and generate a hash map for those environments to determine which application versions to delete. One might argue that this type of work is better suited for something other than terraform. I would submit that managing the deprecation and removal of stale application versions is outside of the scope of the Also, Beanstalk won't let you delete a version which is actively deployed to a stack. |
Looking forward to this. Agree with @KCrawley definitely need to ensure application versions are not removed each time. A similar comment could be made for the API Gateway deployments too. |
@KCrawley and @bobbydeveaux thanks for the feedback. I agree that cleaning up the application versions is beyond the current scope of Terraform. I tried a few different ways and was never really happy with the results. The issue comes down to differences between Terraform's and Elastic Beanstalk's "view" of the world. A Terraform state file is going to correlate to one environment(generally), while a Beanstalk Application can include multiple environments, and resources shared across those environments. So, the real problem here is that Terraform is trying to manage resources that aren't in its dependency graph, which gets really messy. Until there is a better way to manage those types of resources we could make the delete function essentially a noop, and notify the user that old application versions are not cleaned up by Terraform. @catsby how does that sound to you? |
@dharrisio If the application version is not present yet, it gets created, and that is something simple enough to reason about. Deleting versions, there be dragons. This can be better solved with a remove-unused-elastic-beanstalk-versions task in a delivery pipeline, which can be tweaked and customized to taste. Ie. not Terraform's responsibility, me thinks. |
Hi, when will we have this in the master? |
I provided an updated rebase PR for this: #7407 to speed up the inclusion of this into master, I also need it urgently. |
The current issue here is not really about rebasing. From the issues discussed above, I'm not sure that this should really be in master any time soon. Because there really isn't a good way to manage application versions I'm not sure that this resource is a good fit for Terraform. From what has been discussed so far, there are two options for including this as a resource:
I think uploading new application versions will be best handled outside of Terraform. For now, I think adding the |
I'm new to both terraform and elastic beanstalk, so please bear with me. Why does adding an If environment A is using version 1 and environment B is using version 2, terraform shouldn't delete either version. When environment A is updated to use version 2, terraform can delete version 1. What am I missing? |
@cwarden When Terraform updates environment B to use version2, it will delete version1, create version2 (it can do this the other way around too with So we would never really be able to get to a state you described, which as you mentioned doesn't really present the problem. Hope this helps clear that up for you. |
@dharrisio beanstalk won't let you delete versions which are deployed to an environment. the main issue which is addressed by this PR (for myself) is when creating a new beanstalk application and environment it is required to have an application version which is compatible with the stack (and will pass health checks if they're turned on). even if the ability to create application versions is removed it should be, at a minimum, possible to attach a zip or s3 reference to the newly created resource. |
My mental model must be wrong. I'm assuming terraform works like this:
Why, when terraform updates environment B to version 2, the dependency upon version 1 by environment A doesn't prevent version 1 from being deleted? Using alternative resources as an example, if two |
That seems like a great analogy if that's the case! FWIW, a work-around we're using is an idempotent script to upload and deploy the application, and use a "local-exec" provisioner to run it. Here's an example tf and deploy script for Jenkins: https://gist.github.com/mrooney/79d80e262c6c9d484c5e1e2130f8b917 |
If the modifed
This is along the lines of what I was thinking. |
@catsby Any chance we could get this looked at soon? |
Can this be merged soon please? |
Having only just dived into terraform and beanstalk and hit the block of initial app version, I would recommend keeping all versions the user wants to keep as explicit resources, i.e. have And do I understand correctly that AWS does not stop you from deleting a app version still in use? That's a bummer, can we add a warning in the planning stage? |
Any update on the progress of this getting to master? |
The Elastic Beanstalk API call to delete `application_version` resource should not delete the s3 bundle, as this object is managed by another Terraform resource
Adds test that fails after rebasing branch onto v0.8.x. `version_label` changes do not update the `aws_elastic_beanstalk_environment` resource.
Prevents an `application_version` used by multiple environments from being deleted.
3d71f5b
to
c2b9c0b
Compare
@stack72 I added a check to return an error when an Application Version is in use by more than one environment, as well as an attribute to force delete the resource if necessary. Here is my output from the tests, the one that failed is due to a missing solution stack in my account.
|
this LGTM! Thanks for all the work on this @dharrisio :) Sorry it took so long to get merged Paul |
* Added new resource aws_elastic_beanstalk_application_version. * Changing bucket and key to required. * Update to use d.Id() directly in DescribeApplicationVersions. * Checking err to make sure that the application version is successfully deleted. * Update `version_label` to `Computed: true`. * provider/aws: Updating to python solution stack * provider/aws: Beanstalk App Version delete source The Elastic Beanstalk API call to delete `application_version` resource should not delete the s3 bundle, as this object is managed by another Terraform resource * provider/aws: Update application version docs * Fix application version test * Add `version_label` update test Adds test that fails after rebasing branch onto v0.8.x. `version_label` changes do not update the `aws_elastic_beanstalk_environment` resource. * `version_label` changes to update environment * Prevent unintended delete of `application_version` Prevents an `application_version` used by multiple environments from being deleted. * Add `force_delete` attribute * Update documentation
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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
This is a rebased version of #3871.
This adds support for Elastic Beanstalk Application Versions.
Example Terraform document
Tests
The changes to
resourceAwsElasticBeanstalkEnvironmentUpdate
might not appear to be related to the Application Version resource. The reason I made those changes is that the currentresourceAwsElasticBeanstalkEnvironmentUpdate
function fails when trying to update theversion_label
anddescription
in the same Terraform plan.UpdateEnvironment
will return immediately, set the environment state to 'Updating' and move on the next update. Thissecond update will fail, because
UpdateEnvironment
can only be called when the environment state is 'Ready'. I Updated theresourceAwsElasticBeanstalkEnvironmentUpdate
func to put all of the updates in oneUpdateEnvironmentInput
struct. Instead of making multiple update calls, this updates all the resource attributes in one call. The alternative is to wait for the Beanstalk Environment state to be 'Ready' after updating each attribute.While working on this, I've been thinking about the tests for the Beanstalk resources. As you can see above the tests took about 20 minutes, I expect this to get even longer as I have a few other changes I'll be submitting soon (with more tests).
There are a few ways to speed them up.
Any thoughts on that would be appreciated!