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

google: add compute instance #56

Merged
merged 1 commit into from
Nov 8, 2019
Merged

google: add compute instance #56

merged 1 commit into from
Nov 8, 2019

Conversation

tormath1
Copy link
Contributor

@tormath1 tormath1 commented Oct 23, 2019

This PR is based on the Google boilerplate. I import Google Compute Instances using this api.

TC been tested against 2 instances: in different zones and different labels.

What I've done:

  • isolate requiredStringFlags function into root.go since we are using the same function in both command lines
  • fetch zone list since the API need both project and zone to list instances. We fetch zones from the given region
  • implement a simple reader in waiting for RAWS removal
  • hack the ID between read and import

I'll squash commits before merging.

@tormath1 tormath1 force-pushed the google-compute-instance branch 2 times, most recently from 37cdfdd to d022b70 Compare October 24, 2019 08:01
Copy link
Member

@xescugc xescugc left a comment

Choose a reason for hiding this comment

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

Ok a few comments on the code, but the commits need to be cleaner (you are changing and changing code from the same PR in commits).

We want to try the syntax as close as possible to TF+Provider as possible, this goes for the Tags and Labels, IIRC Google uses Label instead of tags, so we should expose the name label instead of tags but internally use the Tag abstraction.

Also about zones IDK if it's the regions we have on AWS

I think this is all though :)

google/reader.go Outdated
compute *compute.Service
project string
region string
//TODO: add filters
Copy link
Member

Choose a reason for hiding this comment

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

If there is a TODO add an issue for it and add the link to the TODO.

google/reader.go Outdated
if err != nil {
return nil, err
}
// zones are URL format. Need to split them
Copy link
Member

Choose a reason for hiding this comment

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

Can you put an example? I see for the code what it is (it's the last element of the URL that we want) but just to have itmore clear.

google/reader.go Outdated
return nil, err
}
// zones are URL format. Need to split them
zones := make([]string, 0)
Copy link
Member

Choose a reason for hiding this comment

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

zones := make([]stirng,0, len(region.Zones)) so you already allocate the needed space.

google/reader.go Outdated
// ListInstances return a list of instances in the project/region
func (r *GCPReader) ListInstances() (map[string][]compute.Instance, error) {
is := compute.NewInstancesService(r.compute)
//TODO: add filters
Copy link
Member

Choose a reason for hiding this comment

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

Same, add issue if this is relevant and link it.

google/reader.go Outdated
}
for _, zone := range zones {
instances := make([]compute.Instance, 0)
il, err := is.List(r.project, zone).Do()
Copy link
Member

Choose a reason for hiding this comment

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

Dest this return all of them? or it's paginated?

instances := make([]compute.Instance, 0)
il, err := is.List(r.project, zone).
// 500 is the current `maxResults`
instances := make([]compute.Instance, 0, 500)
Copy link
Member

Choose a reason for hiding this comment

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

And if you have more than 500? It's not possible to request them all?

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 use pages. Each page has a default size of 500 elements: see pagination and max result

instances slice will store only the instances returned by the current page (so 500 maximum). Then we append this slice to the final instancesList map.

@tormath1
Copy link
Contributor Author

tormath1 commented Nov 6, 2019

ready for a next review :)

Copy link
Member

@xescugc xescugc left a comment

Choose a reason for hiding this comment

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

LGTM Rebase and Squash

@tormath1 tormath1 force-pushed the google-compute-instance branch from 755e5c6 to 02fbd01 Compare November 6, 2019 10:21
@tormath1
Copy link
Contributor Author

tormath1 commented Nov 6, 2019

rebased and squashed ✔️

@tormath1 tormath1 merged commit 604e641 into master Nov 8, 2019
@tormath1 tormath1 deleted the google-compute-instance branch November 8, 2019 11:00
tormath1 added a commit that referenced this pull request Nov 8, 2019
- instance (from PR #56)
- network
- firewall
tormath1 added a commit that referenced this pull request Nov 8, 2019
* google: pass config as a pointer

* google: implement firewall ressource

* readme: fix gcp plugin version

* google: implement compute network resource

* changelog: add google compute resources

- instance (from PR #56)
- network
- firewall
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

Successfully merging this pull request may close these issues.

3 participants