-
Notifications
You must be signed in to change notification settings - Fork 11
Add cloud creds support for terraform runner #16
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
Add cloud creds support for terraform runner #16
Conversation
putmanoj
commented
Apr 22, 2024
- Add cloud credentials classes for embedded-terraform with DDF configuration
- Add cloud credentails classes with authentication connection parameters for terraform-runner
app/models/manageiq/providers/embedded_terraform/automation_manager/scm_credential.rb
Outdated
Show resolved
Hide resolved
app/models/manageiq/providers/embedded_terraform/automation_manager/ibmcloud_credential.rb
Outdated
Show resolved
Hide resolved
app/models/manageiq/providers/embedded_terraform/automation_manager/scm_credential.rb
Outdated
Show resolved
Hide resolved
spec/models/manageiq/providers/embedded_terraform/automation_manager/credential_spec.rb
Outdated
Show resolved
Hide resolved
spec/models/manageiq/providers/embedded_terraform/automation_manager/credential_spec.rb
Outdated
Show resolved
Hide resolved
spec/models/manageiq/providers/embedded_terraform/automation_manager/credential_spec.rb
Outdated
Show resolved
Hide resolved
app/models/manageiq/providers/embedded_terraform/automation_manager/cloud_credential.rb
Show resolved
Hide resolved
|
|
||
| def self.params_to_attributes(params) | ||
| attrs = super.dup | ||
| attrs[:auth_key] = attrs.delete(:security_token) if attrs.key?(:security_token) |
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.
Why call a property security_token if we're just going to store it in auth_key, could you use "auth_key" instead up here ☝️ https://github.com/ManageIQ/manageiq-providers-embedded_terraform/pull/16/files#diff-10eac92f3aa8adb511c059784672e62020e8e6172d8154c295c6a5678c75007fR29-R30
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 question. We also have an alias for security_token from auth_key so hopefully we can use auth_key everywhere to keep it consistent.
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.
Yeah I understand having the :label be something specific but wasn't sure what having the internal key being different from the column bought us
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.
Just followed the pattern of what is in ansible implemetation - just a copy the same
https://github.com/ManageIQ/manageiq/blob/master/app/models/manageiq/providers/embedded_ansible/automation_manager/amazon_credential.rb#L52
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.
Ok, even better. Let's just use auth_key. I don't think it makes sense to translate one field to another unless we have a good reason.
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.
This can be done in a follow-up
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.
yup, I'll do this in a follow up. no need to delay merging on this.
| def self.params_to_attributes(params) | ||
| attrs = super.dup | ||
|
|
||
| attrs[:auth_key] = attrs.delete(:ssh_key_data) if attrs.key?(:ssh_key_data) |
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.
Basically the same question here as above (and looks like for a number of these). Maybe there is a good reason? IDK
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.
Again same pattern as in ansible implementation ...
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.
Right, I don't think we should blindly copy&paste from other code without thinking about it first :)
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'll get this for followup.
app/models/manageiq/providers/embedded_terraform/automation_manager/google_credential.rb
Show resolved
Hide resolved
| if %i[host domain project region cacert clientcert clientkey insecure].any? { |opt| attrs.has_key?(opt) } | ||
| attrs[:options] ||= {} | ||
| attrs[:options][:host] = attrs.delete(:host) if attrs.key?(:host) | ||
| attrs[:options][:domain] = attrs.delete(:domain) if attrs.key?(:domain) | ||
| attrs[:options][:project] = attrs.delete(:project) if attrs.key?(:project) | ||
| attrs[:options][:region] = attrs.delete(:region) if attrs.key?(:region) | ||
|
|
||
| attrs[:options][:cacert] = attrs.delete(:cacert) if attrs.key?(:cacert) | ||
| attrs[:options][:clientcert] = attrs.delete(:clientcert) if attrs.key?(:clientcert) | ||
| attrs[:options][:clientkey] = attrs.delete(:clientkey) if attrs.key?(:clientkey) | ||
|
|
||
| attrs[:options][:insecure] = attrs.delete(:insecure) if attrs.key?(:insecure) | ||
| end | ||
|
|
||
| attrs |
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 something like this does what you're trying to do:
| if %i[host domain project region cacert clientcert clientkey insecure].any? { |opt| attrs.has_key?(opt) } | |
| attrs[:options] ||= {} | |
| attrs[:options][:host] = attrs.delete(:host) if attrs.key?(:host) | |
| attrs[:options][:domain] = attrs.delete(:domain) if attrs.key?(:domain) | |
| attrs[:options][:project] = attrs.delete(:project) if attrs.key?(:project) | |
| attrs[:options][:region] = attrs.delete(:region) if attrs.key?(:region) | |
| attrs[:options][:cacert] = attrs.delete(:cacert) if attrs.key?(:cacert) | |
| attrs[:options][:clientcert] = attrs.delete(:clientcert) if attrs.key?(:clientcert) | |
| attrs[:options][:clientkey] = attrs.delete(:clientkey) if attrs.key?(:clientkey) | |
| attrs[:options][:insecure] = attrs.delete(:insecure) if attrs.key?(:insecure) | |
| end | |
| attrs | |
| unless (attrs.keys & %i[host domain project region cacert clientcert clientkey insecure]).empty? | |
| attrs.slice!(:host, :domain, :project, :region, :cacert, :clientkey, :insecure) | |
| end | |
| {:options => attrs} |
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.
Are there other values you're concerned about retaining? The slice option will only remove all key/values that aren't in the list so if you have others that aren't in that list, they'll be lost.
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 attrs will have more than just these keys like userid / password so we can't replace the top level hash with just {:options =>
What about something like
options = super.dup
attrs = options.slice!(:host, :domain, :project, :region, :cacert, :clientkey, :insecure)
attrs.merge!(:options => options) unless options.blank?
attrs
attrs will now have the rest of the keys that aren't in the slice! which should be the rest of the top level keys.
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.
Note, we have this pattern in params_to_attributes to pull out specific keys from attrs and store them in the :options subkey instead. Perhaps extract a method move_keys_to_options from above.
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.
Or not... this one is the most complicated one.
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.
Note, we have this pattern in params_to_attributes to pull out specific keys from attrs and store them in the :options subkey instead. Perhaps extract a method move_keys_to_options from above.
Yeah I wonder if maybe defining accessors would help clean this up? Like
def clientkey
options && options[:clientkey]
end
def clientkey=(val)
options ||= {}
options[:clientkey] = val
end
Then we probably don't need to override params_to_attributes at all. This would be a lot of change maybe something for a followup
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.
yup, followup is good
app/models/manageiq/providers/embedded_terraform/automation_manager/vsphere_credential.rb
Show resolved
Hide resolved
| { | ||
| :component => 'checkbox', | ||
| :label => N_('Trust self-signed SSL certificates ?'), | ||
| :helperText => N_('Trust self-signed SSL certificates ?'), |
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.
Is this the same thing as VERIFY_NONE (when insecure true) vs. VERIFY_PEER (when insecure false)? We call that Verify SSL, SSL Verification or SSL Verify Mode elsewhere.
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.
Yes, we can improve the label text ,
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.
Though by default insecure is false by default, so is OFF or 'unchecked'.
https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs#insecure
If we use Verify SSL as label, then meaning changes, ...
the checkbox needs to be 'ON' or 'checked' by default. Just don't know enough DDF yet, to know how to make checkbox 'checked' by default.
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.
@jrafanie , any other label suggestion ?
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 agree, we should use positive terms "Verify SSL" with it checked/enabled by default. We can with check @GilbertCherrie if we're not seeing it "on" by default.
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.
We can merge as is and I'll work with @GilbertCherrie if I can't figure out how to correctly switch the logic. I like "verify ssl" true/false as insecure "false" is a double negative and hard to understand.
app/models/manageiq/providers/embedded_terraform/automation_manager/azure_credential.rb
Outdated
Show resolved
Hide resolved
|
With #3 and ManageIQ/manageiq-ui-classic#9117 (rebased) locally and this PR... here are some screenshots of the credentials we're defining here: openstack 2: |
app/models/manageiq/providers/embedded_terraform/automation_manager/amazon_credential.rb
Show resolved
Hide resolved
app/models/manageiq/providers/embedded_terraform/automation_manager/google_credential.rb
Show resolved
Hide resolved
jrafanie
left a comment
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.
@putmanoj let ms know if there's any suggested changes you'd like me to work on... Some of these can be things we do in followup PRs. Anything resolved, we can mark resolved and any still remaining, we can choose to not resolve at all or leave them for followup work.
app/models/manageiq/providers/embedded_terraform/automation_manager/google_credential.rb
Show resolved
Hide resolved
app/models/manageiq/providers/embedded_terraform/automation_manager/ibm_cloud_credential.rb
Show resolved
Hide resolved
| { | ||
| :component => 'checkbox', | ||
| :label => N_('Trust self-signed SSL certificates ?'), | ||
| :helperText => N_('Trust self-signed SSL certificates ?'), |
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 agree, we should use positive terms "Verify SSL" with it checked/enabled by default. We can with check @GilbertCherrie if we're not seeing it "on" by default.
fix cloud creds conversion & add terraform runner test with credentials
add common method for add cam parameters
3678f85 to
101cd17
Compare
|
Checked commits putmanoj/manageiq-providers-embedded_terraform@816f9c8~...101cd17 with ruby 2.7.8, rubocop 1.56.3, haml-lint 0.51.0, and yamllint |
Simplify description from credentials PR #16







