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

Retire terraform runner stack #71

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

putmanoj
Copy link
Contributor

@putmanoj putmanoj commented Sep 4, 2024

  • The destroy(retire) api from terraform-runner, uses terraform-template,input-vars from provision action. And needs stack_id created in provision action.

    • template_id & input-vars are available in the Service instance, whereas stack_id available in Job instance.
    • As 'Retirement' action is triggered from 'My Services' page, we need the stack_id in Services,
    • So updating the Service instance with stack_id in Job class, to use later when 'Retirement' is triggered.
  • The Terraform::Runner runs 'Retirement' action with same run/run_async method

    • when additional vars are added ie. :miq_action => 'Retirement' & :miq_terraform_stack_id => '<stack_id from terraform-runner>', otherwise runs 'Provision' action.

Comment on lines +40 to +41
if template_id.nil? && action.downcase == 'retirement'
template_id = config_info.dig(:provision, :configuration_script_payload_id)
Copy link
Member

Choose a reason for hiding this comment

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

Is this saying that when doing retirement use the provisioning workflow?

Choose a reason for hiding this comment

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

By default, for terraform , same terraform template files, vars, but different action, ie when 'Retirement' action -> run destroy

Copy link
Member

Choose a reason for hiding this comment

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

Could we set the configuration script payload on the retirement resource_action also so this would "just work" ?

lib/terraform/runner.rb Outdated Show resolved Hide resolved
@Fryguy Fryguy added the enhancement New feature or request label Sep 4, 2024
Comment on lines +150 to +162
def update_service_instance_with_stack_id(action, service_instance_id, stack_id)
if !action.nil? && action.downcase == 'provision'
service_instance = ServiceTerraformTemplate.find_by(:id => service_instance_id)
if !service_instance.nil?
service_instance.preprocess(action, {:extra_vars => {:miq_terraform_stack_id => stack_id}})
_log.debug("updated service-instance/#{service_instance.to_json} with stack_id#{stack_id}")
else
_log.info("Not found service-instance/#{service_instance_id}")
end
else
_log.debug("Not Provision action, no update to service-instance/#{service_instance_id} required")
end
end
Copy link
Member

Choose a reason for hiding this comment

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

Believe we discussed this in chat, but just to make sure this doesn't get lost I'll add here also.

I think the proper way to do this is to have the service retirement retire all of the related resources which in this case will be an OrchestrationStack. This would also work if in the future you had a service that ends up creating multiple terraform_stacks where what you have here would preclude that.

Comment on lines +80 to +88
case action.downcase
when 'retirement'
retire_job_options = options[job_option_key('retirement')].deep_dup
retire_job_options[:action] = action
prov_job_options = options[job_option_key('provision')].deep_dup
# if not already available in retirement options, (won't be available for terraform)
# copy extra_vars,execution_ttl,verbosity,credentials,etc from provision action
job_options = prov_job_options.deep_merge(retire_job_options)
else
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem right, shouldn't we set what we need in the options for the retirement action so we don't have to do this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants