diff --git a/pkg/provider/aws/create-instance.go b/pkg/provider/aws/create-instance.go index 3a08313a..9c3a6b8f 100644 --- a/pkg/provider/aws/create-instance.go +++ b/pkg/provider/aws/create-instance.go @@ -11,6 +11,7 @@ import ( providerAPI "github.com/crc/crc-cloud/pkg/manager/provider/api" "github.com/crc/crc-cloud/pkg/provider/aws/sg" "github.com/crc/crc-cloud/pkg/util" + crctls "github.com/crc/crc-cloud/pkg/util/tls" "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2" "github.com/pulumi/pulumi-tls/sdk/v4/go/tls" "github.com/pulumi/pulumi/sdk/v3/go/pulumi" @@ -118,13 +119,7 @@ func securityGroupsIds(ctx *pulumi.Context) (pulumi.StringArrayInput, error) { } func createKey(ctx *pulumi.Context) (*tls.PrivateKey, *ec2.KeyPair, error) { - pk, err := tls.NewPrivateKey( - ctx, - "OpenshiftLocal-OCP", - &tls.PrivateKeyArgs{ - Algorithm: pulumi.String("RSA"), - RsaBits: pulumi.Int(4096), - }) + pk, err := crctls.CreateKey(ctx) if err != nil { return nil, nil, err } diff --git a/pkg/provider/gcp/create-instance.go b/pkg/provider/gcp/create-instance.go index 41c4f293..b91132c2 100644 --- a/pkg/provider/gcp/create-instance.go +++ b/pkg/provider/gcp/create-instance.go @@ -7,6 +7,7 @@ import ( providerAPI "github.com/crc/crc-cloud/pkg/manager/provider/api" "github.com/crc/crc-cloud/pkg/provider/constants" "github.com/crc/crc-cloud/pkg/util" + crctls "github.com/crc/crc-cloud/pkg/util/tls" "github.com/pulumi/pulumi-gcp/sdk/v6/go/gcp/compute" "github.com/pulumi/pulumi-tls/sdk/v4/go/tls" "github.com/pulumi/pulumi/sdk/v3/go/pulumi" @@ -50,7 +51,7 @@ func fillCreateRequest(projectName, bootingPrivateKeyFilePath, ocpPullSecretFile } func (r createRequest) runFunc(ctx *pulumi.Context) error { - privateKey, err := createKey(ctx) + privateKey, err := crctls.CreateKey(ctx) if err != nil { return err } diff --git a/pkg/util/tls/tls.go b/pkg/util/tls/tls.go new file mode 100644 index 00000000..1b638e30 --- /dev/null +++ b/pkg/util/tls/tls.go @@ -0,0 +1,20 @@ +package tls + +import ( + "github.com/pulumi/pulumi-tls/sdk/v4/go/tls" + "github.com/pulumi/pulumi/sdk/v3/go/pulumi" +) + +func CreateKey(ctx *pulumi.Context) (*tls.PrivateKey, error) { + pk, err := tls.NewPrivateKey( + ctx, + "OpenshiftLocal-OCP", + &tls.PrivateKeyArgs{ + Algorithm: pulumi.String("RSA"), + RsaBits: pulumi.Int(4096), + }) + if err != nil { + return nil, err + } + return pk, nil +}