Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hostkey_algos to the git.ssh schema #679

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ Optional:

Optional:

- `hostkey_algos` (List of String) The list of hostkey algorithms to use for ssh connections, arranged from most preferred to the least.
- `password` (String, Sensitive) Password of the SSH private key.
- `private_key` (String, Sensitive) Private key used for authenticating to the Git SSH server.
- `username` (String) Username for Git SSH server.
Expand Down
21 changes: 18 additions & 3 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"
"path/filepath"

"github.com/fluxcd/pkg/git"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/path"
Expand All @@ -43,9 +44,10 @@ const (
var EmbeddedManifests string

type Ssh struct {
Username types.String `tfsdk:"username"`
Password types.String `tfsdk:"password"`
PrivateKey types.String `tfsdk:"private_key"`
Username types.String `tfsdk:"username"`
Password types.String `tfsdk:"password"`
PrivateKey types.String `tfsdk:"private_key"`
HostKeyAlgos types.List `tfsdk:"hostkey_algos"`
}

type Http struct {
Expand Down Expand Up @@ -264,6 +266,11 @@ func (p *fluxProvider) Schema(ctx context.Context, req provider.SchemaRequest, r
Optional: true,
Sensitive: true,
},
"hostkey_algos": schema.ListAttribute{
ElementType: types.StringType,
Description: "The list of hostkey algorithms to use for ssh connections, arranged from most preferred to the least.",
Optional: true,
},
},
Optional: true,
},
Expand Down Expand Up @@ -374,6 +381,14 @@ func (p *fluxProvider) Configure(ctx context.Context, req provider.ConfigureRequ
}
}

if data.Git.Ssh != nil && !data.Git.Ssh.HostKeyAlgos.IsNull() && len(data.Git.Ssh.HostKeyAlgos.Elements()) > 0 {
elements := make([]types.String, 0, len(data.Git.Ssh.HostKeyAlgos.Elements()))
data.Git.Ssh.HostKeyAlgos.ElementsAs(ctx, &elements, false)
for _, algo := range elements {
git.HostKeyAlgos = append(git.HostKeyAlgos, algo.ValueString())
}
}

prd, err := NewProviderResourceData(ctx, data)
if err != nil {
resp.Diagnostics.AddError("Could not create provider resource data", err.Error())
Expand Down
1 change: 1 addition & 0 deletions internal/provider/resource_bootstrap_git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ func bootstrapGitSSH(env environment) string {
url = "%s"
ssh = {
username = "git"
hostkey_algos = ["rsa-sha2-512", "rsa-sha2-256"]
private_key = <<EOF
%s
EOF
Expand Down
Loading