Skip to content

Commit 1db4bcd

Browse files
authored
Merge pull request #296 from DontShaveTheYak/develop
Release v0.8.0
2 parents 74c8b67 + b5d3cd6 commit 1db4bcd

File tree

10 files changed

+166
-149
lines changed

10 files changed

+166
-149
lines changed

.devcontainer/Dockerfile

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
FROM ubuntu:22.04
1+
FROM ubuntu:24.04
22

3-
ARG USERNAME=vscode
3+
ARG USERNAME=ubuntu
44
ARG USER_UID=1000
55
ARG USER_GID=$USER_UID
66

77
# Ensure apt is in non-interactive to avoid prompts
88
ENV DEBIAN_FRONTEND=noninteractive
99

1010
# Create the user
11-
RUN groupadd --gid $USER_GID $USERNAME \
12-
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
13-
#
14-
# [Optional] Add sudo support. Omit if you don't need to install software after connecting.
15-
&& apt-get update \
11+
RUN apt-get update \
1612
&& apt-get install -y sudo \
1713
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
1814
&& chmod 0440 /etc/sudoers.d/$USERNAME
@@ -43,12 +39,12 @@ SHELL ["/bin/bash","--login", "-c"]
4339

4440
# Stuff needed to make pyenv work correctly since the login shell
4541
# above doesnt seem to run bachrc
46-
ENV PYENV_ROOT="/home/vscode/.pyenv"
42+
ENV PYENV_ROOT="/home/ubuntu/.pyenv"
4743
ENV PATH $PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH
4844

4945

5046
# Install the required python versions (this takes a bit usually) so we do lots of cacheing
51-
RUN --mount=type=cache,target=/home/vscode/.pyenv/cache,uid=1000 \
47+
RUN --mount=type=cache,target=/home/ubuntu/.pyenv/cache,uid=1000 \
5248
pyenv install -s 3.8.18 && \
5349
pyenv install -s 3.9.18 && \
5450
pyenv install -s 3.10.13 && \

.devcontainer/devcontainer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@
3939
"postCreateCommand": "poetry install && pre-commit install",
4040
// "postStartCommand": "",
4141
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
42-
"remoteUser": "vscode"
42+
"remoteUser": "ubuntu"
4343
}

.github/workflows/release.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
steps:
2121

2222
- name: Checkout Code
23-
uses: actions/[email protected].1
23+
uses: actions/[email protected].4
2424
with:
2525
fetch-depth: 0
2626

@@ -75,7 +75,7 @@ jobs:
7575
needs: tag
7676
steps:
7777
- name: Checkout Code
78-
uses: actions/[email protected].1
78+
uses: actions/[email protected].4
7979

8080
- name: Setup Python 3.11
8181
uses: actions/[email protected]

.github/workflows/test.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
name: Python 3.11
1414
steps:
1515
- name: Checkout Code
16-
uses: actions/[email protected].1
16+
uses: actions/[email protected].4
1717

1818
- name: Setup Latest Python
1919
uses: actions/[email protected]
@@ -39,7 +39,7 @@ jobs:
3939
run: coverage xml --fail-under=0
4040

4141
- name: Upload coverage to Codecov
42-
uses: codecov/[email protected].0
42+
uses: codecov/[email protected].1
4343
with:
4444
token: ${{ secrets.CODECOV_TOKEN }}
4545
flags: unit
@@ -54,7 +54,7 @@ jobs:
5454
name: Python ${{ matrix.python-version }}
5555
steps:
5656
- name: Checkout Code
57-
uses: actions/[email protected].1
57+
uses: actions/[email protected].4
5858

5959
- name: Setup Python ${{ matrix.python-version }}
6060
uses: actions/[email protected]

poetry.lock

+112-112
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cf2tf/conversion/overrides.py

+25-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from typing import TYPE_CHECKING, Callable, Dict
22

3+
from cf2tf.terraform.hcl2.complex import ListType, MapType
34
from cf2tf.terraform.hcl2.custom import LiteralType
45
from cf2tf.terraform.hcl2.primitive import NullType, StringType, TerraformType
5-
from cf2tf.terraform.hcl2.complex import ListType, MapType
66

77
if TYPE_CHECKING:
88
from cf2tf.convert import TemplateConverter
@@ -50,14 +50,33 @@ def tag_conversion(_tc: "TemplateConverter", params: CFParams) -> CFParams:
5050
if isinstance(params["Tags"], dict):
5151
return params
5252

53-
orginal_tags: ListType = params["Tags"] # type: ignore
53+
original_tags: ListType = params["Tags"] # type: ignore
5454

55-
new_tags = {LiteralType(tag["Key"]): tag["Value"] for tag in orginal_tags}
55+
first_item = original_tags[0]
5656

57-
del params["Tags"]
58-
params["tags"] = MapType(new_tags)
57+
# It's possible that the tags might be one or more
58+
# conditional statements of LiteralType
59+
# This wont fix every case, but it should fix most
60+
# and it's better than nothing
61+
if not isinstance(first_item, (dict, MapType)):
62+
del params["Tags"]
63+
params["tags"] = first_item
64+
return params
5965

