Skip to content

Commit c31a281

Browse files
authored
Merge pull request #65 from oleksandr-r-q/feature/oleksandr_gcp_tf_provider
Feature/oleksandr gcp tf provider
2 parents f7fa713 + 79cf6e0 commit c31a281

File tree

18 files changed

+1646
-3
lines changed

18 files changed

+1646
-3
lines changed

deploy.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ shellfoundry install
1111
cd ..\..
1212
cd backends\aws_tf_backend
1313
shellfoundry install
14+
cd ..\..
15+
cd backends\gcp_tf_backend
16+
shellfoundry install
1417
cd ..\..\..

package/cloudshell/iac/terraform/constants.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
AZURE2G_MODEL = "Microsoft Azure Cloud Provider 2G"
4343
AWS2G_MODEL = "Amazon AWS Cloud Provider 2G"
4444

45-
CLP_PROVIDER_MODELS = [AWS1G_MODEL, AWS2G_MODEL, AZURE1G_MODEL, AZURE2G_MODEL]
45+
GCP2G_MODEL = "Google Cloud Provider"
46+
47+
CLP_PROVIDER_MODELS = [AWS1G_MODEL, AWS2G_MODEL, AZURE1G_MODEL, AZURE2G_MODEL, GCP2G_MODEL]
4648

