ansible-collections / ansible-collections/google.cloud

Ability to attach service project to host project in shared vpc setup

Open
#336 1 comment 0 reactions 0 assignees View on GitHub
stale
Dominant language
Python
Stars
105
Forks
144
Avg merge
5d 10h
Merged PRs (30d)
4

Description

##### SUMMARY
After general GCP project creation step. Would be helpful if we include below features to be included in ansible modules
1) Enable a project as a host project
2) Enable a project as a service project and attach the project to already created host project

Above features are currently possible in terraform.
##### ISSUE TYPE
- Feature Idea

##### COMPONENT NAME

GCP API endpoint documentation are as follows
1) Enable host project: https://cloud.google.com/compute/docs/reference/rest/v1/projects/enableXpnHost
2) Attach service project for host project: https://cloud.google.com/compute/docs/reference/rest/v1/projects/enableXpnResource

##### ADDITIONAL INFORMATION

I tried to add below config in https://github.com/GoogleCloudPlatform/magic-modules/blob/master/products/compute/api.yaml

```yaml
- !ruby/object:Api::Resource
name: 'Project'
kind: 'compute#project'
base_url: projects/{{project}}/enableXpnResource
create_url: projects/{{project}}/enableXpnResource
has_self_link: true
description: |
Associate Service Project into Host Project
input: true
async: !ruby/object:Api::OpAsync
operation: !ruby/object:Api::OpAsync::Operation
kind: 'compute#operation'
path: 'name'
base_url: 'projects/{{project}}/operations/{{op_id}}'
wait_ms: 1000
result: !ruby/object:Api::OpAsync::Result
path: 'targetLink'
status: !ruby/object:Api::OpAsync::Status
path: 'status'
complete: 'DONE'
allowed:
- 'PENDING'
- 'RUNNING'
- 'DONE'
error: !ruby/object:Api::OpAsync::Error
path: 'error/errors'
message: 'message'
properties:
- !ruby/object:Api::Type::String
name: 'project'
description: |
URL of the host project
required: true
- !ruby/object:Api::Type::NestedObject
name: 'xpnResource'
description: |
Attaches service project to host project
properties:
- !ruby/object:Api::Type::Enum
name: 'type'
required: true
description: |
The type of the service resource.
values:
- :PROJECT
- !ruby/object:Api::Type::String
name: 'id'
required: true
description: |
The ID of the service resource.
In the case of projects, this field supports project id
(e.g., my-project-123) and project number (e.g. 12345678).
```

Was consistently getting below error.

```
I, [2020-11-17T10:42:57.559286 #41730] INFO -- : Generating Project
F, [2020-11-17T10:42:57.565199 #41730] FATAL -- : Error compiling /Users/balan/Documents/repository/magic-modules/templates/ansible/documentation.erb
Error compiling file: /Users/balan/Documents/repository/magic-modules/templates/ansible/resource.erb
bundler: failed to load command: compiler (compiler)
NameError: undefined local variable or method `example' for #
(erb):44:in `provider_binding'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/erb.rb:901:in `eval'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/erb.rb:901:in `result'
/Users/balan/Documents/repository/magic-modules/compile/core.rb:127:in `compile'
(erb):11:in `provider_binding'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/erb.rb:901:in `eval'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/erb.rb:901:in `result'
/Users/balan/Documents/repository/magic-modules/compile/core.rb:219:in `compile_string'
/Users/balan/Documents/repository/magic-modules/compile/core.rb:154:in `compile_file'
/Users/balan/Documents/repository/magic-modules/provider/file_template.rb:63:in `block in generate'
/Users/balan/Documents/repository/magic-modules/provider/file_template.rb:63:in `open'
/Users/balan/Documents/repository/magic-modules/provider/file_template.rb:63:in `generate'
/Users/balan/Documents/repository/magic-modules/provider/ansible.rb:241:in `generate_resource'
/Users/balan/Documents/repository/magic-modules/provider/core.rb:236:in `generate_object'
/Users/balan/Documents/repository/magic-modules/provider/core.rb:224:in `block in generate_objects'
/Users/balan/Documents/repository/magic-modules/provider/core.rb:207:in `each'
/Users/balan/Documents/repository/magic-modules/provider/core.rb:207:in `generate_objects'
/Users/balan/Documents/repository/magic-modules/provider/ansible.rb:320:in `generate_objects'
/Users/balan/Documents/repository/magic-modules/provider/core.rb:80:in `generate'
compiler:227:in `block in '
compiler:142:in `each'
compiler:142:in `'
```

Since I am not familiar with Ruby and magic-modules, I couldn't find effectively why the template file is not rendering. Would be great if someone could help with this or point me in right direction

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the compiler failure with the attempted Project definition in products/compute/api.yaml, then inspect templates/ansible/documentation.erb and templates/ansible/resource.erb around the reported example binding. Trace the template context through compile/core.rb; done means host-project enablement and service-project attachment can be generated without the NameError.

Written by the indexing model from the issue text.

Assessment

Tech stack
google-cloud, ruby
Domain
build-system, cloud
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.