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

Import as a Module #141

Closed
xescugc opened this issue Nov 2, 2020 · 0 comments · Fixed by #164
Closed

Import as a Module #141

xescugc opened this issue Nov 2, 2020 · 0 comments · Fixed by #164
Assignees
Labels
Feature roadmap feature

Comments

@xescugc
Copy link
Member

xescugc commented Nov 2, 2020

Abstract

Would be good to have an import directly as a Terraform Module so we are able to directly use the imported infrastructure as a module.

Proposal

As the import is directly filled there is no way in which we can define which attributes of a Resource need to be defined as variables so they can be modified when it's used as a Module.

For this we could have an specific configuration for each Provider in which we would define from each resource which attributes are the most "common" to have variables so it can be changed from the Module.

Implementation

The implementation I have in mind is to add a new flag of --module-name that will generate the HCL as a Module which means to have the HCL inside a ./module-{module-name}/hcl.tf and have also a ./{module-name}.tf.

The {module-name}.tf will source the ./module-{module-name}/ and have all the variables that are defined on the hcl.tf with the filled data that it had when importing, so it can be generated as it was imported.

The config that was mentioned that we'll have for each Provider will be something like:

{
  "aws_instance": [
    "count",
  ],
}

It'll be able to be overrided by a --module-config with the same format, in which case that one would be used instead of the default one.

Which means that any aws_instance.count will be defined as a variable (different for each aws_instance, something like var.aws_instance_{instance-name}_count

And then the module would be like:

module "{module-name}" {
  source = "./module-{module-name}"

  # If it has a value
  aws_instance_{instance-name}_count = 4
  
  # If it has no value inside of the module
  # so the module usage can have them defined
  # aws_instance_{instance-name}_count
}

Open issues (if applicable)

@xescugc xescugc added the Feature roadmap feature label Nov 2, 2020
@kerak19 kerak19 changed the title Import as a Moule Import as a Module Nov 2, 2020
@xescugc xescugc mentioned this issue Jan 28, 2021
@xescugc xescugc self-assigned this Jan 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature roadmap feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant