-
-
Notifications
You must be signed in to change notification settings - Fork 652
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
run terraform plan
when setting --dry-run
flag on experimental-deploy
goal
#20488
run terraform plan
when setting --dry-run
flag on experimental-deploy
goal
#20488
Conversation
Hey, Thanks for the PR! I'm not too familiar with the terraform backend, so I'll hold off reviewing it for another maintainer/contributor who's more well-versed in that. With that said, I'd like to leave a few thoughts as someone "in the vincinity" -- I build a k8s plugin. There's a whole set of verbs that make sense in the infrastructure domain that don't necessarily map well to Pants actions. This was raised in the original topic as well. In a fully pants-managed world, what does the user-story look like there? Going further, what about And taking that one step further... What I do right now without adopting |
Good points @tgolsson! The infra and Pants domains do not map really well indeed. I went with the What to do with other operations such as Let's see what other maintainers have to say about it. |
you can run it for multiple targets I think, |
I have to wrap my head around what that means. We are not yet using Pants. I am investigating how our codebase with lots of terraform, lots of python, and some docker can be managed using Pants. |
Thanks for the contribution! I had a quick look and it looks good. I'll be able to do a full review tomorrow.
I think it makes sense to add As for all the extra verbs, I think that at some point it's reasonable to eject from Pants with I'm not sure how much discussion has to happen before we could merge this. That is, I'm hoping that we don't have to hash out exactly what's common enough to standardise and what should be left to backends, as I think |
Thanks for the feedback @lilatomic !
Yes I think so too. In that case, I’ll extend the PR tomorrow to make sure Helm also uses this flag rather than the passthrough arguments.
This will be something for another PR / issue then.
Not sure how the decision making works here. For me the current idea of the dry-run flag is sufficient for our terraform needs right now.
From a quick search I could only find helm and terraform as targets for deploy, but please correct me if I’m wrong. If I’m right, then we can omit this field for now, since both helm and terraform support dry running. |
@lilatomic based on our discussion yesterday I changed helm to use the new goal-level flag as well. |
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.
Thank you for the MR! It looks good to me. I appreciate the thorough tests.
I'll see about getting the CI running and a review from a Maintainer.
@@ -165,7 +164,7 @@ class HelmSubsystem(TemplatedExternalTool): | |||
) | |||
|
|||
args = ArgsListOption( | |||
example="--dry-run", | |||
example="--force", |
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.
I think we should also mention the correct way to pass --dry-run
, something like:
use the
--experimental-deploy-dry-run
flag to pass--dry-run
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.
Good catch. I added it in another place, but I think that was an error message. Added it to this description as well.
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.
Also added information on dry-running into the helm and terraform docs.
ping @alonsodomin @lilatomic |
Sorry for the delay chiming on here. The addition of the The implementation here looks good to me but leaves me wondering if it's enough. Meaning that when we normally want to run in a dry run mode we expect to get some output from the tool apart from just an OK or KO return code. As is right now I believe that output will be omitted (current implementation of the goal only prints if the action succeeded or not). I think we should make the On the wider topic of the existence of the At the moment it's true that That PR is currently parked until I find the time to come up with a better idea (or we totally give up on PS: Sorry for the wall of text. |
Thanks for the review @alonsodomin . If I understand you correctly the only thing we have to do for this PR is the printing of the output. I'm not sure what exactly is missing here, because for Can you elaborate what's still needed? Do we perhaps need to disable something on the Terraform backend and move that to the Deploy goal? ❯ PANTS_SOURCE=../pants pants experimental-deploy --dry-run ::
Pantsd has been turned off via Env.
15:41:39.32 [INFO] Deploying targets...
module.lambda_function.data.aws_region.current: Reading...
module.lambda_function.data.aws_caller_identity.current: Reading...
module.lambda_function.data.aws_region.current: Read complete after 0s [id=eu-west-1]
module.lambda_function.data.aws_iam_policy_document.assume_role[0]: Reading...
module.some_cool_module.data.aws_iam_policy_document.test_assume_role: Reading...
module.lambda_function.data.aws_partition.current: Reading...
module.lambda_function.data.aws_iam_policy_document.assume_role[0]: Read complete after 0s [id=2690255455]
module.some_cool_module.data.aws_iam_policy_document.test_assume_role: Read complete after 0s [id=1229436035]
module.lambda_function.data.aws_partition.current: Read complete after 0s [id=aws]
module.lambda_function.data.aws_caller_identity.current: Read complete after 0s [id=740837425924]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
<= read (data resources)
Terraform will perform the following actions:
# module.lambda_function.data.aws_iam_policy_document.logs[0] will be read during apply
# (config refers to values not yet known)
<= data "aws_iam_policy_document" "logs" {
+ id = (known after apply)
+ json = (known after apply)
+ statement {
+ actions = [
+ "logs:CreateLogGroup",
+ "logs:CreateLogStream",
+ "logs:PutLogEvents",
]
+ effect = "Allow"
+ resources = (known after apply)
}
}
# module.lambda_function.aws_cloudwatch_log_group.lambda[0] will be created
+ resource "aws_cloudwatch_log_group" "lambda" {
+ arn = (known after apply)
+ id = (known after apply)
+ log_group_class = (known after apply)
+ name = "/aws/lambda/my-lambda1"
+ name_prefix = (known after apply)
+ retention_in_days = 0
+ skip_destroy = false
+ tags_all = (known after apply)
}
# module.lambda_function.aws_iam_policy.logs[0] will be created
+ resource "aws_iam_policy" "logs" {
+ arn = (known after apply)
+ id = (known after apply)
+ name = "my-lambda1-logs"
+ name_prefix = (known after apply)
+ path = "/"
+ policy = (known after apply)
+ policy_id = (known after apply)
+ tags_all = (known after apply)
}
# module.lambda_function.aws_iam_role.lambda[0] will be created
+ resource "aws_iam_role" "lambda" {
+ arn = (known after apply)
+ assume_role_policy = jsonencode(
{
+ Statement = [
+ {
+ Action = "sts:AssumeRole"
+ Effect = "Allow"
+ Principal = {
+ Service = "lambda.amazonaws.com"
}
},
]
+ Version = "2012-10-17"
}
)
+ create_date = (known after apply)
+ force_detach_policies = true
+ id = (known after apply)
+ managed_policy_arns = (known after apply)
+ max_session_duration = 3600
+ name = "my-lambda1"
+ name_prefix = (known after apply)
+ path = "/"
+ tags_all = (known after apply)
+ unique_id = (known after apply)
}
# module.lambda_function.aws_iam_role_policy_attachment.logs[0] will be created
+ resource "aws_iam_role_policy_attachment" "logs" {
+ id = (known after apply)
+ policy_arn = (known after apply)
+ role = "my-lambda1"
}
# module.lambda_function.aws_lambda_function.this[0] will be created
+ resource "aws_lambda_function" "this" {
+ architectures = (known after apply)
+ arn = (known after apply)
+ description = "My awesome lambda function"
+ filename = "../../../dist/src.python.some_lambda/lambda.zip"
+ function_name = "my-lambda1"
+ handler = "lambda_function.handler"
+ id = (known after apply)
+ invoke_arn = (known after apply)
+ last_modified = (known after apply)
+ memory_size = 128
+ package_type = "Zip"
+ publish = false
+ qualified_arn = (known after apply)
+ qualified_invoke_arn = (known after apply)
+ reserved_concurrent_executions = -1
+ role = (known after apply)
+ runtime = "python3.9"
+ signing_job_arn = (known after apply)
+ signing_profile_version_arn = (known after apply)
+ skip_destroy = false
+ source_code_hash = (known after apply)
+ source_code_size = (known after apply)
+ tags_all = (known after apply)
+ timeout = 3
+ version = (known after apply)
+ ephemeral_storage {
+ size = 512
}
+ logging_config {
+ log_format = "Text"
+ log_group = (known after apply)
}
}
# module.some_cool_module.aws_iam_role.test will be created
+ resource "aws_iam_role" "test" {
+ arn = (known after apply)
+ assume_role_policy = jsonencode(
{
+ Statement = [
+ {
+ Action = "sts:AssumeRole"
+ Effect = "Allow"
+ Principal = {
+ Service = "codebuild.amazonaws.com"
}
},
]
+ Version = "2012-10-17"
}
)
+ create_date = (known after apply)
+ force_detach_policies = false
+ id = (known after apply)
+ managed_policy_arns = (known after apply)
+ max_session_duration = 3600
+ name = "test-pants-role"
+ name_prefix = (known after apply)
+ path = "/"
+ tags_all = (known after apply)
+ unique_id = (known after apply)
}
Plan: 6 to add, 0 to change, 0 to destroy.
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now.
✓ src/terraform/some_cool_root_module:some_cool_root_module_deployment deployed |
agh, my bad, was checking the implementation of the deploy goal in core and assumed the output was not being emitted. It's ok as it is. |
@alonsodomin ping. The CI passes. Do you need me to merge main into this? can you get PR merged? |
just approved and merged, many thanks! |
Thanks again for the contribution! |
Changed the following things to achieve this
--dry-run
flag to theexperimental-deploy
goal to handle dry runs such asterraform plan
plan
rather thanapply
when setting the--dry-run
flag while deploying aterraform_deployment
--dry-run
flag instead of a passthrough arg for dry-runningTested
Closes #18490