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

Print plan before apply #1304

Merged
merged 2 commits into from
Jun 18, 2024
Merged

Print plan before apply #1304

merged 2 commits into from
Jun 18, 2024

Conversation

akselleirv
Copy link
Collaborator

@akselleirv akselleirv commented Jun 4, 2024

Closes #1296

Example output after testing:

kubectl logs -n flux-system sensitive-output-test-tf-runner
2024/06/04 04:56:51 Starting the runner... version  sha
{"level":"info","ts":"2024-06-04T04:56:52.618Z","logger":"runner.terraform","msg":"preparing for Upload and Extraction","instance-id":""}
{"level":"info","ts":"2024-06-04T04:56:52.618Z","logger":"runner.terraform","msg":"write backend config","instance-id":"","path":"/tmp/flux-system-sensitive-output-test/sensitive-output-test","config":"backend_override.tf"}
{"level":"info","ts":"2024-06-04T04:56:52.618Z","logger":"runner.terraform","msg":"write config to file","instance-id":"","filePath":"/tmp/flux-system-sensitive-output-test/sensitive-output-test/backend_override.tf"}
{"level":"info","ts":"2024-06-04T04:56:52.619Z","logger":"runner.terraform","msg":"looking for path","instance-id":"","file":"terraform"}
{"level":"info","ts":"2024-06-04T04:56:52.619Z","logger":"runner.terraform","msg":"creating new terraform","instance-id":"e2f92e7e-3c1a-4a9a-9496-c0e2691e79f0","workingDir":"/tmp/flux-system-sensitive-output-test/sensitive-output-test","execPath":"/usr/local/bin/terraform"}
{"level":"info","ts":"2024-06-04T04:56:52.621Z","logger":"runner.terraform","msg":"setting envvars","instance-id":"e2f92e7e-3c1a-4a9a-9496-c0e2691e79f0"}
{"level":"info","ts":"2024-06-04T04:56:52.621Z","logger":"runner.terraform","msg":"getting envvars from os environments","instance-id":"e2f92e7e-3c1a-4a9a-9496-c0e2691e79f0"}
{"level":"info","ts":"2024-06-04T04:56:52.621Z","logger":"runner.terraform","msg":"setting up the input variables","instance-id":"e2f92e7e-3c1a-4a9a-9496-c0e2691e79f0"}
{"level":"info","ts":"2024-06-04T04:56:52.621Z","logger":"runner.terraform","msg":"mapping the Spec.Values","instance-id":"e2f92e7e-3c1a-4a9a-9496-c0e2691e79f0"}
{"level":"info","ts":"2024-06-04T04:56:52.621Z","logger":"runner.terraform","msg":"mapping the Spec.Vars","instance-id":"e2f92e7e-3c1a-4a9a-9496-c0e2691e79f0"}
{"level":"info","ts":"2024-06-04T04:56:52.621Z","logger":"runner.terraform","msg":"mapping the Spec.VarsFrom","instance-id":"e2f92e7e-3c1a-4a9a-9496-c0e2691e79f0"}
{"level":"info","ts":"2024-06-04T04:56:52.622Z","logger":"runner.terraform","msg":"generating the template founds"}
{"level":"info","ts":"2024-06-04T04:56:52.622Z","logger":"runner.terraform","msg":"main.tf.tpl not found, skipping"}
{"level":"info","ts":"2024-06-04T04:56:52.623Z","logger":"runner.terraform","msg":"initializing","instance-id":"e2f92e7e-3c1a-4a9a-9496-c0e2691e79f0"}
{"level":"info","ts":"2024-06-04T04:56:52.623Z","logger":"runner.terraform","msg":"mapping the Spec.BackendConfigsFrom","instance-id":"e2f92e7e-3c1a-4a9a-9496-c0e2691e79f0"}
{"level":"info","ts":"2024-06-04T04:56:54.235Z","logger":"runner.terraform","msg":"workspace select"}
{"level":"info","ts":"2024-06-04T04:56:54.236Z","logger":"runner.terraform","msg":"creating a plan","instance-id":"e2f92e7e-3c1a-4a9a-9496-c0e2691e79f0"}
{"level":"info","ts":"2024-06-04T04:56:54.399Z","logger":"runner.terraform","msg":"show the raw plan file","instance-id":"e2f92e7e-3c1a-4a9a-9496-c0e2691e79f0"}
{"level":"info","ts":"2024-06-04T04:56:54.488Z","logger":"runner.terraform","msg":"creating a plan","instance-id":"e2f92e7e-3c1a-4a9a-9496-c0e2691e79f0"}
{"level":"info","ts":"2024-06-04T04:56:54.704Z","logger":"runner.terraform","msg":"save the plan","instance-id":"e2f92e7e-3c1a-4a9a-9496-c0e2691e79f0"}
{"level":"info","ts":"2024-06-04T04:56:54.723Z","logger":"runner.terraform","msg":"loading plan from secret","instance-id":"e2f92e7e-3c1a-4a9a-9496-c0e2691e79f0"}
{"level":"info","ts":"2024-06-04T04:56:54.729Z","logger":"runner.terraform","msg":"running apply","instance-id":"e2f92e7e-3c1a-4a9a-9496-c0e2691e79f0"}

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # tls_private_key.example will be created
  + resource "tls_private_key" "example" {
      + algorithm                     = "ECDSA"
      + ecdsa_curve                   = "P224"
      + id                            = (known after apply)
      + private_key_openssh           = (sensitive value)
      + private_key_pem               = (sensitive value)
      + private_key_pem_pkcs8         = (sensitive value)
      + public_key_fingerprint_md5    = (known after apply)
      + public_key_fingerprint_sha256 = (known after apply)
      + public_key_openssh            = (known after apply)
      + public_key_pem                = (known after apply)
      + rsa_bits                      = 2048
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + hello_safe   = "Hello, World! I'm safe!"
  + hello_unsafe = (sensitive value)
  + private_key  = (sensitive value)

tls_private_key.example: Creating...
tls_private_key.example: Creation complete after 0s [id=4c819ec87937cfb17dc71c1dafde152c12c6bfd7]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Outputs:

hello_safe = "Hello, World! I'm safe!"
hello_unsafe = <sensitive>
private_key = <sensitive>
{"level":"info","ts":"2024-06-04T04:56:54.919Z","logger":"runner.terraform","msg":"creating outputs","instance-id":"e2f92e7e-3c1a-4a9a-9496-c0e2691e79f0"}
{"level":"info","ts":"2024-06-04T04:56:54.953Z","logger":"runner.terraform","msg":"cleanup TmpDir","instance-id":"e2f92e7e-3c1a-4a9a-9496-c0e2691e79f0","tmpDir":"/tmp/flux-system-sensitive-output-test"}

@akselleirv akselleirv requested a review from ilithanos June 4, 2024 05:11
@ilithanos
Copy link
Collaborator

The implementation looks good, but we should add a test case to ensure it works as intended even when we do changes later down the road

@akselleirv
Copy link
Collaborator Author

Added a test case for it @ilithanos :)

@akselleirv
Copy link
Collaborator Author

@ilithanos can you please give this a review again?

Copy link
Collaborator

@ilithanos ilithanos left a comment

Choose a reason for hiding this comment

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

Looks good :)

@akselleirv akselleirv merged commit bcf75fa into main Jun 18, 2024
15 checks passed
@akselleirv akselleirv deleted the print-plan branch June 18, 2024 14:09
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.

Detect what was applied historically
2 participants