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-resources] module support PoC #4532

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
205 changes: 205 additions & 0 deletions reconcile/gql_definitions/introspection.json
Original file line number Diff line number Diff line change
Expand Up @@ -39132,6 +39132,11 @@
"kind": "OBJECT",
"name": "NamespaceTerraformResourceRosaAuthenticatorVPCE_V1",
"ofType": null
},
{
"kind": "OBJECT",
"name": "NamespaceTerraformResourceModule_v1",
"ofType": null
}
]
},
Expand Down Expand Up @@ -46075,6 +46080,206 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "NamespaceTerraformResourceModule_v1",
"description": null,
"fields": [
{
"name": "provider",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "region",
"description": null,
"args": [],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "identifier",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "defaults",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "overrides",
"description": null,
"args": [],
"type": {
"kind": "SCALAR",
"name": "JSON",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "output_resource_name",
"description": null,
"args": [],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "output_format",
"description": null,
"args": [],
"type": {
"kind": "INTERFACE",
"name": "NamespaceTerraformResourceOutputFormat_v1",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "annotations",
"description": null,
"args": [],
"type": {
"kind": "SCALAR",
"name": "JSON",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "module",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "NamespaceTerraformResourceModuleSpec_v1",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [
{
"kind": "INTERFACE",
"name": "NamespaceTerraformResourceAWS_v1",
"ofType": null
}
],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "NamespaceTerraformResourceModuleSpec_v1",
"description": null,
"fields": [
{
"name": "url",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "path",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "ref",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "SaasResourceTemplateTargetReference_v2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,19 @@ query TerraformResourcesNamespaces {
}
}
}
... on NamespaceTerraformResourceModule_v1 {
region
identifier
defaults
overrides
output_resource_name
annotations
module {
url
path
ref
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,19 @@
}
}
}
... on NamespaceTerraformResourceModule_v1 {
region
identifier
defaults
overrides
output_resource_name
annotations
module {
url
path
ref
}
}
}
}
}
Expand Down Expand Up @@ -1010,8 +1023,24 @@ class NamespaceTerraformResourceMskV1(NamespaceTerraformResourceAWSV1):
users: Optional[list[MskSecretParametersV1]] = Field(..., alias="users")


class NamespaceTerraformResourceModuleSpecV1(ConfiguredBaseModel):
url: str = Field(..., alias="url")
path: str = Field(..., alias="path")
ref: str = Field(..., alias="ref")


class NamespaceTerraformResourceModuleV1(NamespaceTerraformResourceAWSV1):
region: Optional[str] = Field(..., alias="region")
identifier: str = Field(..., alias="identifier")
defaults: str = Field(..., alias="defaults")
overrides: Optional[str] = Field(..., alias="overrides")
output_resource_name: Optional[str] = Field(..., alias="output_resource_name")
annotations: Optional[str] = Field(..., alias="annotations")
module: NamespaceTerraformResourceModuleSpecV1 = Field(..., alias="module")


class NamespaceTerraformProviderResourceAWSV1(NamespaceExternalResourceV1):
resources: list[Union[NamespaceTerraformResourceRDSV1, NamespaceTerraformResourceRosaAuthenticatorV1, NamespaceTerraformResourceALBV1, NamespaceTerraformResourceS3V1, NamespaceTerraformResourceRoleV1, NamespaceTerraformResourceASGV1, NamespaceTerraformResourceSNSTopicV1, NamespaceTerraformResourceElastiCacheV1, NamespaceTerraformResourceServiceAccountV1, NamespaceTerraformResourceS3SQSV1, NamespaceTerraformResourceCloudWatchV1, NamespaceTerraformResourceRosaAuthenticatorVPCEV1, NamespaceTerraformResourceS3CloudFrontV1, NamespaceTerraformResourceKMSV1, NamespaceTerraformResourceElasticSearchV1, NamespaceTerraformResourceACMV1, NamespaceTerraformResourceKinesisV1, NamespaceTerraformResourceRoute53ZoneV1, NamespaceTerraformResourceMskV1, NamespaceTerraformResourceSQSV1, NamespaceTerraformResourceDynamoDBV1, NamespaceTerraformResourceECRV1, NamespaceTerraformResourceS3CloudFrontPublicKeyV1, NamespaceTerraformResourceSecretsManagerV1, NamespaceTerraformResourceSecretsManagerServiceAccountV1, NamespaceTerraformResourceAWSV1]] = Field(..., alias="resources")
resources: list[Union[NamespaceTerraformResourceRDSV1, NamespaceTerraformResourceRosaAuthenticatorV1, NamespaceTerraformResourceALBV1, NamespaceTerraformResourceS3V1, NamespaceTerraformResourceRoleV1, NamespaceTerraformResourceASGV1, NamespaceTerraformResourceSNSTopicV1, NamespaceTerraformResourceElastiCacheV1, NamespaceTerraformResourceServiceAccountV1, NamespaceTerraformResourceS3SQSV1, NamespaceTerraformResourceCloudWatchV1, NamespaceTerraformResourceRosaAuthenticatorVPCEV1, NamespaceTerraformResourceModuleV1, NamespaceTerraformResourceS3CloudFrontV1, NamespaceTerraformResourceKMSV1, NamespaceTerraformResourceElasticSearchV1, NamespaceTerraformResourceACMV1, NamespaceTerraformResourceKinesisV1, NamespaceTerraformResourceRoute53ZoneV1, NamespaceTerraformResourceMskV1, NamespaceTerraformResourceSQSV1, NamespaceTerraformResourceDynamoDBV1, NamespaceTerraformResourceECRV1, NamespaceTerraformResourceS3CloudFrontPublicKeyV1, NamespaceTerraformResourceSecretsManagerV1, NamespaceTerraformResourceSecretsManagerServiceAccountV1, NamespaceTerraformResourceAWSV1]] = Field(..., alias="resources")


class EnvironmentV1(ConfiguredBaseModel):
Expand Down
20 changes: 17 additions & 3 deletions reconcile/utils/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,31 @@ class GitError(Exception):
pass


def clone(repo_url, wd, depth=None, verify=True):
def clone(
repo_url: str,
wd: str,
depth: int | None = None,
verify: bool | None = True,
ref: str | None = None,
token: str | None = None,
):
cmd = ["git"]
if not verify:
cmd += ["-c", "http.sslVerify=false"]
cmd += ["clone"]
if depth:
cmd += ["--depth", str(depth)]
cmd += [repo_url, wd]
if ref:
cmd += ["--branch", ref]
if token:
cmd.append(repo_url.replace("https://", f"https://{token}@"))
else:
cmd.append(repo_url)
cmd += [wd]
os.makedirs(wd, exist_ok=True)
result = subprocess.run(cmd, cwd=wd, capture_output=True, check=False)
if result.returncode != 0:
raise GitError(f"git clone failed: {repo_url}")
raise GitError(f"git clone failed: {repo_url}: {result}")


def checkout(commit, wd):
Expand Down
4 changes: 2 additions & 2 deletions reconcile/utils/gitlab_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ def __init__(
self.server = instance["url"]
if not secret_reader:
secret_reader = SecretReader(settings=settings)
token = secret_reader.read(instance["token"])
self.token = secret_reader.read(instance["token"])
self.ssl_verify = instance["sslVerify"]
if self.ssl_verify is None:
self.ssl_verify = True
self.gl = gitlab.Gitlab(
self.server,
private_token=token,
private_token=self.token,
ssl_verify=self.ssl_verify,
timeout=timeout,
)
Expand Down
Loading