Module: MuxTf::TerraformHelpers
- Includes:
- PiotrbCliUtils::ShellHelpers, PiotrbCliUtils::Util
- Included in:
- Cli::Current, Cli::PlanSummary, PlanFormatter, PlanSummaryHandler, PlanSummaryHandler, PlanUtils
- Defined in:
- lib/mux_tf/terraform_helpers.rb
Defined Under Namespace
Classes: ResultStruct
Instance Method Summary collapse
- #tf_apply(filename: nil, targets: []) ⇒ Object
- #tf_force_unlock(id:) ⇒ Object
- #tf_init(input: nil, upgrade: nil, reconfigure: nil, color: true, &block) ⇒ Object
-
#tf_plan(out:, color: true, detailed_exitcode: nil, compact_warnings: false, input: nil, targets: [], json: false, &block) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity.
- #tf_show(file, json: false, capture: false) ⇒ Object
- #tf_validate ⇒ Object
Instance Method Details
#tf_apply(filename: nil, targets: []) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mux_tf/terraform_helpers.rb', line 14 def tf_apply(filename: nil, targets: []) args = [] args << filename if filename if targets && !targets.empty? targets.each do |target| args << "-target=#{target}" end end cmd = tf_prepare_command(["apply", *args], need_auth: true) run_terraform(cmd) end |
#tf_force_unlock(id:) ⇒ Object
10 11 12 |
# File 'lib/mux_tf/terraform_helpers.rb', line 10 def tf_force_unlock(id:) run_terraform(tf_prepare_command(["force-unlock", "-force", id], need_auth: true)) end |
#tf_init(input: nil, upgrade: nil, reconfigure: nil, color: true, &block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mux_tf/terraform_helpers.rb', line 32 def tf_init(input: nil, upgrade: nil, reconfigure: nil, color: true, &block) args = [] args << "-input=#{input.inspect}" unless input.nil? args << "-upgrade" unless upgrade.nil? args << "-reconfigure" unless reconfigure.nil? args << "-no-color" unless color cmd = tf_prepare_command(["init", *args], need_auth: true) stream_or_run_terraform(cmd, &block) end |
#tf_plan(out:, color: true, detailed_exitcode: nil, compact_warnings: false, input: nil, targets: [], json: false, &block) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/mux_tf/terraform_helpers.rb', line 43 def tf_plan(out:, color: true, detailed_exitcode: nil, compact_warnings: false, input: nil, targets: [], json: false, &block) # rubocop:disable Metrics/CyclomaticComplexity args = [] args += ["-out", out] args << "-input=#{input.inspect}" unless input.nil? args << "-compact-warnings" if compact_warnings args << "-no-color" unless color args << "-detailed-exitcode" if detailed_exitcode args << "-json" if json if targets && !targets.empty? targets.each do |target| args << "-target=#{target}" end end cmd = tf_prepare_command(["plan", *args], need_auth: true) stream_or_run_terraform(cmd, split_streams: json, &block) end |
#tf_show(file, json: false, capture: false) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/mux_tf/terraform_helpers.rb', line 61 def tf_show(file, json: false, capture: false) if json args = ["show", "-json", file] cmd = tf_prepare_command(args, need_auth: true) capture_terraform(cmd, json: true) else args = ["show", file] cmd = tf_prepare_command(args, need_auth: true) if capture capture_terraform(cmd) else run_terraform(cmd) end end end |
#tf_validate ⇒ Object
27 28 29 30 |
# File 'lib/mux_tf/terraform_helpers.rb', line 27 def tf_validate cmd = tf_prepare_command(["validate", "-json"], need_auth: true) capture_terraform(cmd, json: true) end |