diff --git a/src/damavand/cloud/aws/object_storage.py b/src/damavand/cloud/aws/object_storage.py index 8ec763e..0ef4609 100644 --- a/src/damavand/cloud/aws/object_storage.py +++ b/src/damavand/cloud/aws/object_storage.py @@ -1,3 +1,4 @@ +from functools import cache import boto3 import io import logging @@ -9,7 +10,6 @@ from damavand import utils from damavand.controllers import ObjectStorageController, buildtime, runtime from damavand.errors import ( - CallResourceBeforeProvision, RuntimeException, ObjectNotFound, ResourceAccessDenied, @@ -32,16 +32,11 @@ def __init__( self.__s3_client = boto3.client("s3", region_name=region) @buildtime - def provision(self): - if not self.id_: - self.id_ = self.name - logger.info( - f"Resource ID not provided for bucket with name `{self.name}`, using the name as ID." - ) - - self._pulumi_object = s3.Bucket( - self.id_, - bucket=self.name, + @cache + def resource(self) -> PulumiResource: + return s3.BucketV2( + resource_name=f"{self.name}-bucket", + bucket_prefix=self.name, tags=self.tags, **self.extra_args, ) @@ -123,10 +118,3 @@ def exist(self, path: str) -> bool: raise ResourceAccessDenied(name=self.name) from e case _: raise RuntimeException() from e - - @buildtime - def to_pulumi(self) -> PulumiResource: - if self._pulumi_object is None: - raise CallResourceBeforeProvision() - - return self._pulumi_object diff --git a/src/damavand/controllers/object_storage.py b/src/damavand/controllers/object_storage.py index d6cb724..740793d 100644 --- a/src/damavand/controllers/object_storage.py +++ b/src/damavand/controllers/object_storage.py @@ -13,9 +13,6 @@ def __init__( ) -> None: super().__init__(name, id_, tags, **kwargs) - def provision(self): - raise NotImplementedError - def read(self, path: str) -> bytes: """Read an object from the storage.""" raise NotImplementedError diff --git a/tests/clouds/aws/test_aws_object_storage.py b/tests/clouds/aws/test_aws_object_storage.py index 2a19cb6..d9355fb 100644 --- a/tests/clouds/aws/test_aws_object_storage.py +++ b/tests/clouds/aws/test_aws_object_storage.py @@ -5,7 +5,7 @@ from pulumi_aws import s3 from damavand.cloud.aws import AwsObjectStorageController -from damavand.errors import CallResourceBeforeProvision, ObjectNotFound +from damavand.errors import ObjectNotFound @pytest.fixture @@ -20,22 +20,12 @@ def conn(): return boto3.resource("s3", region_name="us-east-1") -def test_to_pulumi_raise_before_provision( +def test_resource_return_pulumi_s3_bucket_v2( monkeypatch: MonkeyPatch, bucket: AwsObjectStorageController ): monkeypatch.setattr("damavand.utils.is_building", lambda: True) - with pytest.raises(CallResourceBeforeProvision): - bucket.to_pulumi() - - -def test_to_pulumi_return_pulumi_s3_bucket( - monkeypatch: MonkeyPatch, bucket: AwsObjectStorageController -): - monkeypatch.setattr("damavand.utils.is_building", lambda: True) - - bucket.provision() - assert isinstance(bucket.to_pulumi(), s3.Bucket) + assert isinstance(bucket.resource(), s3.BucketV2) @mock_aws