1- from constructs import Construct
21from cdktf_cdktf_provider_google import (
3- artifact_registry_repository ,
4- artifact_registry_repository_iam_binding ,
5- service_account ,
6- kms_key_ring ,
7- kms_crypto_key ,
8- kms_crypto_key_iam_binding
9- )
2+ artifact_registry_repository , artifact_registry_repository_iam_binding ,
3+ kms_crypto_key , kms_crypto_key_iam_binding , kms_key_ring , service_account )
4+ from constructs import Construct
105
116
127class ArtifactRegistryComponent (Construct ):
138 def __init__ (
14- self ,
15- scope : Construct ,
16- id : str ,
17- project_id : str ,
18- project_number : str ,
19- location : str ,
20- name : str ,
21- cloudrun_account : service_account .ServiceAccount ,
22- flight_controller_key_ring : kms_key_ring .KmsKeyRing ):
9+ self ,
10+ scope : Construct ,
11+ id : str ,
12+ project_id : str ,
13+ project_number : str ,
14+ name_prefix : str ,
15+ location : str ,
16+ cloudrun_account : service_account .ServiceAccount ,
17+ flight_controller_key_ring : kms_key_ring .KmsKeyRing ,
18+ ):
2319 super ().__init__ (scope , id )
2420
2521 registry_key = kms_crypto_key .KmsCryptoKey (
2622 self ,
2723 "registry_key" ,
28- name = "flight_controller_registry_key " ,
24+ name = "registry_key " ,
2925 key_ring = flight_controller_key_ring .id ,
3026 rotation_period = "7776000s" ,
27+ lifecycle = {
28+ "prevent_destroy" : True
29+ }
3130 )
3231
3332 registry_key_iam = kms_crypto_key_iam_binding .KmsCryptoKeyIamBinding (
3433 self ,
3534 "registry_key_iam_binding" ,
3635 crypto_key_id = registry_key .id ,
3736 role = "roles/cloudkms.cryptoKeyEncrypterDecrypter" ,
38-
39- members = [
37+ members = [
4038 f"serviceAccount:service-{ project_number } @gcp-sa-artifactregistry.iam.gserviceaccount.com"
41- ]
39+ ],
4240 )
4341
4442 self .registry = artifact_registry_repository .ArtifactRegistryRepository (
4543 self ,
4644 "registry" ,
47- repository_id = name ,
45+ repository_id = f" { name_prefix } -event-receiver" ,
4846 description = "Registry to store event_receiver docker images" ,
4947 format = "DOCKER" ,
5048 project = project_id ,
5149 location = location ,
5250 kms_key_name = registry_key .id ,
53- depends_on = [
54- registry_key
55- ]
51+ depends_on = [registry_key , registry_key_iam ],
5652 )
5753
58- self .adminbinding = artifact_registry_repository_iam_binding .ArtifactRegistryRepositoryIamBinding (
54+ self .admin_binding = artifact_registry_repository_iam_binding .ArtifactRegistryRepositoryIamBinding (
5955 self ,
6056 "admin" ,
6157 repository = self .registry .id ,
6258 role = "roles/artifactregistry.repoAdmin" ,
6359 members = [
64- "domain:contino.io" ,
65- ]
60+ "domain:contino.io" ,
61+ ],
6662 )
6763
68- self .readerbinding = artifact_registry_repository_iam_binding .ArtifactRegistryRepositoryIamBinding (
64+ self .reader_binding = artifact_registry_repository_iam_binding .ArtifactRegistryRepositoryIamBinding (
6965 self ,
7066 "reader" ,
7167 repository = self .registry .id ,
7268 role = "roles/artifactregistry.reader" ,
73- members = [
74- f"serviceAccount:{ cloudrun_account .email } "
75- ]
76- )
69+ members = [f"serviceAccount:{ cloudrun_account .email } " ],
70+ )
0 commit comments