Skip to content

Commit

Permalink
Fix: Invalid resource name during make deploy
Browse files Browse the repository at this point in the history
Regression from 8c4ff44

https://gitlab.anvil.gi.ucsc.edu/ucsc/azul/-/jobs/57342
https://gitlab.dev.singlecell.gi.ucsc.edu/ucsc/azul/-/jobs/109690

Only occurs when log forwarding is enabled

python api_gateway.tf.json.template.py api_gateway.tf.json
Traceback (most recent call last):
  File "/builds/ucsc/azul/terraform/api_gateway.tf.json.template.py", line 122, in <module>
    emit_tf({
  File "/builds/ucsc/azul/src/azul/terraform.py", line 160, in emit_tf
    emit(_transform_tf(config, tag_resources=tag_resources))
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/builds/ucsc/azul/src/azul/terraform.py", line 261, in _transform_tf
    _tagged_resource(resource_type, resource_name, resource)
  File "/builds/ucsc/azul/src/azul/terraform.py", line 279, in _tagged_resource
    'tags': _tags(resource_type, resource_name, tags)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/builds/ucsc/azul/src/azul/terraform.py", line 331, in _tags
    'name': config.qualified_resource_name(resource_name),
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/builds/ucsc/azul/src/azul/__init__.py", line 561, in qualified_resource_name
    self._validate_term(resource_name)
  File "/builds/ucsc/azul/src/azul/__init__.py", line 1371, in _validate_term
    require(cls._is_valid_term(term),
  File "/builds/ucsc/azul/src/azul/__init__.py", line 1849, in require
    reject(not condition, *args, exception=exception)
  File "/builds/ucsc/azul/src/azul/__init__.py", line 1869, in reject
    raise exception(*args)
azul.RequirementError: Term is either too short, too long or contains invalid characters: 'indexer_forward_alb_logs-s3event'
make[1]: *** [../common.mk:119: api_gateway.tf.json] Error 1
make[1]: Leaving directory '/builds/ucsc/azul/terraform'
make: *** [Makefile:114: auto_terraform] Error 2
Cleaning up project directory and file based variables 00:01
ERROR: Job failed: exit code 1
  • Loading branch information
hannes-ucsc committed Feb 5, 2025
1 parent 78673ba commit 8cabfae
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/azul/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
cache,
cached_property,
config,
iif,
require,
)
from azul.chalice import (
Expand Down Expand Up @@ -81,7 +80,7 @@ def store(self):

class Terraform:

def taggable_resource_types(self) -> Sequence[str]:
def taggable_resource_types(self) -> set[str]:
schema = self.schema.document
version = schema['format_version']
require(version == '1.0', 'Unexpected format version', version)
Expand All @@ -90,11 +89,11 @@ def taggable_resource_types(self) -> Sequence[str]:
for provider in schema['provider_schemas'].values()
if 'resource_schemas' in provider
)
return [
return {
resource_type
for resource_type, resource in resources
if 'tags' in resource['block']['attributes']
]
}

def run(self, *args: str, **kwargs) -> str:
args = ['terraform', *args]
Expand Down Expand Up @@ -246,19 +245,18 @@ def _transform_tf(tf_config: JSON, *, tag_resources: bool = True) -> JSON:
Add tags to all taggable resources and change the `name` tag to `Name`
for tagged AWS resources.
"""
taggable_types = terraform.taggable_resource_types()
taggable_types = terraform.taggable_resource_types() if tag_resources else {}
return json_mapping(_sanitize_tf({
block_name: _sanitize_tf([
_sanitize_tf({
resource_type: _sanitize_tf([
{
resource_name: {
**resource,
**iif(
tag_resources
and block_name == 'resource'
and resource_type in taggable_types,
**(
_tagged_resource(resource_type, resource_name, resource)
if block_name == 'resource' and resource_type in taggable_types else
{}
)
}
}
Expand Down

0 comments on commit 8cabfae

Please sign in to comment.