1.5 KiB
1.5 KiB
Middlewares
The main goal of middlewares is to reconciliate IaC and remote resources. For this we filter default resources, mutate, or remove fields in resources or even create and delete new resources.
type AwsDefaultRoute struct{}
func NewAwsDefaultRoute() AwsDefaultRoute {
return AwsDefaultRoute{}
}
func (m AwsDefaultRoute) Execute(remoteResources, resourcesFromState *[]*resource.Resource) error {
newRemoteResources := make([]*resource.Resource, 0)
// ...
*remoteResources = newRemoteResources
return nil
}
In the above example, we define a middleware called AwsDefaultRoute
that will modify remote resources. Middleware can access two arrays of type *[]*resource.Resource
: IaC resources first and then remote resources. The goal is to rework these slices to remove false positive drifts. Notice both remoteResources
and resourcesFromState
variables are pointers, which mean middlewares can perform mutations on resources before the comparison is made.
Different kind of middlewares
- Help driftctl match IaC resources and remote resources.
- Filter noises from provider default resources
- Resource transformation
- Specific edge cases
Examples
aws_route_table_expander
explode inline route in dedicated resourcesaws_default_route
ignore route created by default when creating a table if they are not managed in IaCaws_iam_user_policy_attachment
andaws_iam_role_policy_attachment
transformed toaws_iam_policy_attachment
route53_records_id_reconcilier
that rework ID's to match Terraform ones