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

Feature: Terraform specify --target #2606

Open
markush81 opened this issue Dec 3, 2024 · 1 comment
Open

Feature: Terraform specify --target #2606

markush81 opened this issue Dec 3, 2024 · 1 comment
Labels

Comments

@markush81
Copy link
Contributor

Related to

Other

Impact

major improvement to user experience

Missing Feature

Terraforms argument --target would be a major improvement in usage. Cause sometimes you want only parts to be done really automatically via schedules


  -target=resource    Limit the planning operation to only the given module,
                      resource, or resource instance and all of its
                      dependencies. You can use this option multiple times to
                      include more than one object. This is for exceptional
                      use only.

Implementation

I assume either dedicated UI param for --target or implemented via possibility of CLI args are used could be a solution.

image

	var templateExtraArgs []string
	if t.Template.Arguments != nil {
		err = json.Unmarshal([]byte(*t.Template.Arguments), &templateExtraArgs)
		if err != nil {
			t.Log("Invalid format of the template extra arguments, must be valid JSON")
			return
		}
	}

	var taskExtraArgs []string
	if t.Template.AllowOverrideArgsInTask && t.Task.Arguments != nil {
		err = json.Unmarshal([]byte(*t.Task.Arguments), &taskExtraArgs)
		if err != nil {
			t.Log("Invalid format of the TaskRunner extra arguments, must be valid JSON")
			return
		}
	}

	args = append(args, templateExtraArgs...)
	args = append(args, taskExtraArgs...)

like in getPlaybookArgs

Design

No response

@markush81
Copy link
Contributor Author

I just tried with

image

and



diff --git a/services/tasks/LocalJob.go b/services/tasks/LocalJob.go
index d2e0491a..a5c869ea 100644
--- a/services/tasks/LocalJob.go
+++ b/services/tasks/LocalJob.go
@@ -256,13 +256,37 @@ func (t *LocalJob) getTerraformArgs(username string, incomingVersion *string) (a
        }
 
        for _, secret := range t.Environment.Secrets {
-               fmt.Println(secret)
                if secret.Type != db.EnvironmentSecretVar {
                        continue
                }
                args = append(args, "-var", fmt.Sprintf("%s=%s", secret.Name, secret.Secret))
        }
 
+       fmt.Println(t.Template.Arguments)
+       var templateExtraArgs []string
+       if t.Template.Arguments != nil {
+               err = json.Unmarshal([]byte(*t.Template.Arguments), &templateExtraArgs)
+               if err != nil {
+                       t.Log("Invalid format of the template extra arguments, must be valid JSON")
+                       return
+               }
+       }
+
+       fmt.Println(t.Task.Arguments)
+       var taskExtraArgs []string
+       if t.Template.AllowOverrideArgsInTask && t.Task.Arguments != nil {
+               err = json.Unmarshal([]byte(*t.Task.Arguments), &taskExtraArgs)
+               if err != nil {
+                       t.Log("Invalid format of the TaskRunner extra arguments, must be valid JSON")
+                       return
+               }
+       }
+
+       args = append(args, templateExtraArgs...)
+       args = append(args, taskExtraArgs...)

        return
 }

and it would do the trick

10:51:26 AM
No changes. Your infrastructure matches the configuration.
10:51:26 AM
10:51:26 AM
Terraform has compared your real infrastructure against your configuration
10:51:26 AM
and found no differences, so no changes are needed.
10:51:26 AM
╷
10:51:26 AM
│ Warning: Resource targeting is in effect
10:51:26 AM
│ 
10:51:26 AM
│ You are creating a plan with the -target option, which means that the
10:51:26 AM
│ result of this plan may not represent all of the changes requested by the
10:51:26 AM
│ current configuration.
10:51:26 AM
│ 
10:51:26 AM
│ The -target option is not for routine use, and is provided only for
10:51:26 AM
│ exceptional situations such as recovering from errors or mistakes, or when
10:51:26 AM
│ Terraform specifically suggests to use it as part of an error message.
10:51:26 AM
╵
10:51:26 AM
Attempting to send microsoft teams alert

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

No branches or pull requests

1 participant