60-
return params
66+
try:
67+
new_tags = {LiteralType(tag["Key"]): tag["Value"] for tag in original_tags}
68+
69+
del params["Tags"]
70+
params["tags"] = MapType(new_tags)
71+
return params
72+
except Exception:
73+
del params["Tags"]
74+
params["tags"] = LiteralType(
75+
f"// Could not convert tags: {original_tags.render(4)}"
76+
)
77+
return params
78+
79+
raise Exception("Could not convert tags")
6180

6281

6382
OVERRIDE_DISPATCH: ResourceOverride = {

src/cf2tf/convert.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ def add_space():
622622
def perform_resource_overrides(
623623
tf_type: str, params: Dict[str, TerraformType], tc: TemplateConverter
624624
):
625-
log.debug("Overiding params for {tf_type}")
625+
log.debug(f"Overiding params for {tf_type}")
626626
if tf_type not in OVERRIDE_DISPATCH:
627627
return params
628628

@@ -638,7 +638,7 @@ def perform_resource_overrides(
638638
def perform_global_overrides(
639639
tf_type: str, params: Dict[str, TerraformType], tc: TemplateConverter
640640
):
641-
log.debug("Performing global overrides for {tf_type}")
641+
log.debug(f"Performing global overrides for {tf_type}")
642642

643643
for param, override in GLOBAL_OVERRIDES.items():
644644
if param in params:

src/cf2tf/terraform/code.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import logging
22
import re
33
from pathlib import Path
4+
from shutil import rmtree
45
from tempfile import gettempdir
56
from typing import Optional
6-
from shutil import rmtree
77

88
import click
99
from click._termui_impl import ProgressBar
1010
from git import RemoteProgress
11-
from git.repo.base import Repo, InvalidGitRepositoryError
11+
from git.repo.base import InvalidGitRepositoryError, Repo
1212
from thefuzz import fuzz, process # type: ignore
1313

14-
import cf2tf.convert
14+
# import cf2tf.convert
1515

1616
log = logging.getLogger("cf2tf")
1717

@@ -35,7 +35,7 @@ def find(self, resource_type: str) -> Path:
3535
ranking: int
3636
doc_path: Path
3737
resource_name, ranking, doc_path = process.extractOne(
38-
name.lower(), files, scorer=fuzz.token_sort_ratio
38+
name.lower(), files, scorer=fuzz.ratio
3939
)
4040

4141
log.debug(
@@ -109,9 +109,11 @@ def resource_type_to_name(resource_type: str) -> str:
109109

110110
search_tokens = resource_type.replace("::", " ").replace("AWS", " ").split(" ")
111111

112-
for i, token in enumerate(search_tokens):
113-
if len(token) >= 4:
114-
search_tokens[i] = cf2tf.convert.camel_case_split(token)
112+
# I will leave the logic for camel case splitting here for now.
113+
# in case we want to use it later.
114+
# for i, token in enumerate(search_tokens):
115+
# if len(token) >= 4:
116+
# search_tokens[i] = cf2tf.convert.camel_case_split(token)
115117

116118
search_term = " ".join(search_tokens).lower().strip()
117119

src/cf2tf/terraform/doc_file.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
import logging
2+
import re
13
from io import TextIOWrapper
24
from pathlib import Path
35
from typing import List
4-
import re
5-
6-
import logging
76

87
log = logging.getLogger("cf2tf")
98

@@ -89,7 +88,7 @@ def parse_items(file: TextIOWrapper):
8988
continue
9089

9190
# These should be the attributes we are after
92-
if line[0] == "*":
91+
if line[0] == "*" or line[0] == "-":
9392
regex = r"`([\w.*]+)`"
9493

9594
match = re.search(regex, line)

tests/test_terraform/test_code.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from cf2tf.terraform.code import (
66
SearchManager,
77
resource_type_to_name,
8-
transform_file_name,
98
search_manager,
9+
transform_file_name,
1010
)
1111

1212

@@ -31,6 +31,7 @@ def test_sm_(mock_sm: SearchManager):
3131
("AWS::Lambda::Function", "lambda_function.html.markdown"),
3232
("AWS::Events::Rule", "cloudwatch_event_rule.html.markdown"),
3333
("AWS::Cognito::UserPool", "cognito_user_pool.html.markdown"),
34+
("AWS::AutoScaling::AutoScalingGroup", "autoscaling_group.html.markdown"),
3435
]
3536

3637

@@ -51,8 +52,8 @@ def test_transform_file_name():
5152

5253
type_to_name_tests = [
5354
("AWS::Ec2::Instance", "ec2 instance"),
54-
("AWS::EC2::RouteTable", "ec2 route table"),
55-
("AWS::RDS::DBSubnetGroup", "rds db subnet group"),
55+
("AWS::EC2::RouteTable", "ec2 routetable"),
56+
("AWS::RDS::DBSubnetGroup", "rds dbsubnetgroup"),
5657
("AWS::S3::Bucket", "s3 bucket"),
5758
]
5859

0 commit comments

Comments
 (0)