| 208 | } |
| 209 | |
| 210 | func (p *Parser) WorkspaceTagDefaults(ctx context.Context) (map[string]string, error) { |
| 211 | // This only gets us the expressions. We need to evaluate them. |
| 212 | // Example: var.region -> "us" |
| 213 | tags, requiredVars, err := p.WorkspaceTags(ctx) |
| 214 | if err != nil { |
| 215 | return nil, xerrors.Errorf("extract workspace tags: %w", err) |
| 216 | } |
| 217 | |
| 218 | if len(tags) == 0 { |
| 219 | return map[string]string{}, nil |
| 220 | } |
| 221 | |
| 222 | // To evaluate the expressions, we need to load the default values for |
| 223 | // variables and parameters. |
| 224 | varsDefaults, err := p.VariableDefaults(ctx) |
| 225 | if err != nil { |
| 226 | return nil, xerrors.Errorf("load variable defaults: %w", err) |
| 227 | } |
| 228 | paramsDefaults, err := p.CoderParameterDefaults(ctx, varsDefaults, requiredVars) |
| 229 | if err != nil { |
| 230 | return nil, xerrors.Errorf("load parameter defaults: %w", err) |
| 231 | } |
| 232 | |
| 233 | // Evaluate the tags expressions given the inputs. |
| 234 | // This will resolve any variables or parameters to their default |
| 235 | // values. |
| 236 | evalTags, err := evaluateWorkspaceTags(varsDefaults, paramsDefaults, tags) |
| 237 | if err != nil { |
| 238 | return nil, xerrors.Errorf("eval provisioner tags: %w", err) |
| 239 | } |
| 240 | |
| 241 | return evalTags, nil |
| 242 | } |
| 243 | |
| 244 | // TemplateVariables returns all of the Terraform variables in the module |
| 245 | // as TemplateVariables. |