Skip to content

Commit

Permalink
SCALRCORE-24861 Add vcs_enabled for agent-pool, Add agent_pool_id for…
Browse files Browse the repository at this point in the history
… vcs_provider
  • Loading branch information
lyzohub committed Apr 12, 2023
1 parent f11ecf9 commit b01e0cf
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -23,6 +23,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `data.scalr_environment`: optional `id` and `name` arguments can be used together ([#228](https://github.com/Scalr/terraform-provider-scalr/pull/228))
- `data.scalr_endpoint`: optional `id` and `name` arguments can be used together ([#228](https://github.com/Scalr/terraform-provider-scalr/pull/228))
- `data.scalr_service_account`: optional `id` and `email` arguments can be used together ([#228](https://github.com/Scalr/terraform-provider-scalr/pull/228))
- `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

Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/scalr_agent_pool.md
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
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
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
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
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-20230403055927-2e9dae9e7852
github.com/scalr/go-scalr v0.0.0-20230411141017-78d2f06f68e0
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
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-20230403055927-2e9dae9e7852 h1:2igC+Z9oxF5xuzrr4369cFH615VbYA4PnnST06KZvK0=
github.com/scalr/go-scalr v0.0.0-20230403055927-2e9dae9e7852/go.mod h1:p34SHb25YRvbgft7SUjSDYESeoQhWzAlxGXId/BbaSE=
github.com/scalr/go-scalr v0.0.0-20230411141017-78d2f06f68e0 h1:qM50WQmFHgjqWw6St03Zahd+QtjkcmBgk8rbbreXxnQ=
github.com/scalr/go-scalr v0.0.0-20230411141017-78d2f06f68e0/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
10 changes: 10 additions & 0 deletions scalr/data_source_scalr_agent_pool.go
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 All @@ -54,6 +60,7 @@ func dataSourceScalrAgentPoolRead(ctx context.Context, d *schema.ResourceData, m

agentPoolID := d.Get("id").(string)
name := d.Get("name").(string)
vcsEnabled := d.Get("vcs_enabled").(bool)
accountID := d.Get("account_id").(string)
envID := d.Get("environment_id").(string)

Expand All @@ -73,6 +80,8 @@ func dataSourceScalrAgentPoolRead(ctx context.Context, d *schema.ResourceData, m
options.Environment = scalr.String(envID)
}

options.VcsEnabled = scalr.Bool(vcsEnabled)

agentPoolsList, err := scalrClient.AgentPools.List(ctx, options)
if err != nil {
return diag.Errorf("Error retrieving agent pool: %v", err)
Expand All @@ -97,6 +106,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
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
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
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 All @@ -123,6 +133,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 @@ -144,6 +159,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
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 b01e0cf

Please sign in to comment.