Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl ResourceProvisioner {
.get("Name")
.and_then(Value::as_str)
.map(str::to_string)
.unwrap_or_else(|| resource.logical_id.clone());
.unwrap_or_else(|| self.physical_name(resource));
let region = &self.region;
let account = &self.account_id;
let app_id = new_app_id();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -991,21 +991,11 @@ impl ResourceProvisioner {
resource: &ResourceDefinition,
) -> Result<ProvisionResult, String> {
let props = &resource.properties;
let generate_distinct_id = props
.get("GenerateDistinctId")
.and_then(|v| v.as_bool())
.unwrap_or(false);
let name = props
.get("Name")
.and_then(|v| v.as_str())
.map(String::from)
.unwrap_or_else(|| {
if generate_distinct_id {
format!("cfn-key-{}-{}", resource.logical_id, apigw_make_id())
} else {
format!("cfn-key-{}", resource.logical_id)
}
});
.unwrap_or_else(|| self.physical_name(resource));
let value = props
.get("Value")
.and_then(|v| v.as_str())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl ResourceProvisioner {
.get("Name")
.and_then(Value::as_str)
.map(str::to_string)
.unwrap_or_else(|| resource.logical_id.clone());
.unwrap_or_else(|| self.physical_name(resource));
let id = fakecloud_core::ids::short_id(7);
let arn = application_arn(&self.region, &self.account_id, &id);

Expand Down Expand Up @@ -79,7 +79,7 @@ impl ResourceProvisioner {
.get("Name")
.and_then(Value::as_str)
.map(str::to_string)
.unwrap_or_else(|| resource.logical_id.clone());
.unwrap_or_else(|| self.physical_name(resource));
let id = fakecloud_core::ids::short_id(7);
let arn = environment_arn(&self.region, &self.account_id, &app_id, &id);

Expand Down Expand Up @@ -154,7 +154,7 @@ impl ResourceProvisioner {
.get("Name")
.and_then(Value::as_str)
.map(str::to_string)
.unwrap_or_else(|| resource.logical_id.clone());
.unwrap_or_else(|| self.physical_name(resource));
let location_uri = props
.get("LocationUri")
.and_then(Value::as_str)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl ResourceProvisioner {
.get("Name")
.and_then(Value::as_str)
.map(str::to_string)
.unwrap_or_else(|| resource.logical_id.clone());
.unwrap_or_else(|| self.physical_name(resource));
let region = &self.region;
let account = &self.account_id;
let arn = format!("arn:aws:appsync:{region}:{account}:apis/{api_id}/datasources/{name}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ impl ResourceProvisioner {
resource: &ResourceDefinition,
) -> Result<ProvisionResult, String> {
let props = &resource.properties;
let generated_name = self.physical_name(resource);
let name = props
.get("Name")
.and_then(|v| v.as_str())
.unwrap_or(&resource.logical_id)
.unwrap_or(&generated_name)
.to_string();
let description = props
.get("Description")
Expand Down Expand Up @@ -142,10 +143,11 @@ impl ResourceProvisioner {
resource: &ResourceDefinition,
) -> Result<ProvisionResult, String> {
let props = &resource.properties;
let generated_name = self.physical_name(resource);
let name = props
.get("Name")
.and_then(|v| v.as_str())
.unwrap_or(&resource.logical_id)
.unwrap_or(&generated_name)
.to_string();
let cat_type = props
.get("Type")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl ResourceProvisioner {
let props = &resource.properties;
let name = prop_str(props, "LaunchConfigurationName")
.map(String::from)
.unwrap_or_else(|| resource.logical_id.clone());
.unwrap_or_else(|| self.physical_name(resource));
let image_id = prop_str(props, "ImageId")
.ok_or("AWS::AutoScaling::LaunchConfiguration requires ImageId")?
.to_string();
Expand Down Expand Up @@ -117,7 +117,7 @@ impl ResourceProvisioner {
let props = &resource.properties;
let name = prop_str(props, "AutoScalingGroupName")
.map(String::from)
.unwrap_or_else(|| resource.logical_id.clone());
.unwrap_or_else(|| self.physical_name(resource));
let min_size = prop_i64(props, "MinSize").unwrap_or(0);
let max_size = prop_i64(props, "MaxSize").unwrap_or(min_size);
let desired = prop_i64(props, "DesiredCapacity").unwrap_or(min_size);
Expand Down
16 changes: 12 additions & 4 deletions crates/fakecloud-cloudformation/src/resource_provisioner/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl ResourceProvisioner {
.get("BackupVaultName")
.and_then(Value::as_str)
.map(str::to_string)
.unwrap_or_else(|| resource.logical_id.clone());
.unwrap_or_else(|| self.physical_name(resource));
let arn = vault_arn(&self.region, &self.account_id, &name);
let encryption = props
.get("EncryptionKeyArn")
Expand Down Expand Up @@ -152,10 +152,11 @@ impl ResourceProvisioner {
.get("BackupPlan")
.filter(|v| v.is_object())
.ok_or("AWS::Backup::BackupPlan requires BackupPlan")?;
let generated_name = self.physical_name(resource);
let plan_name = plan_src
.get("BackupPlanName")
.and_then(Value::as_str)
.unwrap_or(&resource.logical_id)
.unwrap_or(&generated_name)
.to_string();

// The CFN `BackupPlan` carries its rules under `BackupPlanRule`; the API
Expand Down Expand Up @@ -225,11 +226,11 @@ impl ResourceProvisioner {
.get("BackupPlan")
.filter(|v| v.is_object())
.ok_or("AWS::Backup::BackupPlan requires BackupPlan")?;
// Leaving BackupPlanName out of an update keeps the plan's name.
let plan_name = plan_src
.get("BackupPlanName")
.and_then(Value::as_str)
.unwrap_or(&resource.logical_id)
.to_string();
.map(str::to_string);
let plan = normalize_backup_plan(plan_src);
let advanced = plan_src
.get("AdvancedBackupSettings")
Expand All @@ -251,6 +252,13 @@ impl ResourceProvisioner {
record.plan = plan;
record.advanced_backup_settings = advanced;
record.version_id = version.clone();
let plan_name = plan_name.unwrap_or_else(|| {
record
.versions
.last()
.map(|v| v.plan_name.clone())
.unwrap_or_default()
});
record.versions.push(PlanVersion {
version_id: version.clone(),
creation_date: now,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl ResourceProvisioner {
let props = &resource.properties;
let name = prop_str(props, "ComputeEnvironmentName")
.map(String::from)
.unwrap_or_else(|| resource.logical_id.clone());
.unwrap_or_else(|| self.physical_name(resource));
let arn = self.batch_arn("compute-environment", &name);
let uuid = Uuid::new_v4().to_string();
let mut stored = Map::new();
Expand Down Expand Up @@ -113,7 +113,7 @@ impl ResourceProvisioner {
let props = &resource.properties;
let name = prop_str(props, "JobQueueName")
.map(String::from)
.unwrap_or_else(|| resource.logical_id.clone());
.unwrap_or_else(|| self.physical_name(resource));
let arn = self.batch_arn("job-queue", &name);
let mut stored = Map::new();
stored.insert("jobQueueName".into(), json!(name));
Expand Down Expand Up @@ -152,7 +152,7 @@ impl ResourceProvisioner {
let props = &resource.properties;
let name = prop_str(props, "JobDefinitionName")
.map(String::from)
.unwrap_or_else(|| resource.logical_id.clone());
.unwrap_or_else(|| self.physical_name(resource));
let arn;
{
let mut state = self.batch_state.write();
Expand Down Expand Up @@ -219,7 +219,7 @@ impl ResourceProvisioner {
let props = &resource.properties;
let name = prop_str(props, "Name")
.map(String::from)
.unwrap_or_else(|| resource.logical_id.clone());
.unwrap_or_else(|| self.physical_name(resource));
let arn = format!(
"arn:aws:batch:{}:{}:scheduling-policy/{name}",
self.region, self.account_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,8 @@ impl ResourceProvisioner {
let parsed = crate::template::parse_template(&template_body, &child_parameters)
.map_err(|e| format!("Failed to parse nested template: {e}"))?;

let child_stack_name = format!(
"{}-Nested-{}",
resource.logical_id,
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map(|d| d.as_nanos())
.unwrap_or(0)
);
// AWS names a nested stack `{ParentStack}-{LogicalId}-{SUFFIX}`.
let child_stack_name = self.physical_name(resource);
let child_stack_id = format!(
"arn:aws:cloudformation:{}:{}:stack/{}/{}",
self.region,
Expand Down Expand Up @@ -155,6 +149,7 @@ impl ResourceProvisioner {
region: self.region.clone(),
stack_id: child_stack_id.clone(),
strict_unknown_types: self.strict_unknown_types,
reused_names: Default::default(),
};

let child_resources = crate::service::provision_stack_resources(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl ResourceProvisioner {
.and_then(|v| v.as_str())
.unwrap_or("")
.to_string();
let caller_reference = format!("cfn-{}", resource.logical_id);
let caller_reference = self.physical_name(resource);

let id = format!("E{}", fakecloud_core::ids::short_id(13).to_uppercase());
let etag = format!("E{}", fakecloud_core::ids::short_id(7).to_uppercase());
Expand Down Expand Up @@ -504,7 +504,7 @@ impl ResourceProvisioner {
.unwrap_or("")
.to_string();
let caller_reference = if caller_reference.is_empty() {
format!("cfn-{}", resource.logical_id)
self.physical_name(resource)
} else {
caller_reference
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ impl ResourceProvisioner {
resource: &ResourceDefinition,
) -> Result<ProvisionResult, String> {
let props = &resource.properties;
let generated_name = self.physical_name(resource);
let alarm_name = props
.get("AlarmName")
.and_then(|v| v.as_str())
.unwrap_or(&resource.logical_id)
.unwrap_or(&generated_name)
.to_string();
let alarm_description = props
.get("AlarmDescription")
Expand Down Expand Up @@ -219,10 +220,7 @@ impl ResourceProvisioner {
.get("DashboardName")
.and_then(|v| v.as_str())
.map(String::from)
.unwrap_or_else(|| {
let suffix = Uuid::new_v4().simple().to_string();
format!("{}-{}", resource.logical_id, &suffix[..8])
});
.unwrap_or_else(|| self.physical_name(resource));
// CFN passes DashboardBody as a JSON string (Fn::Sub friendly).
let body = props
.get("DashboardBody")
Expand Down Expand Up @@ -272,7 +270,7 @@ impl ResourceProvisioner {
let new_alarm_name = props
.get("AlarmName")
.and_then(|v| v.as_str())
.unwrap_or(&new_def.logical_id);
.unwrap_or(&existing.physical_id);
if new_alarm_name != existing.physical_id {
return Err(
"AWS::CloudWatch::Alarm updates that change AlarmName require replacement"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl ResourceProvisioner {
resource: &ResourceDefinition,
) -> Result<ProvisionResult, String> {
let props = &resource.properties;
let name = ca_str(props, "DomainName").unwrap_or_else(|| resource.logical_id.clone());
let name = ca_str(props, "DomainName").unwrap_or_else(|| self.physical_name(resource));
let owner = self.account_id.clone();
let region = self.region.clone();
let arn = format!("arn:aws:codeartifact:{region}:{owner}:domain/{name}");
Expand Down Expand Up @@ -90,7 +90,7 @@ impl ResourceProvisioner {
let old_name = ca_suffix(&existing.physical_id, "domain/")
.ok_or_else(|| "corrupt CodeArtifact domain physical id".to_string())?
.to_string();
let new_name = ca_str(props, "DomainName").unwrap_or_else(|| existing.logical_id.clone());
let new_name = ca_str(props, "DomainName").unwrap_or_else(|| old_name.clone());
let new_enc = ca_str(props, "EncryptionKey");

// DomainName and EncryptionKey are both replacement-required on the CFN
Expand Down Expand Up @@ -183,7 +183,7 @@ impl ResourceProvisioner {
resource: &ResourceDefinition,
) -> Result<ProvisionResult, String> {
let props = &resource.properties;
let repo = ca_str(props, "RepositoryName").unwrap_or_else(|| resource.logical_id.clone());
let repo = ca_str(props, "RepositoryName").unwrap_or_else(|| self.physical_name(resource));
let domain = ca_str(props, "DomainName")
.ok_or_else(|| "AWS::CodeArtifact::Repository requires DomainName".to_string())?;
let owner = ca_str(props, "DomainOwner").unwrap_or_else(|| self.account_id.clone());
Expand Down Expand Up @@ -253,8 +253,7 @@ impl ResourceProvisioner {
.ok_or_else(|| "corrupt CodeArtifact repository key".to_string())?;
let old_owner = ca_arn_account(&existing.physical_id).unwrap_or(&self.account_id);

let new_repo =
ca_str(props, "RepositoryName").unwrap_or_else(|| existing.logical_id.clone());
let new_repo = ca_str(props, "RepositoryName").unwrap_or_else(|| old_repo.to_string());
let new_domain = ca_str(props, "DomainName")
.ok_or_else(|| "AWS::CodeArtifact::Repository requires DomainName".to_string())?;
let new_owner = ca_str(props, "DomainOwner").unwrap_or_else(|| self.account_id.clone());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl ResourceProvisioner {
.get("Name")
.and_then(Value::as_str)
.map(str::to_string)
.unwrap_or_else(|| resource.logical_id.clone());
.unwrap_or_else(|| self.physical_name(resource));
let region = &self.region;
let account = &self.account_id;
let arn = format!("arn:aws:codebuild:{region}:{account}:project/{name}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl ResourceProvisioner {
resource: &ResourceDefinition,
) -> Result<ProvisionResult, String> {
let props = &resource.properties;
let name = cc_str(props, "RepositoryName").unwrap_or_else(|| resource.logical_id.clone());
let name = cc_str(props, "RepositoryName").unwrap_or_else(|| self.physical_name(resource));
let account = self.account_id.clone();
let region = self.region.clone();
let arn = format!("arn:aws:codecommit:{region}:{account}:{name}");
Expand Down Expand Up @@ -101,8 +101,7 @@ impl ResourceProvisioner {
) -> Result<ProvisionResult, String> {
let props = &resource.properties;
let old_name = existing.physical_id.clone();
let new_name =
cc_str(props, "RepositoryName").unwrap_or_else(|| existing.logical_id.clone());
let new_name = cc_str(props, "RepositoryName").unwrap_or_else(|| old_name.clone());

// RepositoryName is replacement-required on the CFN resource -- a rename
// re-provisions the repository from scratch.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl ResourceProvisioner {
.get("ApplicationName")
.and_then(Value::as_str)
.map(str::to_string)
.unwrap_or_else(|| resource.logical_id.clone());
.unwrap_or_else(|| self.physical_name(resource));
let compute = props
.get("ComputePlatform")
.and_then(Value::as_str)
Expand Down Expand Up @@ -96,7 +96,7 @@ impl ResourceProvisioner {
.get("DeploymentGroupName")
.and_then(Value::as_str)
.map(str::to_string)
.unwrap_or_else(|| resource.logical_id.clone());
.unwrap_or_else(|| self.physical_name(resource));
let service_role = props
.get("ServiceRoleArn")
.and_then(Value::as_str)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl ResourceProvisioner {
.or_else(|| props.get("Name"))
.and_then(Value::as_str)
.map(str::to_string)
.unwrap_or_else(|| resource.logical_id.clone());
.unwrap_or_else(|| self.physical_name(resource));

// Build the camelCase PipelineDeclaration the service stores. Action
// `Configuration` maps are provider-defined free-form keys AWS preserves
Expand Down
Loading
Loading