4749
# Misc
4850
DIRTY_CHARS = r'''

package/cloudshell/iac/terraform/services/clp_envvar_handler.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,24 @@ def set_env_vars_based_on_clp(self):
6565
os.environ["ARM_CLIENT_ID"] = attr.Value
6666
if self.does_attribute_match(self._clp_res_model, attr, "Azure Application Key"):
6767
os.environ["ARM_CLIENT_SECRET"] = self._shell_helper.api.DecryptPassword(attr.Value).Value
68+
69+
70+
class GCPCloudProviderEnvVarHandler(BaseCloudProviderEnvVarHandler):
71+
def __init__(self, clp_res_model, clp_resource_attributes, shell_helper):
72+
BaseCloudProviderEnvVarHandler.__init__(self)
73+
self._clp_res_model = clp_res_model
74+
self._clp_resource_attributes = clp_resource_attributes
75+
self._shell_helper = shell_helper
76+
77+
def set_env_vars_based_on_clp(self):
78+
project_flag = False
79+
cred_flag = False
80+
for attr in self._clp_resource_attributes:
81+
if self.does_attribute_match(self._clp_res_model, attr, "Google Cloud Provider.Credentials Json Path"):
82+
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = attr.Value
83+
cred_flag = True
84+
if self.does_attribute_match(self._clp_res_model, attr, "Google Cloud Provider.project"):
85+
os.environ["GOOGLE_PROJECT"] = attr.Value
86+
project_flag = True
87+
if not cred_flag and not project_flag:
88+
self._shell_helper.sandbox_messages.write_message("Project ID was not found on GCP Cloud Provider")

package/cloudshell/iac/terraform/services/provider_handler.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
from cloudshell.api.cloudshell_api import ResourceInfo
44

55
from cloudshell.iac.terraform.constants import AZURE2G_MODEL, ATTRIBUTE_NAMES, AWS2G_MODEL, CLP_PROVIDER_MODELS, \
6-
AWS1G_MODEL, AZURE1G_MODEL
6+
AWS1G_MODEL, AZURE1G_MODEL, GCP2G_MODEL
77
from cloudshell.iac.terraform.models.shell_helper import ShellHelperObject
88
from cloudshell.iac.terraform.services.clp_envvar_handler import AWSCloudProviderEnvVarHandler, \
9-
AzureCloudProviderEnvVarHandler
9+
AzureCloudProviderEnvVarHandler, GCPCloudProviderEnvVarHandler
1010

1111

1212
class ProviderHandler(object):
@@ -53,6 +53,9 @@ def _set_cloud_env_vars(
5353
elif clp_res_model in [AZURE1G_MODEL, AZURE2G_MODEL]:
5454
clp_handler = AzureCloudProviderEnvVarHandler(clp_res_model, clp_resource_attributes, shell_helper)
5555

56+
elif clp_res_model in [GCP2G_MODEL]:
57+
clp_handler = GCPCloudProviderEnvVarHandler(clp_res_model, clp_resource_attributes, shell_helper)
58+
5659
if clp_handler:
5760
clp_handler.set_env_vars_based_on_clp()
5861
else:
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
env/
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
27+
# PyInstaller
28+
# Usually these files are written by a python script from a template
29+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
30+
*.manifest
31+
*.spec
32+
33+
# Installer logs
34+
pip-log.txt
35+
pip-delete-this-directory.txt
36+
37+
# Unit test / coverage reports
38+
htmlcov/
39+
.tox/
40+
.coverage
41+
.coverage.*
42+
.cache
43+
nosetests.xml
44+
coverage.xml
45+
*,cover
46+
.hypothesis/
47+
48+
# Translations
49+
*.mo
50+
*.pot
51+
52+
# Django stuff:
53+
*.log
54+
55+
# Sphinx documentation
56+
docs/_build/
57+
58+
# PyBuilder
59+
target/
60+
cloudshell_config.yml
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
TOSCA-Meta-File-Version: 1.0
2+
CSAR-Version: 0.1.0
3+
Created-By: Anonymous
4+
Entry-Definitions: shell-definition.yaml
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<properties>
3+
4+
<!-- The address of the Quali server on which to deploy, mandatory -->
5+
<serverRootAddress>localhost</serverRootAddress>
6+
7+
<!-- The port of the Quali server on which to deploy, defaults to "8029" -->
8+
<port>8029</port>
9+
10+
<!-- The server admin username, password and domain to use when deploying -->
11+
<username>YOUR_USERNAME</username>
12+
<password>YOUR_PASSWORD</password>
13+
<domain>Global</domain>
14+
15+
<!-- Simple patterns to filter when sending the driver to the server separated by semicolons (e.g. "file.xml;logs/", also supports regular expressions),
16+
on top of the patterns specified here the plugin will automatically filter the "deployment/" and ".idea/" folders and the "deployment.xml" file -->
17+
<fileFilters>dont_upload_me.xml</fileFilters>
18+
19+
<!-- The drivers to update, holds one or more drivers -->
20+
<drivers>
21+
<!-- runFromLocalProject - Decides whether to run the driver from the current project directory for debugging purposes, defaults to "false" -->
22+
<!-- waitForDebugger - When `runFromLocalProject` is enabled, decides whether to wait for a debugger to attach before running any Python driver code, defaults to "false" -->
23+
<!-- sourceRootFolder - The folder to refer to as the project source root (if specified, the folder will be zipped and deployed instead of the whole project), defaults to the root project folder -->
24+
<driver runFromLocalProject="true" waitForDebugger="true" sourceRootFolder="gcp_tf_backend">
25+
<!-- A list of paths to the driver's files or folders relative to the project's root.
26+
may be a path to a directory, in which case all the files and folders under the directory are added into the driver's zip file.
27+
if the <sources> element is not specified, all the files under the project are added to the driver's zip file -->
28+
<sources>
29+
<source>src</source>
30+
</sources>
31+
<!-- the driver name of the driver to update -->
32+
<targetName>GcpTfBackendDriver</targetName>
33+
</driver>
34+
</drivers>
35+
36+
<!-- The scripts to update, holds one or more scripts -->
37+
<!-- A list of paths to the script's files or folders relative to the project's root.
38+
if the <sources> element is not specified, all the files under the project are added to the script's zip file.
39+
if only one file is specified, the file will not be compressed into a zip file.
40+
-->
41+
<!--
42+
<scripts>
43+
44+
<script>
45+
46+
<sources>
47+
<source>script1.py</source>
48+
</sources>
49+
<targetName>scriptToUpdate</targetName>
50+
</script>
51+
</scripts>
52+
-->
53+
</properties>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.. _readme:
2+
3+
.. include:: ../README.rst
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
tosca_definitions_version: tosca_simple_yaml_1_0
2+
3+
metadata:
4+
template_name: Gcp Tf Backend
5+
template_author: Anonymous
6+
template_version: 0.1.0
7+
template_icon: shell-icon.png
8+
9+
description: >
10+
TOSCA based resource shell
11+
12+
imports:
13+
- cloudshell_standard: cloudshell_resource_standard_2_0_3.yaml
14+
15+
node_types:
16+
17+
vendor.resource.Gcp Tf Backend:
18+
derived_from: cloudshell.nodes.GenericResource
19+
properties:
20+
Credentials Json Path:
21+
description: Credentials Json Path (Use only if Cloud Provider not specified)
22+
type: string
23+
tags: [ setting, user_input ]
24+
Bucket Name:
25+
description: The name of the bucket to be used in order to save the state file
26+
type: string
27+
tags: [ setting, user_input ]
28+
Cloud Provider:
29+
description: In case Private Key and Client Email were not filled - the keys from the cloud provider will be used.
30+
type: string
31+
Project:
32+
description: The default project to manage resources in.
33+
type: string
34+
tags: [ setting, user_input ]
35+
#Execution Server Selector:
36+
# description: Execution Server on which the discovery will be executed
37+
# type: string
38+
# tags: [ setting, user_input ]
39+
hide_address:
40+
type: string
41+
default: true
42+
## Adding custom attributes to the cloud provider discovery form
43+
44+
capabilities:
45+
auto_discovery_capability:
46+
type: cloudshell.capabilities.AutoDiscovery
47+
properties:
48+
enable_auto_discovery:
49+
type: boolean
50+
default: true
51+
auto_discovery_description:
52+
type: string
53+
default: Describe the auto discovery
54+
inventory_description:
55+
type: string
56+
default: Describe the resource shell template
57+
Bucket Name:
58+
description: The name of the bucket to be used in order to save the state file
59+
type: string
60+
# Private Key:
61+
# description: Private key
62+
# type: string
63+
Credentials Json Path:
64+
description: Credentials Json Path
65+
type: string
66+
Project:
67+
type: string
68+
default:
69+
Cloud Provider:
70+
description: In case Private Key and Client Email were not filled - the keys from the cloud provider will be used.
71+
type: string
72+
#Execution Server Selector:
73+
# description: Execution Server on which the discovery will be executed
74+
# type: string
75+
76+
77+
artifacts:
78+
icon:
79+
file: shell-icon.png
80+
type: tosca.artifacts.File
81+
driver:
82+
file: GcpTfBackendDriver.zip
83+
type: tosca.artifacts.File
6.53 KB
Loading

0 commit comments

Comments
 (0)