Skip to content

Commit

Permalink
Add hard errors to a few more involved docs replaces
Browse files Browse the repository at this point in the history
  • Loading branch information
guineveresaenger committed Jan 24, 2025
1 parent c18a425 commit 7f2d523
Showing 1 changed file with 62 additions and 35 deletions.
97 changes: 62 additions & 35 deletions provider/doc_edits.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ import (
func editRules(defaults []tfbridge.DocsEdit) []tfbridge.DocsEdit {
return append(defaults,
fixUpCloudFrontPublicKey,
fixUpEcsServiceNameTrigger,
fixUpEcsServiceNameForceNewDeployment,
fixUpEcsServiceName,
fixUpBucketReplicationConfig,
// This fixes up strings such as:
//
Expand All @@ -54,23 +53,23 @@ func editRules(defaults []tfbridge.DocsEdit) []tfbridge.DocsEdit {

applyReplacementsDotJSON(),

targetedSimpleReplace("iam_role_policies_exclusive.html.markdown", "Terraform", "Pulumi"),
targetedReplace("iam_role_policies_exclusive.html.markdown", "Terraform", "Pulumi"),
addResourceNote("iam_role_policies_exclusive.html.markdown",
"To reliably detect drift between customer managed inline policies listed in this resource and"+
" actual policies attached to the role in the cloud, you currently need to run Pulumi"+
" with `pulumi up --refresh`."+
" See [#4766](https://github.com/pulumi/pulumi-aws/issues/4766) for tracking making"+
" this work with regular `pulumi up` invocations."),

targetedSimpleReplace("iam_role_policy_attachments_exclusive.html.markdown", "Terraform", "Pulumi"),
targetedReplace("iam_role_policy_attachments_exclusive.html.markdown", "Terraform", "Pulumi"),
addResourceNote("iam_role_policy_attachments_exclusive.html.markdown",
"To reliably detect drift between customer managed policies listed in this resource and actual"+
" policies attached to the role in the cloud, you currently need to run Pulumi with"+
" `pulumi up --refresh`."+
" See [#4766](https://github.com/pulumi/pulumi-aws/issues/4766)"+
" for tracking making this work with regular `pulumi up`"),

targetedSimpleReplace("iam_policy_attachment.html.markdown", "Terraform", "Pulumi"),
targetedReplace("iam_policy_attachment.html.markdown", "Terraform", "Pulumi"),
)
}

Expand Down Expand Up @@ -99,21 +98,11 @@ func simpleReplace(from, to string) tfbridge.DocsEdit {
}
}

func targetedSimpleReplace(filePath, from, to string) tfbridge.DocsEdit {
fromB, toB := []byte(from), []byte(to)
return tfbridge.DocsEdit{
Path: filePath,
Edit: func(_ string, content []byte) ([]byte, error) {
return bytes.ReplaceAll(content, fromB, toB), nil
},
}
}

func targetedReplace(filePath, from, to string) tfbridge.DocsEdit {
fromBytes, toBytes := []byte(from), []byte(to)
return tfbridge.DocsEdit{
Path: filePath,
Edit: func(_ string, content []byte) ([]byte, error) {
Edit: func(path string, content []byte) ([]byte, error) {
if bytes.Contains(content, fromBytes) {
content = bytes.ReplaceAll(
content,
Expand All @@ -129,32 +118,70 @@ func targetedReplace(filePath, from, to string) tfbridge.DocsEdit {
}
}

var fixUpCloudFrontPublicKey = targetedSimpleReplace("cloudfront_public_key.html.markdown",
var fixUpCloudFrontPublicKey = targetedReplace("cloudfront_public_key.html.markdown",
"* `name` - (Optional) The name for the public key. By default generated by this provider.",
"* `name` - (Optional) The name for the public key. By default generated by this provider. "+
"Note: Do not set if using the key's id in another resource (e.g. KeyGroup) "+
"since it will result in a dependency error from AWS. "+
"Instead, it is recommended to use Pulumi autonaming by leaving this property unset (default behavior) "+
"or set the `namePrefix` property to allow the provider to autoname the resource.\n")

var fixUpEcsServiceNameTrigger = targetedSimpleReplace("ecs_service.html.markdown",
"* `triggers` - (Optional) Map of arbitrary keys and values that, when changed, will trigger "+
"an in-place update (redeployment). Useful with `plantimestamp()`. See example above.\n",
"* `triggers` - (Optional) Map of arbitrary keys and values that, when changed, will trigger "+
"an in-place update (redeployment). Useful with `plantimestamp()`. "+
"When using the triggers property you also need to set the forceNewDeployment property to True.\n")

var fixUpEcsServiceNameForceNewDeployment = targetedSimpleReplace(
"ecs_service.html.markdown",
"* `force_new_deployment` - (Optional) Enable to force a new task deployment of the service. "+
"This can be used to update tasks to use a newer Docker image with same image/tag combination "+
"(e.g., `myimage:latest`), roll Fargate tasks onto a newer platform version, or immediately deploy "+
"`ordered_placement_strategy` and `placement_constraints` updates.",
"* `force_new_deployment` - (Optional) Enable to force a new task deployment of the service. "+
"This can be used to update tasks to use a newer Docker image with same image/tag combination "+
"(e.g., `myimage:latest`), roll Fargate tasks onto a newer platform version, or immediately deploy "+
"`ordered_placement_strategy` and `placement_constraints` updates.\n"+
"When using the forceNewDeployment property you also need to configure the triggers property.\n")
var fixUpEcsServiceName = tfbridge.DocsEdit{
Path: "ecs_service.html.markdown",
Edit: func(path string, content []byte) ([]byte, error) {
// The bridge cannot differentiate between resource and data source doc files.
// This check makes sure we're not checking the data source file.
if bytes.Contains(content, []byte("The ECS Service data source")) {
return content, nil
}
type replace struct {
from []byte
to []byte
}
replaces := []replace{
{
from: []byte(
"* `force_new_deployment` - (Optional) Enable to force a new task deployment of the service. " +
"This can be used to update tasks to use a newer Docker image with same image/tag combination " +
"(e.g., `myimage:latest`), roll Fargate tasks onto a newer platform version, or immediately deploy " +
"`ordered_placement_strategy` and `placement_constraints` updates.",
),
to: []byte("* `force_new_deployment` - (Optional) Enable to force a new task deployment of the service. " +
"This can be used to update tasks to use a newer Docker image with same image/tag combination " +
"(e.g., `myimage:latest`), roll Fargate tasks onto a newer platform version, or immediately deploy " +
"`ordered_placement_strategy` and `placement_constraints` updates.\n" +
"When using the forceNewDeployment property you also need to configure the triggers property.\n",
),
},
{
from: []byte(
"* `triggers` - (Optional) Map of arbitrary keys and values that, when changed, will trigger " +
"an in-place update (redeployment). Useful with `plantimestamp()`. See example above.\n",
),
to: []byte(
"* `triggers` - (Optional) Map of arbitrary keys and values that, when changed, will trigger " +
"an in-place update (redeployment). Useful with `plantimestamp()`. " +
"When using the triggers property you also need to set the forceNewDeployment property to True.\n",
),
},
}
for _, text := range replaces {
if bytes.Contains(content, text.from) {
content = bytes.ReplaceAll(
content,
text.from,
text.to)
} else {
// Hard error to ensure we keep this content up to date
return nil, fmt.Errorf("could not find text in upstream %s, "+
"please verify replace content in doc_edits.go: %s", path, string(text.from),
)
}
}
return content, nil
},
}

var fixUpBucketReplicationConfig = tfbridge.DocsEdit{
Path: "s3_bucket_replication_configuration.html.markdown",
Edit: func(path string, content []byte) ([]byte, error) {
Expand Down

0 comments on commit 7f2d523

Please sign in to comment.