-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #302 from dbt-labs/feature/erro-handling-split-ids
- Loading branch information
Showing
26 changed files
with
371 additions
and
254 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package helper | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
strings "strings" | ||
|
||
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/dbt_cloud" | ||
) | ||
|
||
func SplitIDToStrings(id string, resource_type string) (string, string, error) { | ||
parts := strings.Split(id, dbt_cloud.ID_DELIMITER) | ||
if len(parts) != 2 { | ||
|
||
err := fmt.Errorf( | ||
"expected ID in the format 'id1%sid2' to import a %s, got: %s", | ||
dbt_cloud.ID_DELIMITER, | ||
resource_type, | ||
id, | ||
) | ||
return "", "", err | ||
} | ||
|
||
return parts[0], parts[1], nil | ||
} | ||
|
||
func SplitIDToInts(id string, resource_type string) (int, int, error) { | ||
parts := strings.Split(id, dbt_cloud.ID_DELIMITER) | ||
if len(parts) != 2 { | ||
|
||
err := fmt.Errorf( | ||
"expected ID in the format 'id1%sid2' to import a %s, got: %s", | ||
dbt_cloud.ID_DELIMITER, | ||
resource_type, | ||
id, | ||
) | ||
return 0, 0, err | ||
} | ||
|
||
id1, err := strconv.Atoi(parts[0]) | ||
if err != nil { | ||
return 0, 0, fmt.Errorf("error converting %s to int when splitting the ID", parts[0]) | ||
} | ||
|
||
id2, err := strconv.Atoi(parts[1]) | ||
if err != nil { | ||
return 0, 0, fmt.Errorf("error converting %s to int when splitting the ID", parts[1]) | ||
} | ||
|
||
return id1, id2, nil | ||
} |
This file contains 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 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 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 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 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 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.