diff --git a/cli/server.go b/cli/server.go index be3a7fefd2..2880ea1088 100644 --- a/cli/server.go +++ b/cli/server.go @@ -653,6 +653,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd. } options := &coderd.Options{ + ID: uuid.New(), AccessURL: vals.AccessURL.Value(), AppHostname: appHostname, AppHostnameRegex: appHostnameRegex, diff --git a/enterprise/cli/server.go b/enterprise/cli/server.go index 75db53bce2..9a2d930f7a 100644 --- a/enterprise/cli/server.go +++ b/enterprise/cli/server.go @@ -13,7 +13,6 @@ import ( "net/url" "time" - "github.com/google/uuid" "golang.org/x/xerrors" "tailscale.com/derp" "tailscale.com/types/key" @@ -138,10 +137,8 @@ func (r *RootCmd) Server(_ func()) *serpent.Command { if err != nil { return nil, nil, xerrors.Errorf("create DERP mesh TLS config: %w", err) } - replicaID := uuid.New() - options.ID = replicaID replicaManager, err := replicasync.New(ctx, options.Logger, options.Database, options.Pubsub, &replicasync.Options{ - ID: replicaID, + ID: options.ID, RelayAddress: options.DeploymentValues.DERP.Server.RelayURL.String(), // #nosec G115 - DERP region IDs are small and fit in int32 RegionID: int32(options.DeploymentValues.DERP.Server.RegionID.Value()), diff --git a/enterprise/coderd/coderd.go b/enterprise/coderd/coderd.go index fc4484a23f..d71c8d27d5 100644 --- a/enterprise/coderd/coderd.go +++ b/enterprise/coderd/coderd.go @@ -226,11 +226,8 @@ func New(ctx context.Context, options *Options) (_ *API, err error) { // The API replica ID must match the replica manager ID because other // replicas use this ID to relay work back to the owning API instance. - if options.ReplicaManager == nil { - return nil, xerrors.New("replica manager is required") - } - if options.Options.ID == uuid.Nil { - options.Options.ID = options.ReplicaManager.ID() + if options.Options.ID != options.ReplicaManager.ID() { + return nil, xerrors.Errorf("replica manager ID %s does not match coderd ID %s", options.ReplicaManager.ID(), options.Options.ID) } api := &API{ diff --git a/enterprise/coderd/coderdenttest/coderdenttest.go b/enterprise/coderd/coderdenttest/coderdenttest.go index a5d3aac942..b9ba156394 100644 --- a/enterprise/coderd/coderdenttest/coderdenttest.go +++ b/enterprise/coderd/coderdenttest/coderdenttest.go @@ -105,10 +105,17 @@ func NewWithAPI(t *testing.T, options *Options) ( } require.False(t, options.DontAddFirstUser && !options.DontAddLicense, "DontAddFirstUser requires DontAddLicense") setHandler, cancelFunc, serverURL, oop := coderdtest.NewOptions(t, options.Options) + if oop.ID == uuid.Nil { + oop.ID = uuid.New() + } replicaManager := options.ReplicaManager + if replicaManager != nil { + oop.ID = replicaManager.ID() + } if replicaManager == nil { var err error replicaManager, err = replicasync.New(context.Background(), oop.Logger, oop.Database, oop.Pubsub, &replicasync.Options{ + ID: oop.ID, RelayAddress: serverURL.String(), // #nosec G115 - DERP region IDs are small and fit in int32. RegionID: int32(oop.DeploymentValues.DERP.Server.RegionID.Value()),