Skip to content

Commit

Permalink
Merged automatically by CI pipeline
Browse files Browse the repository at this point in the history
Revert "Revert "Provider > Add link API between on-prem VCS and Agent-Pool""
  • Loading branch information
emocharnik authored Apr 24, 2023
2 parents b8ada94 + 11849ea commit acb2bac
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 6 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- `scalr_vcs_provider`: added new attribute `agent_pool_id` ([#233](https://github.com/Scalr/terraform-provider-scalr/pull/233))
- `data.scalr_vcs_provider`: added new attribute `agent_pool_id` ([#233](https://github.com/Scalr/terraform-provider-scalr/pull/233))
- `scalr_agent_pool`: added new attribute `vcs_enabled` ([#233](https://github.com/Scalr/terraform-provider-scalr/pull/233))
- `data.scalr_agent_pool`: added new attribute `vcs_enabled` ([#233](https://github.com/Scalr/terraform-provider-scalr/pull/232))

### Fixed

- `data.scalr_module_version`: if there are several module versions with the same version, select the version that has the 'is-root-module' flag set to true. ([#229](https://github.com/Scalr/terraform-provider-scalr/pull/229))

### Required

- scalr-server >= `8.64.0`

## [1.0.5] - 2023-04-21

### Changed
Expand Down Expand Up @@ -39,7 +54,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- `scalr_account_allowed_ips`: accept /32 suffix ([#224](https://github.com/Scalr/terraform-provider-scalr/pull/224))
- `data.scalr_module_version`: if there are several module versions with the same version, select the version that has the 'is-root-module' flag set to true. ([#229](https://github.com/Scalr/terraform-provider-scalr/pull/229))
- `scalr_vcs_provider`: fix handling resource destroy when resource no longer exists ([#235](https://github.com/Scalr/terraform-provider-scalr/pull/235))
- `scalr_webhook`: fix handling resource destroy when resource no longer exists ([#235](https://github.com/Scalr/terraform-provider-scalr/pull/235))

Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/scalr_agent_pool.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ data "scalr_agent_pool" "default" {
* `name` - (Optional) A name of the agent pool.
* `account_id` - (Optional) An identifier of the Scalr account.
* `environment_id` - (Optional) An identifier of the Scalr environment.
* `vcs_enabled` - (Optional) Indicates whether the VCS support is enabled for agents in the pool.

Arguments `id` and `name` are both optional, specify at least one of them to obtain `scalr_agent_pool`.

Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/scalr_vcs_provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The following arguments are supported:
* `vcs_type` - (Optional) Type of the VCS provider. For example, `github`.
* `environment_id` - (Optional) ID of the environment the VCS provider has to be linked to, in the format `env-<RANDOM STRING>`.
* `account_id` - (Optional) ID of the account, in the format `acc-<RANDOM STRING>`.
* `agent_pool_id` - (Optional) ID of the agent pool, in the format `apool-<RANDOM STRING>`.

## Attribute Reference

Expand Down
1 change: 1 addition & 0 deletions docs/resources/scalr_agent_pool.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ resource "scalr_agent_pool" "default" {
* `name` - (Required) Name of the agent pool.
* `account_id` - (Optional) ID of the account.
* `environment_id` - (Optional) ID of the environment.
* `vcs_enabled` - (Optional) Indicates whether the VCS support is enabled for agents in the pool.

## Attribute Reference

Expand Down
1 change: 1 addition & 0 deletions docs/resources/scalr_vcs_provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ resource "scalr_vcs_provider" "example" {
* `account_id` - (Optional) ID of the account.
* `url` - (Optional) This field is required for self-hosted vcs providers.
* `username` - (Optional) This field is required for `bitbucket_enterprise` provider type.
* `agent_pool_id` - (Optional) ID of the agent pool to communicate with VCS through.


## Attribute Reference
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require (
github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734
github.com/scalr/go-scalr v0.0.0-20230421151357-4914e45b665e
github.com/scalr/go-scalr v0.0.0-20230424091123-5437ed6e096e
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/scalr/go-scalr v0.0.0-20230421151357-4914e45b665e h1:i1gW2sY+nZ9b0npQXY6uZg3Atsunwul0njh/QspoPU8=
github.com/scalr/go-scalr v0.0.0-20230421151357-4914e45b665e/go.mod h1:p34SHb25YRvbgft7SUjSDYESeoQhWzAlxGXId/BbaSE=
github.com/scalr/go-scalr v0.0.0-20230424091123-5437ed6e096e h1:dnFu7ozDG1exX+KnYqtfStR/nYobB2k1OhqT+jIEVgg=
github.com/scalr/go-scalr v0.0.0-20230424091123-5437ed6e096e/go.mod h1:p34SHb25YRvbgft7SUjSDYESeoQhWzAlxGXId/BbaSE=
github.com/sebdah/goldie v1.0.0/go.mod h1:jXP4hmWywNEwZzhMuv2ccnqTSFpuq8iyQhtQdkkZBH4=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
Expand Down
11 changes: 11 additions & 0 deletions scalr/data_source_scalr_agent_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ func dataSourceScalrAgentPool() *schema.Resource {
Computed: true,
ValidateFunc: validation.StringIsNotWhiteSpace,
},
"vcs_enabled": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},

"account_id": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -73,6 +79,10 @@ func dataSourceScalrAgentPoolRead(ctx context.Context, d *schema.ResourceData, m
options.Environment = scalr.String(envID)
}

if vcsEnabled, ok := d.GetOkExists("vcs_enabled"); ok { //nolint:staticcheck
options.VcsEnabled = scalr.Bool(vcsEnabled.(bool))
}

agentPoolsList, err := scalrClient.AgentPools.List(ctx, options)
if err != nil {
return diag.Errorf("Error retrieving agent pool: %v", err)
Expand All @@ -97,6 +107,7 @@ func dataSourceScalrAgentPoolRead(ctx context.Context, d *schema.ResourceData, m
log.Printf("[DEBUG] agent pool %s workspaces: %+v", agentPool.ID, workspaces)
_ = d.Set("workspace_ids", workspaces)
}
_ = d.Set("vcs_enabled", agentPool.VcsEnabled)
_ = d.Set("name", agentPool.Name)
d.SetId(agentPool.ID)

Expand Down
11 changes: 11 additions & 0 deletions scalr/data_source_scalr_vcs_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func dataSourceScalrVcsProvider() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"agent_pool_id": {
Type: schema.TypeString,
Optional: true,
},
"environments": {
Type: schema.TypeList,
Computed: true,
Expand All @@ -70,6 +74,10 @@ func dataSourceScalrVcsProviderRead(ctx context.Context, d *schema.ResourceData,
options.Environment = scalr.String(envId.(string))
}

if agentPoolID, ok := d.GetOk("agent_pool_id"); ok {
options.AgentPool = scalr.String(agentPoolID.(string))
}

if vcsType, ok := d.GetOk("vcs_type"); ok {
vcsType := scalr.VcsType(vcsType.(string))
options.VcsType = &vcsType
Expand Down Expand Up @@ -101,6 +109,9 @@ func dataSourceScalrVcsProviderRead(ctx context.Context, d *schema.ResourceData,
_ = d.Set("name", vcsProvider.Name)
_ = d.Set("url", vcsProvider.Url)
_ = d.Set("environments", envIds)
if vcsProvider.AgentPool != nil {
_ = d.Set("agent_pool_id", vcsProvider.AgentPool.ID)
}
d.SetId(vcsProvider.ID)

return nil
Expand Down
16 changes: 14 additions & 2 deletions scalr/resource_scalr_agent_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ func resourceScalrAgentPool() *schema.Resource {
Optional: true,
ForceNew: true,
},
"vcs_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
}
}
Expand All @@ -49,11 +54,13 @@ func resourceScalrAgentPoolCreate(ctx context.Context, d *schema.ResourceData, m
// Get required options
name := d.Get("name").(string)
accountID := d.Get("account_id").(string)
vcsEnabled := d.Get("vcs_enabled").(bool)

// Create a new options struct
options := scalr.AgentPoolCreateOptions{
Name: scalr.String(name),
Account: &scalr.Account{ID: accountID},
Name: scalr.String(name),
Account: &scalr.Account{ID: accountID},
VcsEnabled: scalr.Bool(vcsEnabled),
}

if envID, ok := d.GetOk("environment_id"); ok {
Expand Down Expand Up @@ -89,6 +96,7 @@ func resourceScalrAgentPoolRead(ctx context.Context, d *schema.ResourceData, met
// Update the config.
_ = d.Set("name", agentPool.Name)
_ = d.Set("account_id", agentPool.Account.ID)
_ = d.Set("vcs_enabled", agentPool.VcsEnabled)

if agentPool.Environment != nil {
_ = d.Set("environment_id", agentPool.Environment.ID)
Expand All @@ -103,6 +111,10 @@ func resourceScalrAgentPoolUpdate(ctx context.Context, d *schema.ResourceData, m

id := d.Id()

if d.HasChange("vcs_enabled") {
return diag.Errorf("Error updating agentPool %s: %v", id, "vcs_enabled attribute is readonly.")
}

if d.HasChange("name") {
// Create a new options struct
options := scalr.AgentPoolUpdateOptions{
Expand Down
21 changes: 21 additions & 0 deletions scalr/resource_scalr_vcs_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ func resourceScalrVcsProvider() *schema.Resource {
DefaultFunc: scalrAccountIDDefaultFunc,
ForceNew: true,
},
"agent_pool_id": {
Type: schema.TypeString,
Optional: true,
},
},
}
}
Expand Down Expand Up @@ -97,6 +101,12 @@ func resourceScalrVcsProviderCreate(ctx context.Context, d *schema.ResourceData,
options.Username = scalr.String(username.(string))
}

if agentPoolID, ok := d.GetOk("agent_pool_id"); ok {
options.AgentPool = &scalr.AgentPool{
ID: agentPoolID.(string),
}
}

log.Printf("[DEBUG] Create vcs provider: %s", name)
provider, err := scalrClient.VcsProviders.Create(ctx, options)
if err != nil {
Expand Down Expand Up @@ -125,6 +135,11 @@ func resourceScalrVcsProviderRead(ctx context.Context, d *schema.ResourceData, m
if provider.Account != nil {
_ = d.Set("account_id", provider.Account.ID)
}
if provider.AgentPool != nil {
_ = d.Set("agent_pool_id", provider.AgentPool.ID)
} else {
_ = d.Set("agent_pool_id", "")
}

return nil
}
Expand All @@ -146,6 +161,12 @@ func resourceScalrVcsProviderUpdate(ctx context.Context, d *schema.ResourceData,
options.Username = scalr.String(username.(string))
}

if agentPoolID, ok := d.GetOk("agent_pool_id"); ok {
options.AgentPool = &scalr.AgentPool{
ID: agentPoolID.(string),
}
}

log.Printf("[DEBUG] Update vcs provider: %s", d.Id())
_, err := scalrClient.VcsProviders.Update(ctx, d.Id(), options)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions scalr/resource_scalr_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,8 @@ func resourceScalrWorkspaceRead(ctx context.Context, d *schema.ResourceData, met

if workspace.AgentPool != nil {
_ = d.Set("agent_pool_id", workspace.AgentPool.ID)
} else {
_ = d.Set("agent_pool_id", "")
}

var mv string
Expand Down

0 comments on commit acb2bac

Please sign in to comment.