-
Notifications
You must be signed in to change notification settings - Fork 10
Use ansible/terraform modules over go/exec #8
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
Conversation
| fmt.Sprintf("-state=%s", filepath.Join(dir, StateFileName)), | ||
| fmt.Sprintf("-state-out=%s", filepath.Join(dir, StateFileName)), | ||
| } | ||
| if autoApprove { |
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.
The module has no support for the -auto-approve option and is baked into the module for all terraform operations.
For e.g: tf.Apply
| RepoRoot string `desc:"The path to the root of the local kubernetes repo. Necessary to call certain scripts. Defaults to the current directory. If operating in legacy mode, this should be set to the local kubernetes/kubernetes repo."` | ||
| IgnoreClusterDir bool `desc:"Ignore the cluster folder if exists"` | ||
| AutoApprove bool `desc:"Terraform Auto Approve"` | ||
| AutoApprove bool `desc:"Auto-approve the deployment of infrastructure through terraform" flag:",deprecated"` |
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.
Since auto-approved is no longer supported, setting/unsetting will not have any effect on the execution.
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.
interesting to see that they are always setting the auto-approve in the code - https://github.com/hashicorp/terraform-exec/blob/7ae12dd2176573ec55c9b5c84542d1b466efce54/tfexec/apply.go#L176
Maybe for later: explore whether we can influence the community to support this option, as it would be helpful for a dry‑run test to see what changes are occurring before the actual 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.
Created an issue on the terraform exec repo just to get an opinion!
|
@kishen-v can you please create an issue and add all the information about the change you are trying to make and why? |
646bb99 to
7dfad1b
Compare
|
/hold |
d18dec0 to
e9373c4
Compare
e9373c4 to
e5cc4b6
Compare
e5cc4b6 to
e6e7cd8
Compare
e6e7cd8 to
4997a7b
Compare
|
/test pull-provider-ibmcloud-test-infra-kubernetes |
|
/cc @Prajyot-Parab |
|
/lgtm |
Amulyam24
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.
Golang changes are okay, I might not be the right person to review the flow, will defer it to @Rajalakshmi-Girish, Thanks @kishen-v!
| RepoRoot string `desc:"The path to the root of the local kubernetes repo. Necessary to call certain scripts. Defaults to the current directory. If operating in legacy mode, this should be set to the local kubernetes/kubernetes repo."` | ||
| IgnoreClusterDir bool `desc:"Ignore the cluster folder if exists"` | ||
| AutoApprove bool `desc:"Terraform Auto Approve"` | ||
| AutoApprove bool `desc:"Auto-approve the deployment of infrastructure through terraform" flag:",deprecated"` |
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.
interesting to see that they are always setting the auto-approve in the code - https://github.com/hashicorp/terraform-exec/blob/7ae12dd2176573ec55c9b5c84542d1b466efce54/tfexec/apply.go#L176
Maybe for later: explore whether we can influence the community to support this option, as it would be helpful for a dry‑run test to see what changes are occurring before the actual run.
| // successful execution of ansible playbook | ||
| return 0, nil | ||
| extraVarsMap := make(map[string]interface{}, len(extraVars)) | ||
| for key, val := range extraVars { |
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 mapping can be avoid if change the datatype for the extraVars to map[string]any.
Here is the diff, see if this works:
diff --git a/kubetest2-tf/deployer/deployer.go b/kubetest2-tf/deployer/deployer.go
index dd1887a..c1936b3 100644
--- a/kubetest2-tf/deployer/deployer.go
+++ b/kubetest2-tf/deployer/deployer.go
@@ -76,15 +76,15 @@ type deployer struct {
tmpDir string
machineIPs []string
- RepoRoot string `desc:"The path to the root of the local kubernetes repo. Necessary to call certain scripts. Defaults to the current directory. If operating in legacy mode, this should be set to the local kubernetes/kubernetes repo."`
- IgnoreClusterDir bool `desc:"Ignore the cluster folder if exists"`
- AutoApprove bool `desc:"Auto-approve the deployment of infrastructure through terraform" flag:",deprecated"`
- RetryOnTfFailure int `desc:"Retry on Terraform Apply Failure"`
- BreakKubetestOnUpfail bool `desc:"Breaks kubetest2 when up fails"`
- Playbook string `desc:"Name of ansible playbook to be run"`
- ExtraVars map[string]string `desc:"Passes extra-vars to ansible playbook, enter a string of key=value pairs"`
- SetKubeconfig bool `desc:"Flag to set kubeconfig"`
- TargetProvider string `desc:"provider value to be used(powervs, vpc)"`
+ RepoRoot string `desc:"The path to the root of the local kubernetes repo. Necessary to call certain scripts. Defaults to the current directory. If operating in legacy mode, this should be set to the local kubernetes/kubernetes repo."`
+ IgnoreClusterDir bool `desc:"Ignore the cluster folder if exists"`
+ AutoApprove bool `desc:"Auto-approve the deployment of infrastructure through terraform" flag:",deprecated"`
+ RetryOnTfFailure int `desc:"Retry on Terraform Apply Failure"`
+ BreakKubetestOnUpfail bool `desc:"Breaks kubetest2 when up fails"`
+ Playbook string `desc:"Name of ansible playbook to be run"`
+ ExtraVars map[string]any `desc:"Passes extra-vars to ansible playbook, enter a string of key=value pairs"`
+ SetKubeconfig bool `desc:"Flag to set kubeconfig"`
+ TargetProvider string `desc:"provider value to be used(powervs, vpc)"`
}
func (d *deployer) Version() string {
@@ -247,7 +247,7 @@ func (d *deployer) Up() error {
}
klog.Infof("Ansible params exposed under groupvars: %v", string(ansibleParams))
// Unmarshalling commonJSON into map to add extra-vars
- combinedAnsibleVars := map[string]string{}
+ combinedAnsibleVars := map[string]any{}
if err = json.Unmarshal(ansibleParams, &combinedAnsibleVars); err != nil {
return fmt.Errorf("failed to unmarshal ansible group variables: %v", err)
}
diff --git a/kubetest2-tf/pkg/ansible/ansible.go b/kubetest2-tf/pkg/ansible/ansible.go
index 6782c37..31f7ef8 100644
--- a/kubetest2-tf/pkg/ansible/ansible.go
+++ b/kubetest2-tf/pkg/ansible/ansible.go
@@ -17,20 +17,20 @@ const (
ansibleDataDir = "k8s-ansible"
)
-func Playbook(dir, inventory, playbook string, extraVars map[string]string) error {
+func Playbook(dir, inventory, playbook string, extraVars map[string]any) error {
if err := unpackAnsible(dir); err != nil {
return fmt.Errorf("failed to unpack the ansible code: %v", err)
}
- extraVarsMap := make(map[string]interface{}, len(extraVars))
- for key, val := range extraVars {
- extraVarsMap[key] = val
- }
+ // extraVarsMap := make(map[string]interface{}, len(extraVars))
+ // for key, val := range extraVars {
+ // extraVarsMap[key] = val
+ // }
klog.Infof("Running ansible playbook: %s", playbook)
playbookCmd := ansibleplaybook.NewAnsiblePlaybookCmd(
ansibleplaybook.WithPlaybooks(filepath.Join(dir, playbook)),
ansibleplaybook.WithPlaybookOptions(
&ansibleplaybook.AnsiblePlaybookOptions{
- ExtraVars: extraVarsMap,
+ ExtraVars: extraVars,
Inventory: inventory,
}),
)
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.
same can be used in the other place 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.
Had tried this approach earlier, It ends up with the CLI returning an error that --extra-vars is an unknown flag:
spf13/pflag#375 - Generics aren't supported yet.😞 Given that the repo uses pflag as the underlying package to support flags..
Flag --auto-approve has been deprecated, Auto-approve the deployment of infrastructure through terraform
Error: unknown flag: --extra-vars
Usage:
kubetest2 tf [Flags] [DeployerFlags] -- [TesterArgs]
|
/hold for addressing review comments and testing. |
|
/test pull-provider-ibmcloud-test-infra-kubernetes |
4997a7b to
0392b1e
Compare
|
/test pull-provider-ibmcloud-test-infra-kubernetes |
28dc988 to
2f30e64
Compare
|
/test pull-provider-ibmcloud-test-infra-kubernetes |
@kishen-v I see some error while tf apply retry flow, not sure if this is because of this change, ptal |
|
Hi @mkumatag, I hadn't changed much around the Apply/Retry logic.. I did run the deployer in my local with the latest changes, it worked as expected.. However in the prow logs, I see that the LPAR deployment timed out.. Should it be worth retesting? |
|
/test pull-provider-ibmcloud-test-infra-kubernetes |
|
/unhold |
mkumatag
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.
/lgtm
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: kishen-v, mkumatag The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This PR simplifies implementations for executing terraform/ansible sections through modules and has been tested end-to-end with available options.
Fixes: #9