Skip to content

Commit

Permalink
Update variable to use workspace read by id
Browse files Browse the repository at this point in the history
  • Loading branch information
beekus committed Mar 25, 2020
1 parent 995b2b5 commit 472fdcb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 31 deletions.
33 changes: 9 additions & 24 deletions tfe/resource_tfe_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,12 @@ func resourceTFEVariableCreate(d *schema.ResourceData, meta interface{}) error {
func resourceTFEVariableRead(d *schema.ResourceData, meta interface{}) error {
tfeClient := meta.(*tfe.Client)

// Get organization and workspace.
organization, workspace, err := unpackWorkspaceID(d.Get("workspace_id").(string))
if err != nil {
return fmt.Errorf("Error unpacking workspace ID: %v", err)
}

// Get the workspace.
ws, err := tfeClient.Workspaces.Read(ctx, organization, workspace)
workspaceID := d.Get("workspace_id").(string)
ws, err := tfeClient.Workspaces.ReadByID(ctx, workspaceID)
if err != nil {
return fmt.Errorf(
"Error retrieving workspace %s from organization %s: %v", workspace, organization, err)
"Error retrieving workspace %s: %v", workspaceID, err)
}

log.Printf("[DEBUG] Read variable: %s", d.Id())
Expand Down Expand Up @@ -167,17 +162,12 @@ func resourceTFEVariableRead(d *schema.ResourceData, meta interface{}) error {
func resourceTFEVariableUpdate(d *schema.ResourceData, meta interface{}) error {
tfeClient := meta.(*tfe.Client)

// Get organization and workspace.
organization, workspace, err := unpackWorkspaceID(d.Get("workspace_id").(string))
if err != nil {
return fmt.Errorf("Error unpacking workspace ID: %v", err)
}

// Get the workspace.
ws, err := tfeClient.Workspaces.Read(ctx, organization, workspace)
workspaceID := d.Get("workspace_id").(string)
ws, err := tfeClient.Workspaces.ReadByID(ctx, workspaceID)
if err != nil {
return fmt.Errorf(
"Error retrieving workspace %s from organization %s: %v", workspace, organization, err)
"Error retrieving workspace %s: %v", workspaceID, err)
}

// Create a new options struct.
Expand All @@ -201,17 +191,12 @@ func resourceTFEVariableUpdate(d *schema.ResourceData, meta interface{}) error {
func resourceTFEVariableDelete(d *schema.ResourceData, meta interface{}) error {
tfeClient := meta.(*tfe.Client)

// Get organization and workspace.
organization, workspace, err := unpackWorkspaceID(d.Get("workspace_id").(string))
if err != nil {
return fmt.Errorf("Error unpacking workspace ID: %v", err)
}

// Get the workspace.
ws, err := tfeClient.Workspaces.Read(ctx, organization, workspace)
workspaceID := d.Get("workspace_id").(string)
ws, err := tfeClient.Workspaces.ReadByID(ctx, workspaceID)
if err != nil {
return fmt.Errorf(
"Error retrieving workspace %s from organization %s: %v", workspace, organization, err)
"Error retrieving workspace %s: %v", workspaceID, err)
}

log.Printf("[DEBUG] Delete variable: %s", d.Id())
Expand Down
10 changes: 3 additions & 7 deletions tfe/resource_tfe_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,10 @@ func testAccCheckTFEVariableExists(
}

wsID := rs.Primary.Attributes["workspace_id"]
organization, workspace, err := unpackWorkspaceID(wsID)
ws, err := tfeClient.Workspaces.ReadByID(ctx, wsID)
if err != nil {
return fmt.Errorf("Unable to unpack workspace ID: %s", wsID)
}

ws, err := tfeClient.Workspaces.Read(ctx, organization, workspace)
if err != nil {
return fmt.Errorf("Unable to retreive workspace: %s", err)
return fmt.Errorf(
"Error retrieving workspace %s: %v", wsID, err)
}

v, err := tfeClient.Variables.Read(ctx, ws.ID, rs.Primary.ID)
Expand Down

4 comments on commit 472fdcb

@scottwinkler
Copy link

Choose a reason for hiding this comment

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

what is the purpose of this? this is a breaking change for what seems like no good reason

@paulspiegel
Copy link

Choose a reason for hiding this comment

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

All of our workspace ID outputs from the tfe_workspace resource changed this afternoon

@scottwinkler
Copy link

Choose a reason for hiding this comment

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

Okay but why not support both ways? If someone passes in a workspace ID then that's okay and if they want to do the old way with organization and workspace name then that's good to.

@paulspiegel
Copy link

Choose a reason for hiding this comment

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

Sorry for the confusion, I was saying that it was a breaking change for us and I agree with you

Please sign in to comment.