Skip to content

Commit

Permalink
Add ComputedID for resources that need it (#4009)
Browse files Browse the repository at this point in the history
Fixes #4008

The TF bridge currently requires a notion of ID for resources based on
the Plugin Framework. Before these change the following resource used to
panic, now they provision correctly:

- aws_lambda_runtime_management_config
- aws_datazone_environment_blueprint_configuration
- aws_vpc_endpoint_service_private_dns_verification
- aws_vpc_endpoint_private_dns
  • Loading branch information
t0yv0 authored May 31, 2024
1 parent bbb6123 commit d3b3474
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -5911,6 +5911,8 @@ func ProviderFromMeta(metaInfo *tfbridge.MetadataInfo) *tfbridge.ProviderInfo {

prov.MustApplyAutoAliases()

setupComputedIDs(&prov)

return &prov
}

Expand Down Expand Up @@ -6041,3 +6043,33 @@ func hasNonComputedTagsAndTagsAll(tfResourceName string, res shim.Resource) bool
}
return true
}

func setupComputedIDs(prov *tfbridge.ProviderInfo) {
attr := func(state resource.PropertyMap, attrs ...resource.PropertyKey) resource.ID {
parts := []string{}
for _, a := range attrs {
if v, ok := state[a]; ok {
if v.IsString() && v.StringValue() != "" {
parts = append(parts, v.StringValue())
}
}
}
s := strings.Join(parts, "__")
if s == "" {
s = "id"
}
return resource.ID(s)
}
prov.Resources["aws_lambda_runtime_management_config"].ComputeID = func(ctx context.Context, state resource.PropertyMap) (resource.ID, error) {
return attr(state, "functionName", "qualifier"), nil
}
prov.Resources["aws_datazone_environment_blueprint_configuration"].ComputeID = func(ctx context.Context, state resource.PropertyMap) (resource.ID, error) {
return attr(state, "domainId", "environmentBlueprintId"), nil
}
prov.Resources["aws_vpc_endpoint_service_private_dns_verification"].ComputeID = func(ctx context.Context, state resource.PropertyMap) (resource.ID, error) {
return attr(state, "serviceId"), nil
}
prov.Resources["aws_vpc_endpoint_private_dns"].ComputeID = func(ctx context.Context, state resource.PropertyMap) (resource.ID, error) {
return attr(state, "vpcEndpointId"), nil
}
}

0 comments on commit d3b3474

Please sign in to comment.