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

Integrate Azure into GCP's magic-modules #14

Open
wants to merge 203 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
203 commits
Select commit Hold shift + click to select a range
8699a93
Adapt to Azure package structure and CRUD skeleton
Nov 15, 2018
3e2a586
Add ansible configuration
Nov 15, 2018
5cd90a9
Include the whole prefix as generated TF file name
Nov 15, 2018
40dd062
Add test file and documentation file to Terraform
Nov 20, 2018
b989a28
Implement D operations, update CRU operations
Nov 20, 2018
4cf845f
Add location and tags to resource group
Nov 21, 2018
5c99164
Add some Azure rest spec support
Nov 21, 2018
52466d3
Update Ansible script according to the latest configuration
Nov 21, 2018
355b587
Finish resource group CRUD
Nov 27, 2018
9510744
Adjust documentation to match Azure format
Nov 27, 2018
429a6b6
Refactoring schema properties
Dec 6, 2018
e39a97c
Refactor: resource group name and tags type
Dec 7, 2018
7fa7e35
Introduce azure_update_verb.
Jan 23, 2019
0f47162
Add line back to rg_test.go.
Jan 23, 2019
e1726e9
Add ContainerRegistry API definition.
Jan 24, 2019
1925902
Handle more primitive schema definitions.
Jan 24, 2019
a1744c8
Get name from Azure ID portion.
Jan 24, 2019
ace000b
Introduce Go & Python SDK type definitions.
Jan 25, 2019
c851a8e
Implement request hierarchical object copy.
Jan 26, 2019
4cf8434
Set SDK object back to schema properties.
Jan 29, 2019
5e7c5ed
Add update function template.
Jan 29, 2019
ba5611a
Fix some go code style issues.
Jan 29, 2019
a0e8838
Generate documentation of Azure container registry.
Jan 29, 2019
4aaaa8d
Move CRUD verbs into SDK Definition.
Feb 15, 2019
c267fb1
Refine request parameter invocation logic.
Feb 18, 2019
cc48b36
Refine terraform schema sort logic.
Feb 18, 2019
106c881
Introduce Azure Automation Variable resource.
Feb 19, 2019
163d215
Implement AccTestCheckExist/Destroy.
Feb 20, 2019
36989ee
Implement AccTest for Terraform resources.
Feb 22, 2019
edda1f6
Rename azure_api_path to azure_sdk_references.
Feb 25, 2019
571ca7c
Refactor schema-to-SDK logic.
Feb 26, 2019
1580eba
Implement full version of automation string variable.
Feb 26, 2019
4614c7b
Refine automation variable implementation.
Feb 27, 2019
28fcf37
Introduce Service Bus Disaster Recovery resource.
Feb 27, 2019
7f9193c
Add customizable properties order.
Mar 4, 2019
cd914a5
Add StringMap SDK Type.
Mar 4, 2019
ca6b5f5
Generate Ansible documentation part.
Mar 8, 2019
2cb57f2
Introduce the new examples strategy.
Mar 11, 2019
cc485b5
Complete Terraform documentation generation.
Mar 13, 2019
3fe6169
Use Binding instead of Hash for example
Mar 15, 2019
86a5856
Use examples in AccTest templates.
Mar 21, 2019
661ea3f
Refactor and introduce API Management Policy.
Mar 28, 2019
f4457b0
Refine API Management Policy resource.
Mar 29, 2019
1d632ec
Add acceptance tests for API Management Policy.
Mar 29, 2019
e27e9c0
Fix ERB trim warnings.
Mar 29, 2019
4e095e7
Implement CRUD operations for Ansible.
Mar 30, 2019
676aadd
Azure SDK definition overrides kick-off
Apr 3, 2019
18b4eb2
Introduce batch account api.yaml.
Apr 4, 2019
a68e53b
Complete module argument spec and initialization.
Apr 6, 2019
4efd180
Generate the rest of Ansible module code.
Apr 9, 2019
6393ca1
Include examples in BatchAccount (Ansible).
Apr 9, 2019
b21b9f7
Generate Terraform BatchAccount resource.
Apr 10, 2019
5378f9b
Change author of BatchAccount (Ansible).
Apr 10, 2019
91fb7d8
Refactor prop2sdk to better support custom expand.
Apr 10, 2019
3ec2575
Add expand NestedObject feature to Terraform.
Apr 10, 2019
264bf95
Support nested object flatten in Terraform.
Apr 11, 2019
7cf0d81
Fix Ansible linting issues.
Apr 11, 2019
0d460d9
Refine Terraform documentation.
Apr 12, 2019
92f33ab
Apply the latest api.yaml schema to all api.yaml files.
Apr 12, 2019
ee9b3f3
Add output field to BatchAccount.
Apr 12, 2019
570b2cc
Add ID output property.
Apr 13, 2019
9d18f3e
Add ID output to all api.yaml for Azure.
Apr 13, 2019
fbe5326
Add idempotency and resource ref to Ansible.
Apr 13, 2019
31aa9dd
Fix Ansible runtime errors.
Apr 18, 2019
1e3bc73
Add Azure SDK definition overrides.
Apr 19, 2019
e992e2b
Complete documentation part of Ansible info module.
Apr 20, 2019
1f38885
Unify Terraform example with Ansible example.
Apr 20, 2019
a438abb
Implement info module in Ansible.
Apr 23, 2019
779f1eb
Removed unused code for automation string variable
WodansSon Apr 24, 2019
7e6ac82
Fixes for automation string resource
WodansSon Apr 25, 2019
bb1a069
Update set value code
WodansSon Apr 25, 2019
6ca9ce3
Set request-only properties back to TF schema
Apr 25, 2019
fc986fd
Merge branch 'azure_backend' of https://github.com/VSChina/magic-modu…
Apr 25, 2019
8d499f4
Include the latest changes in tf_string_variable
Apr 25, 2019
ca42446
Add Null Variable
WodansSon Apr 26, 2019
3c68822
Added more variable resources
WodansSon Apr 26, 2019
35b5c47
Added int support
WodansSon Apr 26, 2019
a47dbe5
Refactor SDK marshal/unmarshal parameters.
Apr 26, 2019
d9e29e0
Merge branch 'azure_backend' of https://github.com/VSChina/magic-modu…
Apr 26, 2019
37ffba7
Supports initial version of Terraform data source.
Apr 30, 2019
152a82a
Use AzureRMModuleBaseExt in ansible.
Apr 30, 2019
cc1c1cd
Add SDK Marshalling to Ansible.
May 1, 2019
659ea12
Introduce azure front door resource
May 2, 2019
f9df986
Updates per PR
WodansSon May 2, 2019
6884d3c
Merge branch 'azure_backend' of https://github.com/VSChina/magic-modu…
WodansSon May 2, 2019
e8bb61e
Implement StringArray and Int32 data types
May 4, 2019
cade4ec
Introduce Frontdoor Backend Pool resource.
May 7, 2019
d375c12
Support complex array in HCL.
May 8, 2019
ad81dc1
Introduce front door frontend endpoint resource.
May 8, 2019
0ca1cfa
Update to fix datasource generation
WodansSon May 8, 2019
0564808
Datasource Automation Variable
WodansSon May 9, 2019
7fde1ac
Fix ForceNew and testname issues in TF data source
May 14, 2019
e3a3429
Refine documentation for batch account (Ansible)
May 21, 2019
6677bc1
Merge branch 'azure_backend' of https://github.com/VSChina/magic-modu…
May 21, 2019
7d9d0bd
Add integration test for batch account.
May 29, 2019
ae2aef3
Fix line is too long error in example YAML for Ansible
Jun 1, 2019
ab0f8f2
Use the customized yaml template to generate EXAMPLES for Ansible
Jun 3, 2019
6e57118
Calculate keyvault URL from keyvault ID for Ansible batch account
Jun 3, 2019
ccf00ab
Move batch account to mm-spec repo.
Jun 4, 2019
7751190
Regenerate batch account for Terraform.
Jun 4, 2019
988395e
Add delete step to Ansible inttest.
Jun 6, 2019
06577a9
Remove type restriction on sample_value.
Jun 13, 2019
143f509
Fix test and order bugs in Ansible and Terraform
Jun 13, 2019
1aae5fd
Support inline response format customization for Ansible
Jun 13, 2019
7ed7ecc
Rename `list_by_rg` to `list_by_resource_group`.
Jun 13, 2019
87d6e3c
Fix import error in Ansible info module.
Jun 14, 2019
f3d188f
Add developer guidelines for Azure.
Jun 14, 2019
3cd091c
Fix several Ansible info module styles.
Jun 18, 2019
2e6bd6a
Add Ansible info module tests
Jun 18, 2019
1ce4cb2
add magic-module-specs ad submodule. (#8)
metacpp Jun 18, 2019
958b577
Fix indentation.
Jun 18, 2019
cf08648
Merge with the latest MM (might not working)
Jun 20, 2019
6e3808c
Merge terraform generator to the latest MM
Jun 24, 2019
6b3eaee
Merge Ansible templates to the latest MM
Jun 25, 2019
e58115a
Remove unused Azure generated code.
Jun 25, 2019
369d74f
Add new DateTime and Duration types
Jun 26, 2019
62c7ebb
Adjust resource group schema to match the latest Terraform code style
Jun 27, 2019
5ce7618
Temparary disable go format and python format.
Jun 27, 2019
4cf6703
Add complete support for Ansible SDK marshal.
Jun 28, 2019
070a362
Remove DEBUG messages.
Jun 28, 2019
f56490a
ignore .bundle folder.
metacpp Jun 29, 2019
4676884
Fix the code template issue for Terraform. (#12)
metacpp Jun 30, 2019
332b3ef
Fix the template for location.
metacpp Jul 2, 2019
b956f91
Remove azure resource definitions.
Jul 9, 2019
9dbe6b2
Add support for storage account test names.
Jul 10, 2019
0d8b47d
Add get_batch_account_name
Jul 10, 2019
53b4d05
Fix complex array type and enum flatten issues.
Jul 11, 2019
cff643d
Command Line Option for GCP/Azure Switch (#9)
houkms Jul 22, 2019
323eb80
Refine ansible info module format_response. (#15)
Aug 12, 2019
cbf48d4
Fix issues for Terraform WebApplicationFirewallPolicy resource (#13)
houkms Aug 13, 2019
ad3f8fe
Refine terraform HCL empty line positions
Aug 13, 2019
eb86416
Introduce BooleanEnum type to properties
Aug 14, 2019
096c5ac
Missing comma for BooleanEnum Default value
Aug 14, 2019
c2fa1ab
Support Datetime & Duration & IntegerArray & ReferenceArray Types for…
houkms Sep 5, 2019
a7da040
Update tags and Create template according to the latest coding style
Sep 5, 2019
8986b4e
missing go_type_name override in adk_type_definition
houkms Sep 12, 2019
ca6e07f
adjust MaxItems and MinItems of TypeList in datasource
houkms Sep 16, 2019
36c9681
fix nested map expanding issue in TestCheckResourceAttr
houkms Sep 16, 2019
286fad1
Merge pull request #18 from houkms/fix-datasource
mybayern1974 Sep 16, 2019
998484a
Merge pull request #30 from houkms/fix-attribs-checking
mybayern1974 Sep 16, 2019
2857c31
fix some known issues
houkms Sep 17, 2019
8b590dd
Merge pull request #35 from houkms/fix-p0-issues
mybayern1974 Sep 17, 2019
d3c1bd2
fix the int32 pointer issue
houkms Sep 18, 2019
2927bef
fix the nested input and output property issue
houkms Sep 18, 2019
cfb567d
enable property checking customization in test file
houkms Sep 24, 2019
afad932
fix the expand/flatten function redeclaration issue
houkms Sep 24, 2019
3618bfd
enable enum array for azure_sdk_type_definition
houkms Sep 26, 2019
0019f9c
Merge pull request #38 from houkms/fix-p0
mybayern1974 Sep 26, 2019
fcf8321
Merge pull request #42 from houkms/support_for_enum_array
mybayern1974 Sep 26, 2019
40fb6c6
Merge pull request #41 from houkms/redeclaration
mybayern1974 Sep 26, 2019
56846ea
Merge pull request #40 from houkms/enhancement
mybayern1974 Sep 26, 2019
54885c8
Merge pull request #17 from houkms/fix-issues
mybayern1974 Sep 26, 2019
ef6eb32
adjust tags's position in schema (#55)
houkms Oct 15, 2019
ea4c95b
support new code style for tags in schema (#52)
houkms Oct 15, 2019
d6c773b
using t instead of tags in sub-properties (#49)
houkms Oct 15, 2019
e2cd280
support new code style for Tags (#48)
houkms Oct 15, 2019
18d511c
support float array type property
houkms Oct 15, 2019
de38a49
code style adjustment when handling resource import
houkms Oct 17, 2019
d8afc4b
fix issue in enum_array as output
houkms Oct 17, 2019
9a45dd3
SDKTypeDefinitionOverride support sublcass with concrete type definition
magodo Nov 8, 2019
51c45db
Update api/azure/sdk_type_definition.rb
magodo Nov 8, 2019
7ada62a
Update api/azure/sdk_type_definition.rb
magodo Nov 9, 2019
a15ccfb
Add prop option to compact e/f func name
magodo Nov 10, 2019
872973e
also modify func name on caller side
magodo Nov 12, 2019
206d333
cover more missing parts
magodo Nov 13, 2019
3839e85
Provide custom ef name instead of compacting
magodo Nov 13, 2019
ce4ff58
Fix bug after opting specific override typing
magodo Nov 15, 2019
f0d72d4
Specify erb filename so as to debug template
magodo Nov 18, 2019
3bca7b6
Enable yaml alias in YAML.safe_load
magodo Nov 18, 2019
31f0d2d
Filter out `location` from updatable_properties
magodo Nov 20, 2019
ed19aa7
Use timeouts.ForXXX to create context
magodo Dec 3, 2019
6552179
Merge pull request #85 from magodo/timeout_context
magodo Dec 3, 2019
e447013
add subcategory header to document template
magodo Dec 3, 2019
b6a2c40
Merge pull request #86 from magodo/doc_header_add_subcategory
magodo Dec 3, 2019
9d3f4ac
Search example consider foder struct by autorest.cli
magodo Dec 4, 2019
c7a4598
Merge pull request #87 from magodo/search_example_consider_folder_str…
magodo Dec 4, 2019
f51a6eb
don't set Default for output-only property
magodo Dec 17, 2019
4c3cdf3
Merge pull request #89 from magodo/azure_backend
magodo Dec 17, 2019
e3c8ba7
when searching folder form example, considering suffix of "-preview"
magodo Dec 17, 2019
b4ec684
Merge pull request #90 from magodo/azure_backend
magodo Dec 17, 2019
0c49dca
disable the comment at header
magodo Dec 18, 2019
8b6c6d3
Merge pull request #91 from magodo/azure_backend
magodo Dec 18, 2019
efdfb45
follow new client get scheme
magodo Dec 23, 2019
7824d7c
narrow down settable properties to those appears in sdk type definition
magodo Dec 23, 2019
1053f82
follow hashicorp test refactor
magodo Dec 23, 2019
83e1640
Merge pull request #92 from magodo/azure_backend
magodo Dec 23, 2019
4fc4b82
follow new client get scheme for datasource
magodo Dec 23, 2019
f1deb2a
Merge pull request #93 from magodo/azure_backend
magodo Dec 23, 2019
f79080b
put generated files to internal/services/<rp> folder
magodo Dec 24, 2019
044082b
Merge pull request #94 from magodo/azure_backend
magodo Dec 24, 2019
d2691fe
testcase impl. change (conform to hashicorp refactor)
magodo Dec 24, 2019
6afa17f
chagne package name according to new file layout
magodo Dec 26, 2019
693b84e
Merge pull request #95 from magodo/azure_backend
magodo Dec 27, 2019
3360e5a
add default timeout for d/r
magodo Dec 29, 2019
609c5a9
Merge pull request #96 from magodo/azure_backend
magodo Dec 29, 2019
cfb9b01
resource group name case sensitive
magodo Dec 31, 2019
8f94751
Merge pull request #97 from magodo/azure_backend
magodo Dec 31, 2019
5a863f0
remove `sidebar_current` from gen doc
magodo Jan 9, 2020
09e0ebc
Merge pull request #98 from magodo/azure_backend
magodo Jan 9, 2020
5f976c2
Support custom parseID function
magodo Jan 21, 2020
093951a
Merge pull request #99 from magodo/azure_backend
magodo Jan 21, 2020
c0f27b4
typo
magodo Jan 21, 2020
5788319
Merge pull request #100 from magodo/azure_backend
magodo Jan 21, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
ehthumbs.db
Thumbs.db

final_api.yaml
# Ansible PR Script
tools/ansible-pr/templates/*
!tools/ansible-pr/templates/.keep
.vscode/

.bundle/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@
path = build/terraform-mapper
url = https://github.com/GoogleCloudPlatform/terraform-google-conversion.git
branch = master
[submodule "azure/magic-module-specs"]
path = azure/magic-module-specs
url = [email protected]:Azure/magic-module-specs.git
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
language: ruby # ruby version defined in .ruby-version will be used

before_install:
- gem update --system
- gem install bundler

script:
- bundle exec rake test
- bundle exec rake erblint

git:
submodules: false
111 changes: 111 additions & 0 deletions AZURE_DEVELOPER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Developer Guide for Azure Resources

We extended magic-modules to support Azure SDKs and resources. Our design principle is to share as much code as we can, but if not, we will put Azure specific code and templates in `azure` folder, and under `Azure` namespace. For example, default data type definitions are under `Api::Type` namespace in `api/type.rb` file, while Azure specific type definitions are under `Api::Azure::Type` namespace in `api/azure/type.rb`.

For the original magic-modules development documentation, please refer to [DEVELOPER.md](DEVELOPER.md). Before reading the documentation, please make sure you know the basic concepts and coding technologies of Ruby and Ruby template (erb).

## Folder Structure

We reused most of the folder structure defined by the Google's magic-modules, but extended some Azure specific folders. Here is the big-picture of some important folders:

```
magic-modules
|- api
| |- azure
| | |- *.rb [all Azure specific types could be used in api.yaml]
| |- *.rb [all types could be used in api.yaml]
|- google
| |- *.rb [all utility functions by Google]
|- provider
| |- ansible [Ansible specific type and helper function definitions]
| |- terraform [Terraform specific type and helper function definitions]
| |- azure
| | |- ansible [Azure-ansible specific type and helper function definitions]
| | |- terraform [Azure-terraform specific type and helper function definitions]
| | |- example [Shared example related type definitions]
| | |- ansible.rb [Root object to include all sub-modules in ansible folder]
| | |- terraform.rb [Root object to include all sub-modules in terraform folder]
| | |- core.rb [Helper functions to parse example types]
| |- core.rb, abstract_core.rb, terraform.rb, ansible.rb, config.rb [See below]
| |- *.rb [all types for <product>.yaml and helper functions for templates]
|- templates
| |- ansible
| | |- facts.erb [Ansible info module template]
| | |- resource.erb [Ansible module template]
| | |- integration_test.erb [Ansible test template]
| |- terraform
| | |- datasource.erb [Terraform data source template]
| | |- resource.erb [Terraform resource template]
| | |- resource.html.markdown.erb [Terraform resource documentation template]
| | |- datasource.html.markdown.erb [Terraform data source documentation template]
| | |- schemas
| | | |- *.erb [Terraform schema sub-templates, including definition, d.Get, d.Set, etc.]
| | |- *.erb [Terraform sub-template, e.g. expand, flatten, etc.]
| |- azure
| | |- ansible
| | | |- example [Ansible test yaml and documentation yaml templates]
| | | |- module [Sub-tempaltes to generate Ansible modules or info modules]
| | | |- sdk [Sub-templates to generate Python SDK related code like method call]
| | | |- sdktypes [Sub-templates to generate schema<->SDK marshalling code]
| | | |- test [Ansible test helper templates]
| | |- terraform
| | | |- acctest [Helper sub-templates to generate Terraform tests]
| | | |- example [Terraform test HCL and documentation HCL templates]
| | | |- schemas [Azure-specific schema sub-temapltes, including definition, d.Get, d.Set, etc.]
| | | |- sdk [Sub-templates to generate Go SDK related code like method call, ID parse, fmt.Errorf]
| | | |- sdktypes [Sub-templates to generate schema<->SDK marshalling code]
| |- *.erb [sharable templates like auto-gen comment]
|- compiler.rb [entry point]
```

## Compiler

The entry point of magic module is `compiler.rb`. It will parse the command line, try to read `api.yaml`, `terraform.yaml` and `ansible.yaml` in the input directory, and load the corresponding provider. For Terraform, the provider is located in `provider/terraform.rb`; while for Ansible is `provider/ansible.rb`. When generating code for a specific product (let's say Terraform), all code templates (erb files) will only see functions defined in the corresponding provider.

Class inheritance structure is illustrated below:

```
Provider::Core (provider/core.rb)
|- Provider::AbstractCore (provider/abstract_core.rb)
| |- Provider::Terraform (provider/terraform.rb)
|- Provider::Ansible::Core (provider/ansible.rb)
```

These providers are root object, besides defining some common helper functions, they will `include` all submodules of the provider (for example, the definition of all Azure specific data types `provider/azure/terraform.rb` and `provider/azure/ansible.rb`). Together with the configuration definitions (`provider/terraform/config.rb` or `provider/ansible/config.rb`), we will be able to use all defined data types and properties in `api.yaml`, `terraform.yaml`, `ansible.yaml` and all ERB templates. As a developer, you need to make sure your types are eventually included in these root objects, otherwise magic-modules will raise errors.

## Code Templates

The overall structure of all code templates are listed in the Folder Structure section. Typically for each template, we introduced a helper function with it, and throughout the code base, we should call that helper function to actually apply the code template.

For example, for a template `property_to_sdkobject.erb` in Terraform, we have the following functions/files:

* Actual template file: `templates/azure/terraform/sdktypes/property_to_sdkobject.erb`
* Helper function: `build_property_to_sdk_object` in `provider/azure/terraform/sdk/sub_template.rb`

We should always call the helper functions throughout the code base like the one in `templates/azure/terraform/sdktypes/nested_object_field_assign.erb`.

## Logic

We handled both Terraform and Ansible resource code generation in a similar way.

1. Magic-modules core handles all definitions (`api.yaml`) and overrides (`terraform.yaml`/`ansible.yaml`) for us
2. Generate schema definition structure
3. Generate code to marshal data from schema to SDK
4. Generate code to call CRUDL SDK APIs
5. Generate code to marshal data from SDK to schema

Since magic-modules core handles all overrides, I will not talk too much about it, please reference to the original magic-modules documentation. As a developer for Azure, we only need to define the overridable attributes (which will be used in `terraform.yaml`/`ansible.yaml`) in one of the `resource_override.rb` or `property_override.rb`, and then we are able to use them throughout the code base including templates and helper functions.

Generating schema definition is simple in Ansible since we only need to call `to_yaml` helper function. It requires some additional efforts for Terraform. That's the reason why `templates/terraform/schemas` and `templates/azure/terraform/schemas` exist.

Marshalling is another tough job to do because Azure SDK objects are deeply hierarchical objects. Both Ansible and Terraform handle it in a recursive way (recursive code template). We put both-way marshalling code templates in `templates/azure/[terraform|ansible]/sdktypes` folder. You will be able to find the corresponding helper functions by using the names of the templates.

It is not too difficult to generate Azure SDK API calls since they are all defined in `azure_sdk_definitions` section of `api.yaml`. Typically API calls are put directly in the resource/module code template, but with an reusable method call sub-template.

## Command Line Option

Besides the basic command line options, we add the `-c (--cloud)` option for users to specify the target cloud platform. The supported values are:
* `gcp`: Google Cloud Platform (by default).
* `azure`: Microsoft Azure Cloud

The option records the choice of cloud platform by maintaining a global variable in the entry file `compiler.rb`. The variable controls the switches to different code logic according to different cloud platforms in the following files, `api/resource.rb`, `api/type.rb`, `provider/core.rb`, `provider/config.rb`, `provider/ansible.rb`, `provider/ansible/documentation.rb`, `provider/terraform.rb`, `provider/terraform/sub_template.rb`.
3 changes: 2 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ GEM

PLATFORMS
ruby
x64-mingw32

DEPENDENCIES
activesupport
Expand All @@ -117,4 +118,4 @@ DEPENDENCIES
rubocop (~> 0.63.1)

BUNDLED WITH
1.17.2
2.0.1
33 changes: 33 additions & 0 deletions api/azure/resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2019 Microsoft Corp.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require 'google/yaml_validator'
require 'api/azure/sdk_definition'

module Api
module Azure
module Resource

# The Azure-extended properties which supplement Api::Resource::Properties
module Properties
attr_reader :azure_sdk_definition
end

# Azure-extended validate function of Api::Resource::validate
def azure_validate
check :azure_sdk_definition, type: Api::Azure::SDKDefinition, required: true
end

end
end
end
64 changes: 64 additions & 0 deletions api/azure/sdk_definition.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright 2019 Microsoft Corp.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require 'api/object'
require 'api/azure/sdk_operation_definition'

module Api
module Azure
class SDKDefinition < Api::Object
attr_reader :provider_name
attr_reader :go_client_namespace
attr_reader :go_client
attr_reader :python_client_namespace
attr_reader :python_client
attr_reader :create
attr_reader :read
attr_reader :update
attr_reader :delete
attr_reader :list_by_parent
attr_reader :list_by_resource_group
attr_reader :list_by_subscription

def validate
super
check :provider_name, type: ::String, required: true
check :go_client_namespace, type: ::String, required: true
check :go_client, type: ::String, required: true
check :python_client_namespace, type: ::String, required: true
check :python_client, type: ::String, required: true
check :create, type: Api::Azure::SDKOperationDefinition, required: true
check :read, type: Api::Azure::SDKOperationDefinition, required: true
check :update, type: Api::Azure::SDKOperationDefinition
check :delete, type: Api::Azure::SDKOperationDefinition, required: true
check :list_by_parent, type: Api::Azure::SDKOperationDefinition
check :list_by_resource_group, type: Api::Azure::SDKOperationDefinition
check :list_by_subscription, type: Api::Azure::SDKOperationDefinition
end

def filter_language!(language)
@create.filter_language!(language) unless @create.nil?
@read.filter_language!(language) unless @read.nil?
@update.filter_language!(language) unless @update.nil?
@delete.filter_language!(language) unless @delete.nil?
end

def merge_overrides!(overrides)
@create.merge_overrides!(overrides.create) if [email protected]? && !overrides.create.nil?
@read.merge_overrides!(overrides.read) if [email protected]? && !overrides.read.nil?
@update.merge_overrides!(overrides.update) if [email protected]? && !overrides.update.nil?
@delete.merge_overrides!(overrides.delete) if [email protected]? && !overrides.delete.nil?
end
end
end
end
34 changes: 34 additions & 0 deletions api/azure/sdk_definition_override.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2019 Microsoft Corp.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require 'api/object'
require 'api/azure/sdk_operation_definition_override'

module Api
module Azure
class SDKDefinitionOverride < Api::Object
attr_reader :create
attr_reader :read
attr_reader :update
attr_reader :delete

def validate
super
check :create, type: SDKOperationDefinitionOverride
check :read, type: SDKOperationDefinitionOverride
check :update, type: SDKOperationDefinitionOverride
check :delete, type: SDKOperationDefinitionOverride
end
end
end
end
67 changes: 67 additions & 0 deletions api/azure/sdk_operation_definition.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright 2019 Microsoft Corp.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require 'api/object'
require 'api/azure/sdk_type_definition'

module Api
module Azure
class SDKOperationDefinition < Api::Object
attr_reader :go_func_name
attr_reader :python_func_name
attr_reader :async
attr_reader :request
attr_reader :response

def validate
super
@request ||= Hash.new
@response ||= Hash.new

check :go_func_name, type: ::String, required: true
check :python_func_name, type: ::String, required: true
check :async, type: :boolean
check_ext :request, type: ::Hash, key_type: ::String, item_type: SDKTypeDefinition, required: true
check_ext :response, type: ::Hash, key_type: ::String, item_type: SDKTypeDefinition, required: true
end

def filter_language!(language)
filter_applicable! @request, language
filter_applicable!(@response, language) unless @response.nil?
end

def merge_overrides!(overrides)
merge_hash_table!(@request, overrides.request) unless overrides.request.nil?
merge_hash_table!(@response, overrides.response) unless overrides.response.nil?
end

private

def filter_applicable!(fields, language)
fields.reject!{|name, value| !value.applicable_to.nil? && !value.applicable_to.include?(language)}
end

def merge_hash_table!(fields, overrides)
overrides.each do |name, value|
if value.remove
fields.delete(name)
elsif !fields.has_key?(name)
fields[name] = value
else
fields[name].merge_overrides! value
end
end
end
end
end
end
30 changes: 30 additions & 0 deletions api/azure/sdk_operation_definition_override.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2019 Microsoft Corp.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require 'api/object'
require 'api/azure/sdk_type_definition_override'

module Api
module Azure
class SDKOperationDefinitionOverride < Api::Object
attr_reader :request
attr_reader :response

def validate
super
check_ext :request, type: ::Hash, key_type: ::String, item_type: SDKTypeDefinitionOverride
check_ext :response, type: ::Hash, key_type: ::String, item_type: SDKTypeDefinitionOverride
end
end
end
end
Loading