generated from oracle-quickstart/oci-quickstart-template
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from jason-chong/gh-update
Gh update
- Loading branch information
Showing
139 changed files
with
8,826 additions
and
1,456 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
# Terraform Modules | ||
|
||
This modules directory holds the reusable modules for Oracle Enterprise Landing Zones. | ||
These modules contain the very basics of our specific OCI Services configure in an | ||
Oracle Enterprise Landing Zone specific way. By storing them in modules we can reuse them in | ||
our [templates](../templates/README). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!-- BEGIN_TF_DOCS --> | ||
## Requirements | ||
|
||
No requirements. | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_oci"></a> [oci](#provider\_oci) | n/a | | ||
|
||
## Modules | ||
|
||
No modules. | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [oci_core_drg_attachment.drg_attachment](https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/core_drg_attachment) | resource | | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| <a name="input_drg_attachment_type"></a> [drg\_attachment\_type](#input\_drg\_attachment\_type) | DRG Attacment Network Type | `string` | n/a | yes | | ||
| <a name="input_drg_attachment_vcn_route_type"></a> [drg\_attachment\_vcn\_route\_type](#input\_drg\_attachment\_vcn\_route\_type) | DRG Attacment Network VCN Route Type | `string` | n/a | yes | | ||
| <a name="input_drg_id"></a> [drg\_id](#input\_drg\_id) | DRG OCID Value. | `string` | n/a | yes | | ||
| <a name="input_vcn_id"></a> [vcn\_id](#input\_vcn\_id) | VCN OCID Value | `string` | n/a | yes | | ||
|
||
## Outputs | ||
|
||
No outputs. | ||
<!-- END_TF_DOCS --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
terraform { | ||
required_providers { | ||
oci = { | ||
source = "oracle/oci" | ||
} | ||
} | ||
} | ||
|
||
# ----------------------------------------------------------------------------- | ||
# DRG VCN ATTACHMENT | ||
# ----------------------------------------------------------------------------- | ||
|
||
resource "oci_core_drg_attachment" "drg_attachment" { | ||
drg_id = var.drg_id | ||
network_details { | ||
id = var.vcn_id | ||
type = var.drg_attachment_type | ||
vcn_route_type = var.drg_attachment_vcn_route_type | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
variable "drg_id" { | ||
type = string | ||
description = "DRG OCID Value." | ||
} | ||
|
||
variable "vcn_id" { | ||
type = string | ||
description = "VCN OCID Value" | ||
} | ||
|
||
variable "drg_attachment_type" { | ||
type = string | ||
description = "DRG Attacment Network Type" | ||
} | ||
|
||
variable "drg_attachment_vcn_route_type" { | ||
type = string | ||
description = "DRG Attacment Network VCN Route Type" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!-- BEGIN_TF_DOCS --> | ||
## Requirements | ||
|
||
No requirements. | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_null"></a> [null](#provider\_null) | n/a | | ||
|
||
## Modules | ||
|
||
No modules. | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [null_resource.groups](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| <a name="input_group_names"></a> [group\_names](#input\_group\_names) | The list of user group names. | `list(string)` | n/a | yes | | ||
| <a name="input_identity_domain_id"></a> [identity\_domain\_id](#input\_identity\_domain\_id) | the OCID of identity domain | `string` | n/a | yes | | ||
|
||
## Outputs | ||
|
||
No outputs. | ||
<!-- END_TF_DOCS --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
resource "null_resource" "groups" { | ||
count = length(var.group_names) != 0 ? 1 : 0 | ||
|
||
triggers = { | ||
domain_id = var.identity_domain_id | ||
group_names = "${join(",", var.group_names)}" | ||
} | ||
|
||
provisioner "local-exec" { | ||
working_dir = path.module | ||
command = "pip3 install -r scripts/requirements.txt" | ||
on_failure = continue | ||
} | ||
|
||
provisioner "local-exec" { | ||
working_dir = path.module | ||
command = "python3 scripts/manage_identity_domain.py -d ${var.identity_domain_id} -g ${join(" ", var.group_names)}" | ||
on_failure = continue | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
modules/identity-domain-group/scripts/manage_identity_domain.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# Reference: | ||
# https://docs.oracle.com/en-us/iaas/Content/API/Concepts/signingrequests.htm#seven__Python | ||
# https://www.ateam-oracle.com/post/oracle-cloud-infrastructure-oci-rest-call-walkthrough-with-curl | ||
|
||
import argparse | ||
import oci | ||
import os | ||
import json | ||
import requests | ||
|
||
|
||
class ManageIdentityDomain: | ||
def __init__(self, domain_id, group_names): | ||
self.config, self.auth = self.set_up_oci_config() | ||
self.identity_client = oci.identity.IdentityClient(self.config) | ||
|
||
self.host = self.get_domain_url(domain_id) | ||
self.group_endpoint = self.host + "/admin/v1/Groups" | ||
self.group_names = group_names | ||
|
||
def set_up_oci_config(self): | ||
''' | ||
check terraform environment variables, prefixed by TF_, so it can run in our pipeline | ||
''' | ||
try: | ||
config = oci.config.from_file() | ||
auth = oci.Signer( | ||
tenancy=config['tenancy'], | ||
user=config['user'], | ||
fingerprint=config['fingerprint'], | ||
private_key_file_location=config['key_file'] | ||
) | ||
except oci.exceptions.ConfigFileNotFound: | ||
|
||
tenancy = os.environ.get("TF_VAR_tenancy_ocid") | ||
user = os.environ.get("TF_VAR_current_user_ocid") | ||
fingerprint = os.environ.get("TF_VAR_api_fingerprint") | ||
private_key_file = os.environ.get("TF_VAR_api_private_key") | ||
region = os.environ.get("TF_VAR_region") | ||
|
||
config = { | ||
"user": user, | ||
"key_content": private_key_file, | ||
"fingerprint": fingerprint, | ||
"tenancy": tenancy, | ||
"region": region, | ||
} | ||
auth = oci.Signer( | ||
tenancy=config['tenancy'], | ||
user=config['user'], | ||
fingerprint=config['fingerprint'], | ||
private_key_content=config["key_content"], | ||
private_key_file_location=None | ||
) | ||
|
||
return config, auth | ||
|
||
def get_domain_url(self, domain_id): | ||
print("Waiting for domain to enter ACTIVE state") | ||
get_domain_response = self.identity_client.get_domain( | ||
domain_id=domain_id) | ||
wait_until_domain_available_response = oci.wait_until( | ||
self.identity_client, get_domain_response, 'lifecycle_state', 'ACTIVE') | ||
|
||
print( | ||
f"Got domain url {wait_until_domain_available_response.data.url}") | ||
|
||
return wait_until_domain_available_response.data.url | ||
|
||
def create_group(self, group_name): | ||
body = { | ||
"displayName": group_name, | ||
"schemas": [ | ||
"urn:ietf:params:scim:schemas:core:2.0:Group", | ||
"urn:ietf:params:scim:schemas:oracle:idcs:extension:group:Group" | ||
] | ||
} | ||
|
||
response = requests.post( | ||
self.group_endpoint, json=body, auth=self.auth) | ||
response.raise_for_status() | ||
|
||
print( | ||
f"Display Name: {group_name} \tOCID: {json.loads(response.content)['ocid']}") | ||
|
||
def create_groups(self): | ||
for group in self.group_names: | ||
print(f"Provisioning group {group}") | ||
try: | ||
self.create_group(group) | ||
except requests.HTTPError as e: | ||
print(f"Error creating group {group}") | ||
print(e) | ||
|
||
def delete_group(self, group_name): | ||
# @TODO finish delete method and add destroy provisioner | ||
return | ||
# filter=displayName eq "john" | ||
response = requests.delete( | ||
self.group_endpoint + f"/", auth=self.auth) | ||
response.raise_for_status() | ||
|
||
print(f"Display Name: {group_name} deleted") | ||
|
||
def delete_groups(self): | ||
for group in self.group_names: | ||
print(f"Deleting group {group}") | ||
try: | ||
self.delete_group(group) | ||
except requests.HTTPError as e: | ||
print(f"Error deleting group {group}") | ||
print(e) | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
parser = argparse.ArgumentParser(description="Manage an Identity Domain") | ||
parser.add_argument('-d', '--domain_id', | ||
help="<Required> Id of the domain to manage", | ||
required=True) | ||
parser.add_argument('-g', '--group_names', | ||
nargs='+', | ||
help='<Required> Names of the groups to create (space seperated)', | ||
required=True) | ||
|
||
args = parser.parse_args() | ||
manage_id = ManageIdentityDomain(args.domain_id, args.group_names) | ||
manage_id.create_groups() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
oci | ||
requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
variable "group_names" { | ||
type = list(string) | ||
description = "The list of user group names." | ||
} | ||
|
||
variable "identity_domain_id" { | ||
type = string | ||
description = "the OCID of identity domain" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.