Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into marcin/prod-2536-clus…
Browse files Browse the repository at this point in the history
…ter-name-changes-should-not-force-replacement-in-tf
  • Loading branch information
maciaszczykm committed Aug 22, 2024
2 parents d56d06a + 4bbca78 commit 2f6eb7c
Show file tree
Hide file tree
Showing 21 changed files with 452 additions and 61 deletions.
8 changes: 4 additions & 4 deletions docs/data-sources/git_repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "plural_git_repository Data Source - terraform-provider-plural"
subcategory: ""
description: |-
GitRepository resource
Git repository data source.
---

# plural_git_repository (Data Source)

GitRepository resource
Git repository data source.



Expand All @@ -17,5 +17,5 @@ GitRepository resource

### Optional

- `id` (String) Internal identifier of this GitRepository.
- `url` (String) URL of this GitRepository.
- `id` (String) Internal identifier of this Git repository.
- `url` (String) URL of this Git repository.
28 changes: 28 additions & 0 deletions docs/data-sources/infrastructure_stack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "plural_infrastructure_stack Data Source - terraform-provider-plural"
subcategory: ""
description: |-
Stack data source.
---

# plural_infrastructure_stack (Data Source)

Stack data source.



<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- `id` (String) Internal identifier of this stack.
- `name` (String) Human-readable name of this stack.

### Read-Only

- `approval` (Boolean) Determines whether to require approval.
- `cluster_id` (String) The cluster on which the stack is be applied.
- `project_id` (String) ID of the project that this stack belongs to.
- `type` (String) A type for the stack, specifies the tool to use to apply it.
27 changes: 27 additions & 0 deletions docs/data-sources/pr_automation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "plural_pr_automation Data Source - terraform-provider-plural"
subcategory: ""
description: |-
PR automation data source.
---

# plural_pr_automation (Data Source)

PR automation data source.



<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- `id` (String) Internal identifier of this PR automation.
- `name` (String) Name of this PR automation.

### Read-Only

- `identifier` (String) Identifier of this PR automation.
- `message` (String) Message of this PR automation.
- `title` (String) Title of this PR automation.
1 change: 1 addition & 0 deletions docs/resources/pr_automation_trigger.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ description: |-

- `context` (Map of String) PR Automation configuration context.
- `repo_slug` (String) Repo slug of the repository PR Automation should be triggered against. If not provided PR Automation repo will be used. Example format for a github repository: <userOrOrg>/<repoName>
- `retrigger_key` (String) Every time this key changes PR automation will be retriggered.
4 changes: 4 additions & 0 deletions docs/resources/stack_run_trigger.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ description: |-
### Required

- `id` (String) ID of the Infrastructure Stack that should be used to start a new run from the newest SHA in the stack's run history.

### Optional

- `retrigger_key` (String) Every time this key changes stack run will be retriggered.
24 changes: 24 additions & 0 deletions example/prautomation/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
terraform {
required_providers {
plural = {
source = "pluralsh/plural"
version = "0.2.1"
}
}
}

provider "plural" {
use_cli = true
}

data "plural_pr_automation" "automation" {
name = "pr-test"
}

# resource "plural_pr_automation_trigger" "trigger" {
# pr_automation_id = data.plural_pr_automation.automation.id
# pr_automation_branch = "prautomation"
# context = {
# version: "v0.0.0"
# }
# }
20 changes: 0 additions & 20 deletions example/prautomationtrigger/main.tf

This file was deleted.

7 changes: 6 additions & 1 deletion example/stackruntrigger/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ provider "plural" {
use_cli = true
}

data "plural_infrastructure_stack" "test" {
name = "test-job"
}

resource "plural_stack_run_trigger" "trigger" {
id = "ecc8966a-edfe-4e48-b5ea-f87c3e97d0a3"
id = data.plural_infrastructure_stack.test.id
retrigger_key = "test"
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/hashicorp/terraform-plugin-framework-validators v0.13.0
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/mitchellh/go-homedir v1.1.0
github.com/pluralsh/console/go/client v1.9.0
github.com/pluralsh/console/go/client v1.10.0
github.com/pluralsh/plural-cli v0.9.14-0.20240730152129-7ce540b144fd
github.com/pluralsh/polly v0.1.10
github.com/samber/lo v1.46.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,8 @@ github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFz
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pluralsh/console/go/client v1.9.0 h1:zAXhLUmsYxf1FWNd88N69Glk5A0QMqlSD+mOy9D5+Lo=
github.com/pluralsh/console/go/client v1.9.0/go.mod h1:lpoWASYsM9keNePS3dpFiEisUHEfObIVlSL3tzpKn8k=
github.com/pluralsh/console/go/client v1.10.0 h1:oY8ZeTcoyP5WhrAheQm0PwONJQ/O65sqeWRfgQknMtI=
github.com/pluralsh/console/go/client v1.10.0/go.mod h1:lpoWASYsM9keNePS3dpFiEisUHEfObIVlSL3tzpKn8k=
github.com/pluralsh/gqlclient v1.12.1 h1:JDOkP9jjqkPdTYdpH5hooG4F8T6FDH90XfipeXJmJFY=
github.com/pluralsh/gqlclient v1.12.1/go.mod h1:OEjN9L63x8m3A3eQBv5kVkFgiY9fp2aZ0cgOF0uII58=
github.com/pluralsh/plural-cli v0.9.14-0.20240730152129-7ce540b144fd h1:gg+5AUbiip8WzAQE+avozXLBdP5eS19J6x6+BhtkGNY=
Expand Down
12 changes: 6 additions & 6 deletions internal/datasource/git_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ func (r *GitRepositoryDataSource) Metadata(_ context.Context, req datasource.Met

func (r *GitRepositoryDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
MarkdownDescription: "GitRepository resource",
MarkdownDescription: "Git repository data source.",
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Optional: true,
Description: "Internal identifier of this GitRepository.",
MarkdownDescription: "Internal identifier of this GitRepository.",
Description: "Internal identifier of this Git repository.",
MarkdownDescription: "Internal identifier of this Git repository.",
Validators: []validator.String{
stringvalidator.ConflictsWith(path.MatchRoot("url")),
},
},
"url": schema.StringAttribute{
Optional: true,
Description: "URL of this GitRepository.",
MarkdownDescription: "URL of this GitRepository.",
Description: "URL of this Git repository.",
MarkdownDescription: "URL of this Git repository.",
Validators: []validator.String{
stringvalidator.ConflictsWith(path.MatchRoot("id")),
},
Expand Down Expand Up @@ -79,7 +79,7 @@ func (r *GitRepositoryDataSource) Read(ctx context.Context, req datasource.ReadR

response, err := r.client.GetGitRepository(ctx, data.Id.ValueStringPointer(), data.Url.ValueStringPointer())
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to get GitRepository, got error: %s", err))
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to get Git repository, got error: %s", err))
return
}

Expand Down
113 changes: 113 additions & 0 deletions internal/datasource/infrastructure_stack.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package datasource

import (
"context"
"fmt"

"terraform-provider-plural/internal/client"
"terraform-provider-plural/internal/common"
"terraform-provider-plural/internal/model"

"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
)

func NewInfrastructureStackDataSource() datasource.DataSource {
return &InfrastructureStackDataSource{}
}

// InfrastructureStackDataSource defines the stack data source implementation.
type InfrastructureStackDataSource struct {
client *client.Client
}

func (r *InfrastructureStackDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_infrastructure_stack"
}

func (r *InfrastructureStackDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
MarkdownDescription: "Stack data source.",
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Optional: true,
Description: "Internal identifier of this stack.",
MarkdownDescription: "Internal identifier of this stack.",
Validators: []validator.String{
stringvalidator.ExactlyOneOf(path.MatchRoot("name")),
},
},
"name": schema.StringAttribute{
Optional: true,
Description: "Human-readable name of this stack.",
MarkdownDescription: "Human-readable name of this stack.",
Validators: []validator.String{
stringvalidator.ExactlyOneOf(path.MatchRoot("id")),
},
},
"type": schema.StringAttribute{
Description: "A type for the stack, specifies the tool to use to apply it. ",
MarkdownDescription: "A type for the stack, specifies the tool to use to apply it. ",
Computed: true,
},
"approval": schema.BoolAttribute{
Description: "Determines whether to require approval.",
MarkdownDescription: "Determines whether to require approval.",
Computed: true,
},
"project_id": schema.StringAttribute{
Description: "ID of the project that this stack belongs to.",
MarkdownDescription: "ID of the project that this stack belongs to.",
Computed: true,
},
"cluster_id": schema.StringAttribute{
Description: "The cluster on which the stack is be applied.",
MarkdownDescription: "The cluster on which the stack is be applied.",
Computed: true,
},
},
}
}

func (r *InfrastructureStackDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
if req.ProviderData == nil {
return
}

data, ok := req.ProviderData.(*common.ProviderData)
if !ok {
resp.Diagnostics.AddError(
"Unexpected Infrastructure Stack Resource Configure Type",
fmt.Sprintf("Expected *common.ProviderData, got: %T. Please report this issue to the provider developers.", req.ProviderData),
)

return
}

r.client = data.Client
}

func (r *InfrastructureStackDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
data := new(model.InfrastructureStack)
resp.Diagnostics.Append(req.Config.Get(ctx, data)...)
if resp.Diagnostics.HasError() {
return
}

response, err := r.client.GetInfrastructureStack(ctx, data.Id.ValueStringPointer(), data.Name.ValueStringPointer())
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to get stack, got error: %s", err))
return
}

if response == nil || response.InfrastructureStack == nil {
resp.Diagnostics.AddError("Client Error", "Unable to find stack")
return
}

data.From(response.InfrastructureStack)
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}
Loading

0 comments on commit 2f6eb7c

Please sign in to comment.