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

fix(ressource): fix terraform import SCM repo link #84

Merged
merged 6 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions examples/scm-repo-link/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
variable "api_token" {}

terraform {
required_providers {
scalingo = {
source = "Scalingo/scalingo"
}
}
}

provider "scalingo" {
api_token = var.api_token
}

data "scalingo_scm_integration" "github" {
scm_type = "github"
}

resource "scalingo_app" "test_app" {
name = "terraform-test-scm"
}

resource "scalingo_scm_repo_link" "github-link" {
auth_integration_uuid = data.scalingo_scm_integration.github.id
app = scalingo_app.test_app.id
source = "https://github.com/nalpskc/sample-node-express"
}
11 changes: 5 additions & 6 deletions examples/shared-database/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,34 @@ resource "scalingo_app" "test_app_fr" {
name = "terraform-testapp-fr"

environment {
MY_DB = "${lookup(scalingo_app.test_app.all_environment, "SCALINGO_REDIS_URL", "n/c")}"
MY_DB = lookup(scalingo_app.test_app.all_environment, "SCALINGO_REDIS_URL", "n/c")
}
}

resource "scalingo_domain" "wwwtestappcom" {
common_name = "www.testapp.com"
app = "${scalingo_app.test_app.id}"
app = scalingo_app.test_app.id
}

resource "scalingo_addon" "test_redis" {
provider_id = "scalingo-redis"
plan = "free"
app = "${scalingo_app.test_app.id}"
app = scalingo_app.test_app.id
}

resource "scalingo_github_link" "samplegomartini" {
app = "${scalingo_app.test_app.id}"
app = scalingo_app.test_app.id
source = "https://github.com/johnsudaar/sample-go-martini"
branch = "master"
auto_deploy = true
review_apps = true
deploy_on_branch_change = true
destroy_review_app_on_close = true
destroy_stale_review_app = true
destroy_closed_review_app_after = 2
destroy_stale_review_app_after = 4
}

