-
Notifications
You must be signed in to change notification settings - Fork 11
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 #104 from Scalr/fix/SCALRCORE-20952
SCALRCORE-20952 API > Create VCS provider with personal token > Provider is broken
- Loading branch information
Showing
7 changed files
with
117 additions
and
4 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package scalr | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/validation" | ||
"github.com/scalr/go-scalr" | ||
) | ||
|
||
func resourceScalrVcsProviderV0() *schema.Resource { | ||
return &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"url": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"vcs_type": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: validation.StringInSlice( | ||
[]string{ | ||
string(scalr.Github), | ||
string(scalr.GithubEnterprise), | ||
string(scalr.Gitlab), | ||
string(scalr.GitlabEnterprise), | ||
string(scalr.BitbucketEnterprise), | ||
}, | ||
false, | ||
), | ||
}, | ||
"token": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Sensitive: true, | ||
}, | ||
"account_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ForceNew: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceScalrVcsProviderStateUpgradeV0(rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { | ||
rawState["username"] = "" | ||
return rawState, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package scalr | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func testResourceScalrVcsProviderStateDataV0() map[string]interface{} { | ||
return map[string]interface{}{ | ||
"id": "vcs-123", | ||
"name": "test", | ||
"token": "tolen", | ||
"url": "https://github.com", | ||
"vcs_type": "github", | ||
} | ||
} | ||
|
||
func testResourceScalrVcsProviderStateDataV1() map[string]interface{} { | ||
res := testResourceScalrVcsProviderStateDataV0() | ||
res["username"] = "" | ||
return res | ||
} | ||
|
||
func TestResourceScalrVcsProviderStateUpgradeV0(t *testing.T) { | ||
expected := testResourceScalrVcsProviderStateDataV1() | ||
actual, err := resourceScalrVcsProviderStateUpgradeV0(testResourceScalrVcsProviderStateDataV0(), nil) | ||
assertCorrectState(t, err, actual, expected) | ||
} |