NEW: initial commit

This commit is contained in:
KF 2024-05-30 12:01:24 +08:00
commit 1e9b274965
Signed by: xpk
GPG Key ID: CD4FF6793F09AB86
20 changed files with 439 additions and 0 deletions

32
.gitignore vendored Normal file
View File

@ -0,0 +1,32 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
### Terraform ###
.terraform

3
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

6
.idea/misc.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_22" default="true" project-jdk-name="graalvm-22" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/terraform-training.iml" filepath="$PROJECT_DIR$/terraform-training.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -0,0 +1,10 @@
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/hashicorp/aws" {
version = "5.51.1"
constraints = ">= 5.0.0"
hashes = [
"h1:ESfxP2tCO6IZldSQnepXmIm+x+VtaQt/bKgGjYE+0BY=",
]
}

5
Compute/Demo1/main.tf Normal file
View File

@ -0,0 +1,5 @@
resource "aws_instance" "example" {
ami = "ami-0157c3cc39a1c5cc0"
instance_type = "t4g.large"
subnet_id = "subnet-0927ba1b06ccfe6c5"
}

28
Compute/Demo1/provider.tf Normal file
View File

@ -0,0 +1,28 @@
provider "aws" {
region = "ap-east-1"
default_tags {
tags = {
ServiceProvider = "RackspaceTechnology"
Environment = "Training"
Project = "Iac"
TerraformMode = "managed"
Owner = "ken2026"
TerraformDir = "${reverse(split("/", path.cwd))[1]}/${reverse(split("/", path.cwd))[0]}"
}
}
}
output "last-updated" {
value = timestamp()
}
terraform {
required_version = ">= 1.3.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.0"
}
}
}

View File

@ -0,0 +1,9 @@
{
"version": 4,
"terraform_version": "1.3.9",
"serial": 9,
"lineage": "05a7ba76-3512-c858-95f8-aa6ea555f1ee",
"outputs": {},
"resources": [],
"check_results": null
}

View File

@ -0,0 +1,156 @@
{
"version": 4,
"terraform_version": "1.3.9",
"serial": 7,
"lineage": "05a7ba76-3512-c858-95f8-aa6ea555f1ee",
"outputs": {
"last-updated": {
"value": "2024-05-30T02:41:22Z",
"type": "string"
}
},
"resources": [
{
"mode": "managed",
"type": "aws_instance",
"name": "example",
"provider": "provider[\"registry.terraform.io/hashicorp/aws\"]",
"instances": [
{
"schema_version": 1,
"attributes": {
"ami": "ami-0157c3cc39a1c5cc0",
"arn": "arn:aws:ec2:ap-east-1:040216112220:instance/i-037e063ccb317f0db",
"associate_public_ip_address": true,
"availability_zone": "ap-east-1a",
"capacity_reservation_specification": [
{
"capacity_reservation_preference": "open",
"capacity_reservation_target": []
}
],
"cpu_core_count": 2,
"cpu_options": [
{
"amd_sev_snp": "",
"core_count": 2,
"threads_per_core": 1
}
],
"cpu_threads_per_core": 1,
"credit_specification": [
{
"cpu_credits": "unlimited"
}
],
"disable_api_stop": false,
"disable_api_termination": false,
"ebs_block_device": [],
"ebs_optimized": false,
"enclave_options": [
{
"enabled": false
}
],
"ephemeral_block_device": [],
"get_password_data": false,
"hibernation": false,
"host_id": "",
"host_resource_group_arn": null,
"iam_instance_profile": "",
"id": "i-037e063ccb317f0db",
"instance_initiated_shutdown_behavior": "stop",
"instance_lifecycle": "",
"instance_market_options": [],
"instance_state": "running",
"instance_type": "t4g.large",
"ipv6_address_count": 0,
"ipv6_addresses": [],
"key_name": "",
"launch_template": [],
"maintenance_options": [
{
"auto_recovery": "default"
}
],
"metadata_options": [
{
"http_endpoint": "enabled",
"http_protocol_ipv6": "disabled",
"http_put_response_hop_limit": 2,
"http_tokens": "required",
"instance_metadata_tags": "disabled"
}
],
"monitoring": false,
"network_interface": [],
"outpost_arn": "",
"password_data": "",
"placement_group": "",
"placement_partition_number": 0,
"primary_network_interface_id": "eni-0375c305514c6813c",
"private_dns": "ip-172-20-16-111.ap-east-1.compute.internal",
"private_dns_name_options": [
{
"enable_resource_name_dns_a_record": false,
"enable_resource_name_dns_aaaa_record": false,
"hostname_type": "ip-name"
}
],
"private_ip": "172.20.16.111",
"public_dns": "ec2-18-163-2-19.ap-east-1.compute.amazonaws.com",
"public_ip": "18.163.2.19",
"root_block_device": [
{
"delete_on_termination": true,
"device_name": "/dev/xvda",
"encrypted": false,
"iops": 3000,
"kms_key_id": "",
"tags": {},
"tags_all": {
"Environment": "Training",
"Owner": "ken2026",
"Project": "Iac",
"ServiceProvider": "RackspaceTechnology",
"TerraformDir": "Compute/Demo1",
"TerraformMode": "managed"
},
"throughput": 125,
"volume_id": "vol-061192850e49ddff0",
"volume_size": 8,
"volume_type": "gp3"
}
],
"secondary_private_ips": [],
"security_groups": [],
"source_dest_check": true,
"spot_instance_request_id": "",
"subnet_id": "subnet-0927ba1b06ccfe6c5",
"tags": {},
"tags_all": {
"Environment": "Training",
"Owner": "ken2026",
"Project": "Iac",
"ServiceProvider": "RackspaceTechnology",
"TerraformDir": "Compute/Demo1",
"TerraformMode": "managed"
},
"tenancy": "default",
"timeouts": null,
"user_data": null,
"user_data_base64": null,
"user_data_replace_on_change": false,
"volume_tags": null,
"vpc_security_group_ids": [
"sg-04ec154cb0f516e76"
]
},
"sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6MTIwMDAwMDAwMDAwMCwicmVhZCI6OTAwMDAwMDAwMDAwLCJ1cGRhdGUiOjYwMDAwMDAwMDAwMH0sInNjaGVtYV92ZXJzaW9uIjoiMSJ9"
}
]
}
],
"check_results": null
}