resource "scalingo_collaborator" "customer" {
app = "${scalingo_app.test_app.id}"
app = scalingo_app.test_app.id
email = "customer@scalingo.com"
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/Scalingo/terraform-provider-scalingo
go 1.19

require (
github.com/Scalingo/go-scalingo/v5 v5.2.0
github.com/Scalingo/go-scalingo/v5 v5.2.1
github.com/hashicorp/terraform-plugin-sdk/v2 v2.20.0
)

Expand Down Expand Up @@ -44,8 +44,8 @@ require (
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
github.com/vmihailenco/tagparser v0.1.1 // indirect
github.com/zclconf/go-cty v1.10.0 // indirect
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect
golang.org/x/net v0.0.0-20220920203100-d0c6ba3f52d9 // indirect
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d // indirect
Expand Down
11 changes: 6 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Scalingo/go-scalingo/v5 v5.2.0 h1:UHcVux2lEZ+rf3EYxr2cWehHoXcS6sseWLxi1/VaYz8=
github.com/Scalingo/go-scalingo/v5 v5.2.0/go.mod h1:b/SeZwa10u6/CpB6WmxeToZ5FES8N/o83YpHBGLDvQ8=
github.com/Scalingo/go-scalingo/v5 v5.2.1 h1:m0aBqDmi3C/bKXlism/vnnujHvv4kWGLbXwG1S7nL+A=
github.com/Scalingo/go-scalingo/v5 v5.2.1/go.mod h1:b/SeZwa10u6/CpB6WmxeToZ5FES8N/o83YpHBGLDvQ8=
github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE=
github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
Expand Down Expand Up @@ -177,8 +177,8 @@ golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81R
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220920203100-d0c6ba3f52d9 h1:asZqf0wXastQr+DudYagQS8uBO8bHKeYD1vbAvGmFL8=
golang.org/x/net v0.0.0-20220920203100-d0c6ba3f52d9/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand All @@ -200,8 +200,9 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 h1:nonptSpoQ4vQjyraW20DXPAglgQfVnM9ZC6MmNLMR60=
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
Expand Down
16 changes: 12 additions & 4 deletions scalingo/data_scalingo_scm_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ func dataSourceScScmIntegration() *schema.Resource {
Schema: map[string]*schema.Schema{
"url": {
Type: schema.TypeString,
Required: true,
Optional: true,
},
"scm_type": {
Type: schema.TypeString,
Computed: true,
Optional: true,
},
"uid": {
Type: schema.TypeString,
Expand Down Expand Up @@ -53,15 +53,23 @@ func dataSourceScScmIntegration() *schema.Resource {
func dataSourceScScmIntegrationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client, _ := meta.(*scalingo.Client)

scmType, _ := d.Get("scm_type").(string)
url, _ := d.Get("url").(string)

integrations, err := client.SCMIntegrationsList(ctx)
if err != nil {
return diag.Errorf("fail to fetch integrations: %v", err)
}

selectedIntegrations := keepIf(integrations, func(element scalingo.SCMIntegration) bool {
return element.URL == url
selectedIntegrations := keepIf(integrations, func(integration scalingo.SCMIntegration) bool {
selected := true
if scmType != "" {
selected = selected && (scalingo.SCMType(scmType) == integration.SCMType)
}
if url != "" {
selected = selected && (url == integration.URL)
}
return selected
})

if len(selectedIntegrations) != 1 {
Expand Down
5 changes: 0 additions & 5 deletions scalingo/resource_scalingo_github_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ func resourceScalingoGithubLink() *schema.Resource {
Required: true,
ForceNew: true,
},
"deploy_on_branch_change": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"auto_deploy": {
Type: schema.TypeBool,
Optional: true,
Expand Down
13 changes: 5 additions & 8 deletions scalingo/resource_scalingo_scm_repo_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ func resourceScalingoScmRepoLink() *schema.Resource {
Optional: true,
Default: false,
},
"deploy_on_branch_change": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"deploy_review_apps_enabled": {
Type: schema.TypeBool,
Optional: true,
Expand All @@ -54,7 +49,7 @@ func resourceScalingoScmRepoLink() *schema.Resource {
"delete_on_close_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Default: true,
},
"hours_before_delete_on_close": {
Type: schema.TypeInt,
Expand Down Expand Up @@ -126,7 +121,7 @@ func resourceScmRepoLinkCreate(ctx context.Context, d *schema.ResourceData, meta
return diag.Errorf("fail to add SCM repo link: %v", err)
}

d.SetId(link.ID)
d.SetId(link.AppID)

return nil
}
Expand Down Expand Up @@ -209,9 +204,10 @@ func resourceScmRepoLinkRead(ctx context.Context, d *schema.ResourceData, meta i
if err != nil {
return diag.FromErr(err)
}
d.SetId(link.ID)
d.SetId(link.AppID)

err = SetAll(d, map[string]interface{}{
"app": link.AppID,
"auto_deploy_enabled": link.AutoDeployEnabled,
"deploy_review_apps_enabled": link.DeployReviewAppsEnabled,
"delete_on_close_enabled": link.DeleteOnCloseEnabled,
Expand All @@ -220,6 +216,7 @@ func resourceScmRepoLinkRead(ctx context.Context, d *schema.ResourceData, meta i
"hours_before_delete_stale": int(link.HoursBeforeDeleteStale),
"branch": link.Branch,
"auth_integration_uuid": link.AuthIntegrationUUID,
"source": fmt.Sprintf("%s/%s/%s", link.URL, link.Owner, link.Repo),
})
if err != nil {
return diag.Errorf("fail to store scm repo link information: %v", err)
Expand Down
5 changes: 5 additions & 0 deletions vendor/github.com/Scalingo/go-scalingo/v5/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions vendor/github.com/Scalingo/go-scalingo/v5/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vendor/github.com/Scalingo/go-scalingo/v5/alerts.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/Scalingo/go-scalingo/v5/scm_repo_link.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/Scalingo/go-scalingo/v5/version.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions vendor/golang.org/x/net/AUTHORS

This file was deleted.

3 changes: 0 additions & 3 deletions vendor/golang.org/x/net/CONTRIBUTORS

This file was deleted.

6 changes: 3 additions & 3 deletions vendor/golang.org/x/net/context/context.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions vendor/golang.org/x/net/context/go17.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions vendor/golang.org/x/net/context/pre_go17.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading