Skip to content

Commit

Permalink
feat: Adding folder and tag_prefix to module resource (#78)
Browse files Browse the repository at this point in the history
* feat: Adding folder and tag_prefix to module resource
  • Loading branch information
BenjaminDecreusefond authored Oct 22, 2024
1 parent b4669fe commit 8171991
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/resources/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ resource "terrakube_module" "module" {

### Optional

- `folder` (String) Folder to look into for module files. Need to preprend a / and append a / to work properly.
- `ssh_id` (String) Ssh connection ID for private modules
- `tag_prefix` (String) Prefix tag mono-repository modules. module/ will pick up any tag starting with 'module/*'
- `vcs_id` (String) VCS connection ID for private modules

### Read-Only
Expand Down
2 changes: 2 additions & 0 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ type ModuleEntity struct {
Source string `jsonapi:"attr,source"`
Vcs *VcsEntity `jsonapi:"relation,vcs,omitempty"`
Ssh *SshEntity `jsonapi:"relation,ssh,omitempty"`
Folder string `jsonapi:"attr,folder"`
TagPrefix string `jsonapi:"attr,tagPrefix"`
}

type WorkspaceWebhookEntity struct {
Expand Down
20 changes: 20 additions & 0 deletions internal/provider/module_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type ModuleResourceModel struct {
Source types.String `tfsdk:"source"`
VcsId types.String `tfsdk:"vcs_id"`
SshId types.String `tfsdk:"ssh_id"`
TagPrefix types.String `tfsdk:"tag_prefix"`
Folder types.String `tfsdk:"folder"`
}

func NewModuleResource() resource.Resource {
Expand Down Expand Up @@ -87,6 +89,14 @@ func (r *ModuleResource) Schema(ctx context.Context, req resource.SchemaRequest,
Optional: true,
Description: "Ssh connection ID for private modules",
},
"tag_prefix": schema.StringAttribute{
Optional: true,
Description: "Prefix tag mono-repository modules. module/ will pick up any tag starting with 'module/*'",
},
"folder": schema.StringAttribute{
Optional: true,
Description: "Folder to look into for module files. Need to preprend a / and append a / to work properly.",
},
},
}
}
Expand Down Expand Up @@ -138,6 +148,8 @@ func (r *ModuleResource) Create(ctx context.Context, req resource.CreateRequest,
Description: plan.Description.ValueString(),
Provider: plan.ProviderName.ValueString(),
Source: plan.Source.ValueString(),
TagPrefix: plan.TagPrefix.ValueString(),
Folder: plan.Folder.ValueString(),
}

if !plan.VcsId.IsNull() {
Expand Down Expand Up @@ -197,6 +209,8 @@ func (r *ModuleResource) Create(ctx context.Context, req resource.CreateRequest,
plan.Description = types.StringValue(newModule.Description)
plan.ProviderName = types.StringValue(newModule.Provider)
plan.Source = types.StringValue(newModule.Source)
plan.TagPrefix = types.StringValue(newModule.TagPrefix)
plan.Folder = types.StringValue(newModule.Folder)

tflog.Info(ctx, "Module Resource Created", map[string]any{"success": true})

Expand Down Expand Up @@ -245,6 +259,8 @@ func (r *ModuleResource) Read(ctx context.Context, req resource.ReadRequest, res
state.Description = types.StringValue(module.Description)
state.ProviderName = types.StringValue(module.Provider)
state.Source = types.StringValue(module.Source)
state.Folder = types.StringValue(module.Folder)
state.TagPrefix = types.StringValue(module.TagPrefix)

if module.Vcs != nil {
state.VcsId = types.StringValue(module.Vcs.ID)
Expand Down Expand Up @@ -280,6 +296,8 @@ func (r *ModuleResource) Update(ctx context.Context, req resource.UpdateRequest,
Description: plan.Name.ValueString(),
Provider: plan.ProviderName.ValueString(),
Source: plan.Source.ValueString(),
Folder: plan.Folder.ValueString(),
TagPrefix: plan.TagPrefix.ValueString(),
}

if !plan.VcsId.IsNull() {
Expand Down Expand Up @@ -355,6 +373,8 @@ func (r *ModuleResource) Update(ctx context.Context, req resource.UpdateRequest,
plan.Description = types.StringValue(module.Description)
plan.ProviderName = types.StringValue(module.Provider)
plan.Source = types.StringValue(module.Source)
plan.TagPrefix = types.StringValue(module.TagPrefix)
plan.Folder = types.StringValue(module.Folder)

resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
}
Expand Down

0 comments on commit 8171991

Please sign in to comment.