View File

@ -0,0 +1,10 @@
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/hashicorp/aws" {
version = "5.51.1"
constraints = ">= 5.0.0"
hashes = [
"h1:ESfxP2tCO6IZldSQnepXmIm+x+VtaQt/bKgGjYE+0BY=",
]
}

14
Compute/Demo2/main.tf Normal file
View File

@ -0,0 +1,14 @@
resource "aws_instance" "example1" {
count = 2
ami = "ami-0157c3cc39a1c5cc0"
instance_type = "t4g.large"
subnet_id = "subnet-0927ba1b06ccfe6c5"
}
resource "aws_instance" "example2" {
for_each = toset(["instance1", "instance2"])
ami = "ami-0157c3cc39a1c5cc0"
instance_type = "t4g.large"
subnet_id = "subnet-0927ba1b06ccfe6c5"
tags = { Name : each.value }
}

28
Compute/Demo2/provider.tf Normal file
View File

@ -0,0 +1,28 @@
provider "aws" {
region = "ap-east-1"
default_tags {
tags = {
ServiceProvider = "RackspaceTechnology"
Environment = "Training"
Project = "Iac"
TerraformMode = "managed"
Owner = "ken2026"
TerraformDir = "${reverse(split("/", path.cwd))[1]}/${reverse(split("/", path.cwd))[0]}"
}
}
}
output "last-updated" {
value = timestamp()
}
terraform {
required_version = ">= 1.3.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.0"
}
}
}

View File

@ -0,0 +1,17 @@
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/hashicorp/aws" {
version = "5.51.1"
constraints = ">= 5.0.0"
hashes = [
"h1:ESfxP2tCO6IZldSQnepXmIm+x+VtaQt/bKgGjYE+0BY=",
]
}
provider "registry.terraform.io/hashicorp/tls" {
version = "4.0.5"
hashes = [
"h1:e4LBdJoZJNOQXPWgOAG0UuPBVhCStu98PieNlqJTmeU=",
]
}

4
Compute/Demo3/main.tf Normal file
View File

@ -0,0 +1,4 @@
module "ec2-instance" {
source = "../../Modules/Compute/ec2"
name = "demo3"
}

28
Compute/Demo3/provider.tf Normal file
View File

@ -0,0 +1,28 @@
provider "aws" {
region = "ap-east-1"
default_tags {
tags = {
ServiceProvider = "RackspaceTechnology"
Environment = "Training"
Project = "Iac"
TerraformMode = "managed"
Owner = "ken2026"
TerraformDir = "${reverse(split("/", path.cwd))[1]}/${reverse(split("/", path.cwd))[0]}"
}
}
}
output "last-updated" {
value = timestamp()
}
terraform {
required_version = ">= 1.3.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.0"
}
}
}

View File

@ -0,0 +1,26 @@
resource "aws_instance" "example" {
ami = "ami-0157c3cc39a1c5cc0"
instance_type = "t4g.large"
subnet_id = "subnet-0927ba1b06ccfe6c5"
key_name = aws_key_pair.this.key_name
# IMDSv2 requirement
dynamic "metadata_options" {
for_each = var.disable_secure_idmsv2 == false ? { set_idmsv2 : true } : {}
content {
http_endpoint = "enabled"
http_tokens = "required"
http_put_response_hop_limit = 2
}
}
tags = { Name : var.name }
}
resource "tls_private_key" "this" {
algorithm = "ED25519"
}
resource "aws_key_pair" "this" {
key_name = "${var.name}-sshkey"
public_key = tls_private_key.this.public_key_openssh
}

View File

@ -0,0 +1,28 @@
provider "aws" {
region = "ap-east-1"
default_tags {
tags = {
ServiceProvider = "RackspaceTechnology"
Environment = "Training"
Project = "Iac"
TerraformMode = "managed"
Owner = "ken2026"
TerraformDir = "${reverse(split("/", path.cwd))[1]}/${reverse(split("/", path.cwd))[0]}"
}
}
}
output "last-updated" {
value = timestamp()
}
terraform {
required_version = ">= 1.3.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.0"
}
}
}

View File

@ -0,0 +1,10 @@
variable "name" {
type = string
description = "Name of Ec2 instance"
}
variable "disable_secure_idmsv2" {
type = bool
default = false
description = "Allow use of insecure idmsv1. Default is false."
}

11
terraform-training.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>