Skip to content

Commit

Permalink
[create-vm-agent-config-adxt-84] POC with ec2 / microvm
Browse files Browse the repository at this point in the history
  • Loading branch information
CelianR committed Jan 16, 2025
1 parent 80c6293 commit e8742c5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
16 changes: 16 additions & 0 deletions common/config/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const (
DDAgentExtraEnvVars = "extraEnvVars" // extraEnvVars is expected in the format: <key1>=<value1>,<key2>=<value2>,...
DDAgentJMX = "jmx"
DDAgentFIPS = "fips"
DDAgentConfigPathParamName = "configPath"

// Updater Namespace
DDUpdaterParamName = "deploy"
Expand Down Expand Up @@ -445,3 +446,18 @@ func (e *CommonEnvironment) AgentFIPS() bool {
func (e *CommonEnvironment) AgentJMX() bool {
return e.GetBoolWithDefault(e.AgentConfig, DDAgentJMX, false)
}

func (e *CommonEnvironment) AgentConfigPath() string {
return e.AgentConfig.Get(DDAgentConfigPathParamName)
}

func (e *CommonEnvironment) CustomAgentConfig() (string, error) {
configPath := e.AgentConfigPath()
if configPath == "" {
return "", fmt.Errorf("agent config path is empty")
}

config, err := os.ReadFile(configPath)

return string(config), err
}
8 changes: 8 additions & 0 deletions scenarios/aws/ec2/vm_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ func VMRun(ctx *pulumi.Context) error {
agentOptions = append(agentOptions, agentparams.WithFlavor(env.AgentFlavor()))
}

if env.AgentConfigPath() != "" {
configContent, err := env.CustomAgentConfig()
if err != nil {
return err
}
agentOptions = append(agentOptions, agentparams.WithAgentConfig(configContent))
}

agent, err := agent.NewHostAgent(&env, vm, agentOptions...)
if err != nil {
return err
Expand Down
9 changes: 9 additions & 0 deletions scenarios/aws/microVMs/microvms/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ func newMetalInstance(instanceEnv *InstanceEnvironment, name, arch string, m con
agentOptions = append(agentOptions, agentparams.WithFlavor(awsEnv.AgentFlavor()))
}

if awsEnv.AgentConfigPath() != "" {
configContent, err := awsEnv.CustomAgentConfig()
if err != nil {
return nil, err
}

agentOptions = append(agentOptions, agentparams.WithAgentConfig(configContent))
}

_, err := agent.NewHostAgent(awsEnv, awsInstance, agentOptions...)
if err != nil {
awsEnv.Ctx().Log.Warn(fmt.Sprintf("failed to deploy datadog agent on host instance: %v", err), nil)
Expand Down

0 comments on commit e8742c5

Please sign in to comment.