fix: Parsing dynamic values for agent results in error (#564)

The logic required a constant value before, which disallowed dynamic
value injection into the agent. This isn't an accurate limitation,
so inverting the logic resolves it.
This commit is contained in:
Kyle Carberry
2022-03-25 11:21:39 -06:00
committed by GitHub
parent a06821c103
commit 21fdb80825
2 changed files with 56 additions and 37 deletions

View File

@ -285,25 +285,21 @@ func parseTerraformPlan(ctx context.Context, terraform *tfexec.Terraform, planfi
}
if envRaw, has := resource.Expressions["env"]; has {
env, ok := envRaw.ConstantValue.(map[string]string)
if !ok {
return nil, xerrors.Errorf("unexpected type %T for env map", envRaw.ConstantValue)
if ok {
agent.Env = env
}
agent.Env = env
}
if startupScriptRaw, has := resource.Expressions["startup_script"]; has {
startupScript, ok := startupScriptRaw.ConstantValue.(string)
if !ok {
return nil, xerrors.Errorf("unexpected type %T for startup script", startupScriptRaw.ConstantValue)
if ok {
agent.StartupScript = startupScript
}
agent.StartupScript = startupScript
}
if instanceIDRaw, has := resource.Expressions["instance_id"]; has {
instanceID, ok := instanceIDRaw.ConstantValue.(string)
if !ok {
return nil, xerrors.Errorf("unexpected type %T for instance_id", instanceIDRaw.ConstantValue)
}
if _, has := resource.Expressions["instance_id"]; has {
// This is a dynamic value. If it's expressed, we know
// it's at least an instance ID, which is better than nothing.
agent.Auth = &proto.Agent_InstanceId{
InstanceId: instanceID,
InstanceId: "",
}
}
@ -429,15 +425,6 @@ func parseTerraformApply(ctx context.Context, terraform *tfexec.Terraform, state
}
}
if agent != nil && agent.GetInstanceId() != "" {
// Make sure the instance has an instance ID!
_, exists := resource.AttributeValues["instance_id"]
if !exists {
// This was a mistake!
agent = nil
}
}
resources = append(resources, &proto.Resource{
Name: resource.Name,
Type: resource.Type,