Repository: gitlabform/gitlabform
Issue: Protecting environment using group name returns error

**Describe the bug**

When trying to protect an environment using `group` with group name (https://gitlabform.github.io/gitlabform/reference/protected_environments/), the GitLab API returns the error `Deploy access levels is too short (minimum is 1 character)`. Seems like the API does not support `group`(https://docs.gitlab.com/ee/api/protected_environments.html#protect-a-single-environment), switching to `group_id` worked.

**GitLabForm version**
3.4.1

**GitLab version**
15.7.7-ee


Changed files:
gitlabform/configuration/transform.py, tests/acceptance/premium/test_protected_environments.py

diff --git a/gitlabform/configuration/transform.py b/gitlabform/configuration/transform.py
index 5f27ad1..618fea8 100644
--- a/gitlabform/configuration/transform.py
+++ b/gitlabform/configuration/transform.py
@@ -119,6 +119,19 @@ class GroupTransformer(ConfigurationTransformer):
         logging_args = SimpleNamespace(quiet=False, verbose=False, debug=False)
         processor = Processor(ConsolePrinter(logging_args), configuration.config)
 
+        try:
+            for node_coordinate in processor.get_nodes(
+                "projects_and_groups.*.protected_environments.*.deploy_access_levels.group",
+                mustexist=True,
+            ):
+                group = node_coordinate.parent.pop("group")
+                node_coordinate.parent["group_id"] = self.gitlab._get_group_id(group)
+
+        except YAMLPathException as e:
+            # this just means that we haven't found any keys in YAML
+            # under the given path
+            pass
+
         try:
             for node_coordinate in processor.get_nodes(
                 "**.merge_requests_approval_rules.*.groups",
diff --git a/tests/acceptance/premium/test_protected_environments.py b/tests/acceptance/premium/test_protected_environments.py
index a38dafd..04e6c90 100644
--- a/tests/acceptance/premium/test_protected_environments.py
+++ b/tests/acceptance/premium/test_protected_environments.py
@@ -144,3 +144,74 @@ class TestProtectedEnvironments:
         )
 
         assert len(protected_envs_under_this_project) == 0
+
+    @pytest.mark.skipif(
+        gl.has_no_license(), reason="this test requires a GitLab license (Paid/Trial)"
+    )
+    def test__protect_a_repository_environment_group_name(
+        self, gitlab, group_and_project, other_group
+    ):
+        config = f"""
+            projects_and_groups:
+              {group_and_project}:
+                members:
+                  groups:
+                    {other_group}:
+                      group_access: {AccessLevel.MAINTAINER.value}
+                protected_environments:
+                  enforce: true
+                  foo:
+                    deploy_access_levels:
+                      - group: {other_group}
+            """
+
+        run_gitlabform(config, group_and_project)
+
+        protected_envs_under_this_project = gitlab.list_protected_environments(
+            group_and_project
+        )
+
+        group_id = gitlab._get_group_id(other_group)
+        assert len(protected_envs_under_this_project) == 1
+        assert protected_envs_under_this_project[0]["name"] == "foo"
+        assert len(protected_envs_under_this_project[0]["deploy_access_levels"]) == 1
+        assert (
+            protected_envs_under_this_project[0]["deploy_access_levels"][0]["group_id"]
+            == group_id
+        )
+
+    @pytest.mark.skipif(
+        gl.has_no_license(), reason="this test requires a GitLab license (Paid/Trial)"
+    )
+    def test__protect_a_repository_environment_group_id(
+        self, gitlab, group_and_project, other_group
+    ):
+        group_id = gitlab._get_group_id(other_group)
+
+        config = f"""
+            projects_and_groups:
+              {group_and_project}:
+                members:
+                  groups:
+                    {other_group}:
+                      group_access: {AccessLevel.MAINTAINER.value}
+                protected_environments:
+                  enforce: true
+                  foo:
+                    deploy_access_levels:
+                      - group_id: {group_id}
+            """
+
+        run_gitlabform(config, group_and_project)
+
+        protected_envs_under_this_project = gitlab.list_protected_environments(
+            group_and_project
+        )
+
+        assert len(protected_envs_under_this_project) == 1
+        assert protected_envs_under_this_project[0]["name"] == "foo"
+        assert len(protected_envs_under_this_project[0]["deploy_access_levels"]) == 1
+        assert (
+            protected_envs_under_this_project[0]["deploy_access_levels"][0]["group_id"]
+            == group_id
+        )