diff options
Diffstat (limited to 'cloudinit/sources')
-rw-r--r-- | cloudinit/sources/DataSourceEc2.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/cloudinit/sources/DataSourceEc2.py b/cloudinit/sources/DataSourceEc2.py index e14553b3..21e9ef84 100644 --- a/cloudinit/sources/DataSourceEc2.py +++ b/cloudinit/sources/DataSourceEc2.py @@ -147,6 +147,12 @@ class DataSourceEc2(sources.DataSource): def get_instance_id(self): if self.cloud_platform == Platforms.AWS: # Prefer the ID from the instance identity document, but fall back + if not getattr(self, 'identity', None): + # If re-using cached datasource, it's get_data run didn't + # setup self.identity. So we need to do that now. + api_version = self.get_metadata_api_version() + self.identity = ec2.get_instance_identity( + api_version, self.metadata_address).get('document', {}) return self.identity.get( 'instanceId', self.metadata['instance-id']) else: |