@@ -18,6 +18,9 @@ def body(self):
1818 tag_protection_config = config .pop ("tag_protection" , {})
1919 deploy_keys_config = config .pop ("deploy_keys" , {})
2020 ruleset_config = config .pop ("repository_ruleset" , {})
21+ actions_config = config .pop ("actions" , {})
22+ access_permissions_config = config .pop ("permissions" , {})
23+ autolink_references_config = config .pop ("autolink" , {})
2124
2225 resource_name = self .name
2326 logger .debug (f"Processing github_repository { resource_name } " )
@@ -43,6 +46,9 @@ def body(self):
4346 branch_protection .filename = "github_branch_protection.tf"
4447 branch_protection .set (branch_protection .config )
4548 branch_protection .add ("repository_id" , repository .get_reference ("node_id" ))
49+ branch_protection .set (
50+ {"pattern" : branches_name }
51+ ) # Ensures the pattern is unique to the branch name and doesn't default to `main`
4652 self .add (branch_protection )
4753
4854 for rule_name , tag_pattern in tag_protection_config .items ():
@@ -84,3 +90,54 @@ def body(self):
8490 repository_ruleset .filename = "github_repository_ruleset.tf"
8591 repository_ruleset .set (repository_ruleset .config )
8692 self .add (repository_ruleset )
93+
94+ if actions_config .get ("access_level" ) is not None :
95+ gha_actions_access = TerraformResource (
96+ id = f"{ resource_id } _actions_access" ,
97+ type = "github_actions_repository_access_level" ,
98+ config = {
99+ "repository" : repository .get_reference ("name" ),
100+ "access_level" : actions_config .get ("access_level" ),
101+ },
102+ )
103+ gha_actions_access .filename = "github_repository_actions.tf"
104+ gha_actions_access .set (gha_actions_access .config )
105+ gha_actions_access .add ("repository" , repository .get_reference ("name" ))
106+ self .add (gha_actions_access )
107+
108+ for permission_type , permission_config in access_permissions_config .items ():
109+ logger .debug (f"Processing permissions for { resource_name } " )
110+ for entity , permission in permission_config .items ():
111+ if permission_type == "team" :
112+ config = {"team_id" : f"{ entity } " , "permission" : f"{ permission } " }
113+ else :
114+ config = {"username" : f"{ entity } " , "permission" : f"{ permission } " }
115+ repository_collaborators = TerraformResource (
116+ id = f"{ resource_name } _access_permissions" .replace ("." , "" ),
117+ type = "github_repository_collaborators" ,
118+ config = config ,
119+ )
120+ repository_collaborators .filename = "github_repository_collaborators.tf"
121+ repository_collaborators .add (
122+ "repository" , repository .get_reference ("name" )
123+ )
124+ repository_collaborators .add (
125+ permission_type , [repository_collaborators .config ]
126+ )
127+ self .add (repository_collaborators )
128+
129+ for key_prefix , target_url in autolink_references_config .items ():
130+ logger .debug (f"Processing autolink referneces for { resource_name } " )
131+ config = {
132+ "key_prefix" : f"{ key_prefix } -" ,
133+ "target_url_template" : f"{ target_url } " ,
134+ }
135+ autolink_references = TerraformResource (
136+ id = f"{ key_prefix } " .replace ("." , "" ),
137+ type = "github_repository_autolink_reference" ,
138+ config = config ,
139+ )
140+ autolink_references .filename = "github_repository_autolink_reference.tf"
141+ autolink_references .set (autolink_references .config )
142+ autolink_references .add ("repository" , repository .get_reference ("name" ))
143+ self .add (autolink_references )
0 commit comments