-
Notifications
You must be signed in to change notification settings - Fork 263
fix: name space imports should not change project #1515
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
84c0d56
fix: name space imports should not change project
matttrach 98ecfcd
fix: error importing name space with mismatch
matttrach 8c06906
fix: add environment variables for CI
matttrach 2f6dfcb
fix: update docs
matttrach fd60840
fix: Merge changes from branch 'master'
matttrach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,36 @@ | ||
| # tflint-ignore: terraform_unused_declarations | ||
| variable "cluster_name" { | ||
| type = string | ||
| } | ||
| # tflint-ignore: terraform_unused_declarations | ||
| variable "rke2_version" { | ||
| type = string | ||
| } | ||
| # tflint-ignore: terraform_unused_declarations | ||
| variable "node_count" { | ||
| type = number | ||
| } | ||
| # tflint-ignore: terraform_unused_declarations | ||
| variable "rancher_key" { | ||
| type = string | ||
| } | ||
| # tflint-ignore: terraform_unused_declarations | ||
| variable "domain" { | ||
| type = string | ||
| } | ||
| # tflint-ignore: terraform_unused_declarations | ||
| variable "zone" { | ||
| type = string | ||
| } | ||
| # tflint-ignore: terraform_unused_declarations | ||
| variable "machine_config_kind" { | ||
| type = string | ||
| } | ||
| # tflint-ignore: terraform_unused_declarations | ||
| variable "machine_config_name" { | ||
| type = string | ||
| } | ||
| # tflint-ignore: terraform_unused_declarations | ||
| variable "project_mismatch" { | ||
| type = string | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
matttrach marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,39 +1,34 @@ | ||||||
| package rancher2 | ||||||
|
|
||||||
| import ( | ||||||
| "fmt" | ||||||
| "log" | ||||||
|
|
||||||
| "github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||||||
| clusterClient "github.com/rancher/rancher/pkg/client/generated/cluster/v3" | ||||||
| ) | ||||||
|
|
||||||
| func resourceRancher2NamespaceImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { | ||||||
| // in this context the clusterID is rancher2_cluster_v2.cluster_v1_id or rancher2_cluster.id | ||||||
| // the input is expected to be "project_id.namespace_id" | ||||||
| // project_id is a concatenation of "cluster_id:project_id" or data.rancher2_cluster.downstream_cluster.default_project_id | ||||||
| log.Printf("[INFO] Splitting given id %s", d.Id()) | ||||||
| projectID, resourceID := splitID(d.Id()) | ||||||
|
|
||||||
| log.Printf("[INFO] Splitting project %s", projectID) | ||||||
| clusterID, projectID := splitProjectID(projectID) | ||||||
| log.Printf("[INFO] Using cluster id %s", clusterID) | ||||||
|
|
||||||
| client, err := meta.(*Config).ClusterClient(clusterID) | ||||||
| if err != nil { | ||||||
| log.Printf("[INFO] Problem getting cluster client for cluster with id \"%s\"", clusterID) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit
Suggested change
|
||||||
| return []*schema.ResourceData{}, err | ||||||
| } | ||||||
|
|
||||||
| ns, err := client.Namespace.ByID(resourceID) | ||||||
| if err != nil { | ||||||
| return []*schema.ResourceData{}, err | ||||||
| } | ||||||
|
|
||||||
| d.Set("project_id", clusterID) | ||||||
| if projectID != "" { | ||||||
| log.Printf("[INFO] Moving Namespace ID %s to project %s", d.Id(), projectID) | ||||||
| nsMove := &clusterClient.NamespaceMove{ | ||||||
| ProjectID: projectID, | ||||||
| } | ||||||
|
|
||||||
| err = client.Namespace.ActionMove(ns, nsMove) | ||||||
| if err != nil { | ||||||
| return []*schema.ResourceData{}, err | ||||||
| } | ||||||
| d.Set("project_id", projectID) | ||||||
| if ns.ProjectID != projectID { | ||||||
| return []*schema.ResourceData{}, fmt.Errorf("[ERROR] Project ID \"%s\" in import object doesn't match resource to import (\"%s\").", projectID, ns.ProjectID) | ||||||
| } | ||||||
|
|
||||||
| err = flattenNamespace(d, ns) | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.