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

[terraform-conversions] Add compute_instance to conversions library #1496

Merged

Conversation

nstogner
Copy link
Contributor

Add non-generated compute_instance to CAI conversions. Code was pulled from terraform provider third_party/ and modified slightly.

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@modular-magician
Copy link
Collaborator

Hello! I am a robot who works on Magic Modules PRs.

I have detected that you are a community contributor, so your PR will be assigned to someone with a commit-bit on this repo for initial review. They will authorize it to run through our CI pipeline, which will generate downstream PRs.

Thanks for your contribution! A human will be with you soon.

Copy link
Contributor

@chrisst chrisst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR as is will break terraform which you'll need to fix.

As a larger pattern though you are copying whole files from third_party/terraform and moving them into third_party/validator. Some of them are copied across without modification and others are just changing the method signature. Copying files like this incurs a ton of technical debt because any modification upstream will not propagate to your tool. It also appears that you will not be using many of the methods and just adding copy/pasted dead code into your downstream codebase.

Any files that are copied wholesale should just be sourced from the original location instead of copied by hand into third_party/validator.

For the method signature changes, it would be preferable if you can use those expanders as is. Are you able to build a shim to convert between the Terraform object and your TerraformResourceData object?

products/compute/terraform.yaml Outdated Show resolved Hide resolved
third_party/validator/common_operation.go Outdated Show resolved Hide resolved
computeBeta "google.golang.org/api/compute/v0.beta"
)

func expandAliasIpRanges(ranges []interface{}) []*computeBeta.AliasIpRange {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it's a copy of the original compute_instance_helpers with the flatten helpers stripped out and a couple lines of validation removed. IMO the validation logic isn't really needed in Terraform either and I think the long term burden of this tool will get more complex with every file that you have to fork. So I propose 2 improvements:

  1. If you are importing this just to remove the validation logic but would otherwise be able to use the file as is I'll submit a PR upstream and remove that logic (once I've made sure the api is also validating this in a sane way)

  2. If fix philosphy typo #1 doesn't work can you document in a top of file comment what is going on in this file? Something as simple as what the delta is and why. This will save a lot of time in the future when these methods need to be updated upstream.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am now just using the file from third_party/terraform. Do you want to remove the validation check in this PR or in another?

third_party/validator/compute_operation.go Outdated Show resolved Hide resolved
@nstogner
Copy link
Contributor Author

Unfortunately we are unable to use *schema.ResourceData struct instead of the TerraformResourceData interface in these conversions b/c there is no way to populate its unexported fields. An alternative would be to use the interface when possible in the provider. For the files that don't use *schema.ResourceData I will go ahead to source them from the third_party/terraform/ directory rather than copying.

@nstogner
Copy link
Contributor Author

Removed copying of files from third_party/terraform/ to third_party/validator/ except for the manual copy/patch of compute_instance.go itself.

Copy link
Contributor

@chrisst chrisst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼

}

// Create the instance information
return &computeBeta.Instance{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use the computeBeta library for legacy reasons. If you find that this becomes a problem you can probably move to the GA version.

@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician, I work on Magic Modules.
This PR seems not to have generated downstream PRs before, as of 681c381.

Pull request statuses

No diff detected in Ansible.
No diff detected in Inspec.

New Pull Requests

I built this PR into one or more new PRs on other repositories, and when those are closed, this PR will also be merged and closed.
depends: hashicorp/terraform-provider-google-beta#517
depends: GoogleCloudPlatform/terraform-google-conversion#11
depends: hashicorp/terraform-provider-google#3226

@nstogner
Copy link
Contributor Author

Signed CLA

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@modular-magician modular-magician merged commit 170043d into GoogleCloudPlatform:master Mar 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants