Skip to content

Commit

Permalink
application: bug: remove unsupported parameters (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurochan authored Oct 29, 2023
1 parent 2f62858 commit 93725be
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 30 deletions.
25 changes: 4 additions & 21 deletions internal/provider/resource_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"

api "github.com/pipe-cd/pipecd/pkg/app/server/service/apiservice"
"github.com/pipe-cd/pipecd/pkg/model"
Expand Down Expand Up @@ -56,8 +57,6 @@ type (

applicationResourceGitModel struct {
RepositoryID types.String `tfsdk:"repository_id"`
Remote types.String `tfsdk:"remote"`
Branch types.String `tfsdk:"branch"`
Path types.String `tfsdk:"path"`
Filename types.String `tfsdk:"filename"`
}
Expand Down Expand Up @@ -85,8 +84,6 @@ func (a *ApplicationResource) ImportState(ctx context.Context, req resource.Impo
Description: types.StringValue(getResp.Application.Description),
Git: applicationResourceGitModel{
RepositoryID: types.StringValue(getResp.Application.GitPath.Repo.Id),
Remote: types.StringValue(getResp.Application.GitPath.Repo.Remote),
Branch: types.StringValue(getResp.Application.GitPath.Repo.Branch),
Path: types.StringValue(getResp.Application.GitPath.Path),
Filename: types.StringValue(getResp.Application.GitPath.ConfigFilename),
},
Expand Down Expand Up @@ -161,18 +158,6 @@ func (a *ApplicationResource) Schema(_ context.Context, _ resource.SchemaRequest
stringplanmodifier.RequiresReplace(),
},
},
"remote": schema.StringAttribute{
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
"branch": schema.StringAttribute{
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
"path": schema.StringAttribute{
Description: "The relative path from the root of repository to the application directory.",
Required: true,
Expand All @@ -195,9 +180,7 @@ func (a *ApplicationResource) Schema(_ context.Context, _ resource.SchemaRequest
func (a *applicationResourceModel) application() *model.Application {
git := &model.ApplicationGitPath{
Repo: &model.ApplicationGitRepository{
Id: a.Git.RepositoryID.ValueString(),
Remote: a.Git.Remote.ValueString(),
Branch: a.Git.Branch.ValueString(),
Id: a.Git.RepositoryID.ValueString(),
},
Path: a.Git.Path.ValueString(),
ConfigFilename: a.Git.Filename.ValueString(),
Expand Down Expand Up @@ -254,6 +237,8 @@ func (a *ApplicationResource) Create(ctx context.Context, req resource.CreateReq
return
}

tflog.Debug(ctx, "AddApplication response", map[string]interface{}{"response_fields": getResp})

state := applicationResourceModel{
ID: types.StringValue(addResp.ApplicationId),
Name: types.StringValue(getResp.Application.Name),
Expand All @@ -263,8 +248,6 @@ func (a *ApplicationResource) Create(ctx context.Context, req resource.CreateReq
Description: types.StringValue(getResp.Application.Description),
Git: applicationResourceGitModel{
RepositoryID: types.StringValue(getResp.Application.GitPath.Repo.Id),
Remote: types.StringValue(getResp.Application.GitPath.Repo.Remote),
Branch: types.StringValue(getResp.Application.GitPath.Repo.Branch),
Path: types.StringValue(getResp.Application.GitPath.Path),
Filename: types.StringValue(getResp.Application.GitPath.ConfigFilename),
},
Expand Down
8 changes: 1 addition & 7 deletions internal/provider/resource_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ func TestAccResourceApplication(t *testing.T) {

appGit := &model.ApplicationGitPath{
Repo: &model.ApplicationGitRepository{
Id: "repo_id",
Remote: "repo_remote",
Branch: "main",
Id: "repo_id",
},
Path: "path/to/config",
ConfigFilename: "testapp.pipecd.yaml",
Expand Down Expand Up @@ -87,8 +85,6 @@ func TestAccResourceApplication(t *testing.T) {
resource.TestCheckResourceAttr("pipecd_application.test", "platform_provider", "test_provider"),
resource.TestCheckResourceAttr("pipecd_application.test", "description", "test description"),
resource.TestCheckResourceAttr("pipecd_application.test", "git.repository_id", "repo_id"),
resource.TestCheckResourceAttr("pipecd_application.test", "git.remote", "repo_remote"),
resource.TestCheckResourceAttr("pipecd_application.test", "git.branch", "main"),
resource.TestCheckResourceAttr("pipecd_application.test", "git.path", "path/to/config"),
resource.TestCheckResourceAttr("pipecd_application.test", "git.filename", "testapp.pipecd.yaml"),
),
Expand All @@ -107,8 +103,6 @@ resource "pipecd_application" "test" {
description = "test description"
git = {
repository_id = "repo_id"
remote = "repo_remote"
branch = "main"
path = "path/to/config"
filename = "testapp.pipecd.yaml"
}
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/resource_piped.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (p *PipedResource) Create(ctx context.Context, req resource.CreateRequest,
Description: types.StringValue(piped.Desc),
APIKey: types.StringValue(registerResp.Key),
}
diags = resp.State.Set(ctx, plan)
diags = resp.State.Set(ctx, &plan)
resp.Diagnostics.Append(diags...)
}

Expand Down Expand Up @@ -188,7 +188,7 @@ func (p *PipedResource) Update(ctx context.Context, req resource.UpdateRequest,
return
}

diags = resp.State.Set(ctx, plan)
diags = resp.State.Set(ctx, &plan)
resp.Diagnostics.Append(diags...)
}

Expand Down

0 comments on commit 93725be

Please sign in to comment.