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

Add API to CRUD a SQL database instance #103

Merged
merged 1 commit into from
Nov 11, 2024

Conversation

yunkon-kim
Copy link
Member

@yunkon-kim yunkon-kim commented Nov 11, 2024

  • It's only tested on AWS.

Note

Support for Azure, GCP, and NCP is coming soon.

API list
image

Test sequence and results

1. Create a terrarium to enrich the SQL database

  • API: POST /tr/{trId}/sql-db/env
  • trId: tr01
  • Response body:
{
  "success": true,
  "message": "the infrastructure terrarium is successfully initialized",
  "details": "\n\u001b[0m\u001b[1mInitializing the backend...\u001b[0m\n\n\u001b[0m\u001b[1mInitializing provider plugins...\u001b[0m\n- Reusing previous version of hashicorp/aws from the dependency lock file\n- Using previously-installed hashicorp/aws v5.75.0\n\n\u001b[0m\u001b[1m\u001b[32mOpenTofu has been successfully initialized!\u001b[0m\u001b[32m\u001b[0m\n\u001b[0m\u001b[32m\nYou may now begin working with OpenTofu. Try running \"tofu plan\" to see\nany changes that are required for your infrastructure. All OpenTofu commands\nshould now work.\n\nIf you ever set or change modules or backend configuration for OpenTofu,\nrerun this command to reinitialize your working directory. If you forget, other\ncommands will detect it and remind you to do so if necessary.\u001b[0m\n"
}

2. Create an infracode for the SQL database

  • API: POST /tr/{trId}/sql-db/infracode
  • trId: tr01
  • Request body:
{
  "tfVars": {
    "csp_region": "ap-northeast-2",
    "csp_subnet1_id": "subnet-01d5a43064d86573b",
    "csp_subnet2_id": "subnet-054e2ae6cdb5ba314",
    "csp_vnet_id": "vpc-0c6130f1517e875fe",
    "db_admin_password": "mysdbpass",
    "db_admin_username": "mydbadmin",
    "db_engine_port": 3306,
    "db_engine_version": "8.0.39",
    "db_instance_class": "db.t3.micro",
    "db_instance_identifier": "mydbinstance",
    "egress_cidr_block": "0.0.0.0/0",
    "ingress_cidr_block": "0.0.0.0/0",
    "terrarium_id": ""
  }
}
  • Response body:
{
  "success": true,
  "message": "the infracode for SQL database is Successfully created"
}  

3. Check the infracode

  • API: POST /tr/{trId}/vpn/gcp-aws/plan
  • trId: tr01
  • Response body: skip this result

4. Create SQL database

  • API: POST /tr/{trId}/sql-db
  • trId: tr01
  • Response body:
{
  "success": true,
  "message": "the request (id: 1731313324637003352) is successfully accepted and still deploying resource",
  "details": "Request (reqId: 1731313324637003352) in progress. Please use the status check API with the request ID."
}

5. Get the information of SQL database

  • API: GET /tr/{trId}/sql-db
  • trId: tr01
  • Query param: detail=refined
  • Response body:
{
  "success": true,
  "message": "refined read resource info (map)",
  "object": {
    "db_instance_endpoint": "tr01-mydbinstance.chrkjg2ktom1.ap-northeast-2.rds.amazonaws.com:3306",
    "db_instance_engine": "mysql",
    "db_instance_identifier": "tr01-mydbinstance",
    "db_instance_port": 3306,
    "db_instance_subnet_ids": [
      "subnet-01d5a43064d86573b",
      "subnet-054e2ae6cdb5ba314"
    ],
    "db_instance_username": "mydbadmin",
    "db_instance_version": "8.0.39",
    "db_instance_vpc_id": "vpc-0c6130f1517e875fe",
    "db_security_group_name": "tr01-rds-sg"
  }
}

6. Destroy the SQL database

  • API: DELETE /tr/{trId}/sql-db
  • trId: tr01
  • Response body: skip this result

7. Clear the terrarium

  • API: DELETE /tr/{trId}/sql-db/env
  • trId: tr01

* It's only tested on AWS.
@yunkon-kim yunkon-kim merged commit 1e3182c into cloud-barista:main Nov 11, 2024
@yunkon-kim yunkon-kim deleted the 241108-16 branch November 11, 2024 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant