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

Adding support for Terraform plan target #97

Merged
merged 4 commits into from
Apr 3, 2024

Conversation

trutled3
Copy link
Contributor

@trutled3 trutled3 commented Mar 26, 2024

Description

This pull request adds the capability to create a Terraform run using the target option to focus Terraform to specific resources.

Testing plan

Build tfci, go build
export TF_API_TOKEN=<TOKEN>
export TF_CLOUD_ORGANIZATION=<ORG>
Run tfci, tfci -hostname=<HOST> -organization=<ORG> run create -workspace=<WORKSPACE> -target-addr=aws_instance.foo

External links

…orm. Added new flag under run_create.go and run.go to add support for providing Terraform targets to the run.
…uns. Updated run_create and run documentation for target.
@trutled3 trutled3 requested a review from a team as a code owner March 26, 2024 17:51
@trutled3 trutled3 requested a review from zainq11 March 26, 2024 17:51
@mjyocca mjyocca self-requested a review April 1, 2024 16:46
@mjyocca
Copy link
Contributor

mjyocca commented Apr 1, 2024

@trutled3 Thanks for opening a PR and adding a test case! My team and I will review this today.

…string return a string representation of the value of the flag within the flagStringSlice.String() function.
@trutled3
Copy link
Contributor Author

trutled3 commented Apr 1, 2024

I have updated the PR with your suggestions, thank you again @zainq11 & @mjyocca !

…t=aws_resourrce.test_2,aws_resource.test_3 or --target=aws_resource.test --target=aws_resourrce.test_2,aws_resource.test_3
@trutled3
Copy link
Contributor Author

trutled3 commented Apr 2, 2024

Great catch @mjyocca . I've made that change and verified on my end. It is ready for your review!

@mjyocca
Copy link
Contributor

mjyocca commented Apr 2, 2024

Great catch @mjyocca . I've made that change and verified on my end. It is ready for your review!

Awesome thank you for doing that!

Also out of curiosity. What sort of workflows or scenarios from an automation standpoint will this enable for you? (Example for GitHub Actions, dispatch a workflow passing in the target resources etc.)

@trutled3
Copy link
Contributor Author

trutled3 commented Apr 2, 2024

Certainly @mjyocca ! That is my mistake for not including that in my PR. The TLDR is that this allows us to target specific resources to update as part of a development lifecycle without affecting other resources in the same Terraform deployment.

I have a few use cases that largely surround have a resource managed with Terraform however updating a specific resource as part of another CI CD process such as building and deploying a new image version to my AWS ECR and then update the resources that leverage this image automatically as part of my CI CD lifecycle. The targeted plan allows for planning changes to just the particular resources instead of planning the entire deployment which may have other working changes that we don't want deployed.

Another use case I have is building and releasing new lambda layer versions, and then updating the associated lambdas to use that newly released lambda layer version by updating the a variable the Terraform deployment uses and having Terraform update the Lambda with that new layer version.

@mjyocca mjyocca self-requested a review April 2, 2024 20:32
@mjyocca
Copy link
Contributor

mjyocca commented Apr 2, 2024

Certainly @mjyocca ! That is my mistake for not including that in my PR. The TLDR is that this allows us to target specific resources to update as part of a development lifecycle without affecting other resources in the same Terraform deployment.

I have a few use cases that largely surround have a resource managed with Terraform however updating a specific resource as part of another CI CD process such as building and deploying a new image version to my AWS ECR and then update the resources that leverage this image automatically as part of my CI CD lifecycle. The targeted plan allows for planning changes to just the particular resources instead of planning the entire deployment which may have other working changes that we don't want deployed.

Another use case I have is building and releasing new lambda layer versions, and then updating the associated lambdas to use that newly released lambda layer version by updating the a variable the Terraform deployment uses and having Terraform update the Lambda with that new layer version.

I see thanks for clarifying!

Copy link
Contributor

@zainq11 zainq11 left a comment

Choose a reason for hiding this comment

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

LGTM

@trutled3
Copy link
Contributor Author

trutled3 commented Apr 3, 2024

Thanks @mjyocca and @zainq11 for letting me contribute to this repository!

@mjyocca mjyocca merged commit 84d2d87 into hashicorp:main Apr 3, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants