Currently the Terraform meta arguments, e.g. depends_on, are generated per resource.
Moving these to the terra pkg would make it easier to modify these in the future as it would not require the generated code to be updated.
For example, below is generated code for a resource:
// Resource represents the Terraform resource aws_eks_access_policy_association.
type Resource struct {
Name string
Args Args
state *awsEksAccessPolicyAssociationState
DependsOn terra.Dependencies
Lifecycle *terra.Lifecycle
}
This could become:
// Resource represents the Terraform resource aws_eks_access_policy_association.
type Resource struct {
Name string
Args Args
state *awsEksAccessPolicyAssociationState
// Embed MetaArgs (depends_on, etc.)
terra.MetaArgs
}
Then in the terra pkg we would have something like:
type MetaArgs struct {
DependsOn Dependencies
Lifecycle *Lifecycle
}
// Dependencies returns the list of dependencies for this block.
func (r *MetaArgs) Dependencies() Dependencies {
return r.DependsOn
}
// LifecycleManagement returns the lifecycle block for this block.
func (r *MetaArgs) LifecycleManagement() *Lifecycle {
return r.Lifecycle
}
Then the Dependencies() and LifecycleManagement() functions from the generated code could also be removed.
Note that data sources support nearly all the same meta arguments as resources, and so we could re-use the terra.MetaArgs and embed those in data sources. If a user would use some meta args not supported by data sources this would be reported by terraform, so there is little room for error.
Currently the Terraform meta arguments, e.g. depends_on, are generated per resource.
Moving these to the
terrapkg would make it easier to modify these in the future as it would not require the generated code to be updated.For example, below is generated code for a resource:
This could become:
Then in the
terrapkg we would have something like:Then the
Dependencies()andLifecycleManagement()functions from the generated code could also be removed.Note that data sources support nearly all the same meta arguments as resources, and so we could re-use the
terra.MetaArgsand embed those in data sources. If a user would use some meta args not supported by data sources this would be reported by terraform, so there is little room for error.