in internal/stack/environment.go [31:128]
func (p *environmentProvider) BootUp(ctx context.Context, options Options) error {
logger.Warn("Configuring an stack from environment variables is in technical preview")
config := Config{
Provider: ProviderEnvironment,
ElasticsearchAPIKey: os.Getenv(ElasticsearchAPIKeyEnv),
ElasticsearchHost: os.Getenv(ElasticsearchHostEnv),
ElasticsearchUsername: os.Getenv(ElasticsearchUsernameEnv),
ElasticsearchPassword: os.Getenv(ElasticsearchPasswordEnv),
KibanaHost: os.Getenv(KibanaHostEnv),
CACertFile: os.Getenv(CACertificateEnv),
Parameters: make(map[string]string),
}
if err := requiredEnv(config.ElasticsearchHost, ElasticsearchHostEnv); err != nil {
return err
}
if err := requiredEnv(config.KibanaHost, KibanaHostEnv); err != nil {
return err
}
err := p.initClients()
if err != nil {
return err
}
// TODO: Migrate from serverless variables.
config.Parameters[ParamServerlessLocalStackVersion] = options.StackVersion
config, err = p.setupFleet(ctx, config, options)
if err != nil {
return fmt.Errorf("failed to setup Fleet: %w", err)
}
// We need to store the config here to be able to clean up Fleet if something
// fails later.
err = storeConfig(options.Profile, config)
if err != nil {
return fmt.Errorf("failed to store config: %w", err)
}
logstashEnabled := options.Profile.Config(configLogstashEnabled, "false") == "true"
if logstashEnabled {
err := addLogstashFleetOutput(ctx, p.kibana)
if err != nil {
return fmt.Errorf("failed to create logstash output: %w", err)
}
config.OutputID = fleetLogstashOutput
} else {
internalHost := DockerInternalHost(config.ElasticsearchHost)
if internalHost != config.ElasticsearchHost {
err := addElasticsearchFleetOutput(ctx, p.kibana, internalHost)
if err != nil {
return fmt.Errorf("failed to create elasticsearch output: %w", err)
}
config.OutputID = fleetElasticsearchOutput
}
}
// We need to store the config here to be able to clean up the logstash output if something
// fails later.
err = storeConfig(options.Profile, config)
if err != nil {
return fmt.Errorf("failed to store config: %w", err)
}
selfMonitor := options.Profile.Config(configSelfMonitorEnabled, "false") == "true"
policy, err := createAgentPolicy(ctx, p.kibana, options.StackVersion, config.OutputID, selfMonitor)
if err != nil {
return fmt.Errorf("failed to create agent policy: %w", err)
}
if config.ElasticsearchAPIKey != "" {
config.EnrollmentToken, err = p.kibana.GetEnrollmentTokenForPolicyID(ctx, policy.ID)
if err != nil {
return fmt.Errorf("failed to get an enrollment token for policy %s: %w", policy.Name, err)
}
}
localServices := &localServicesManager{
profile: options.Profile,
}
err = localServices.start(ctx, options, config)
if err != nil {
return fmt.Errorf("failed to start local services: %w", err)
}
if logstashEnabled {
err = updateLogstashFleetOutput(ctx, options.Profile, p.kibana)
if err != nil {
return fmt.Errorf("cannot configure fleet output: %w", err)
}
}
err = storeConfig(options.Profile, config)
if err != nil {
return fmt.Errorf("failed to store config: %w", err)
}
return nil
}