Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider moving resource meta arguments from generated code to terra pkg #14

Open
jlarfors opened this issue Apr 17, 2024 · 0 comments
Open

Comments

@jlarfors
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant