Skip to content

Commit

Permalink
Merge pull request #679 from fluxcd/ssh-hostkey-algos
Browse files Browse the repository at this point in the history
Add `hostkey_algos` to the `git.ssh` schema
  • Loading branch information
stefanprodan authored May 2, 2024
2 parents 55d4aba + 87c3122 commit 8c7df3e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
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

0 comments on commit 8c7df3e

Please sign in to comment.