Skip to content

Commit

Permalink
updates test script and task description
Browse files Browse the repository at this point in the history
  • Loading branch information
id27182 committed Nov 8, 2024
1 parent 0763feb commit f7974a7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.terraform/*
.terraform.lock.hcl
terraform.tfstate
tfPlan.json
tfPlan
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,23 @@ Grafana is an app for building dashboards with data from different sources. To r
To complete this task:
1. Edit `main.tf` - uncommend the `aws_vpc` resource. VPC is an AWS resource for building private networks.
2. Run terraform init and plan, make sure to save your execution plan to a file, called `tfplan` in this repo.
2. Run the following commands to generage a terraform execution plan in json format:
```
terraform init
terraform plan -out=tfplan
terraform show -json tfplan > tfplan.json
```
3. Run automated test to check yourself
3. Run automated test to check yourself.
```
pwsh ./tests/test-tf-plan.ps1
```
If any test fails - please check your task code and repeat step 2 to generage a new tfplan.json file.
4. Deploy infrastructure using terraform apply
```
terraform apply
```
5. Submit your solution for a review.
5. Commit file `tfplan.json` and submit your solution for a review.
21 changes: 2 additions & 19 deletions tests/test-tf-plan.ps1
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
$tfPlanPath = "tfplan"
$tfPlanPath = "tfplan.json"

# Check if terraform execution plan exists
if (Test-Path $tfPlanPath) {
Write-Output "`u{2705} Checking if terrafom plan exists - OK. "
} else {
throw "`u{1F635} Unable to find terraform plan file. Please make sure that you saved terraform execution plan to the file and try again. "
}

# Convert execution plan to json
$tfPlanJsonPath = "tfPlan.json"
# try {
Write-Output "Runnint terraform init..."
terraform init
Write-Output "Runnint terraform show..."
terraform show -json "$tfPlanPath" > "$tfPlanJsonPath"

# } catch {
# throw "`u{1F635} Unexpected error: unable to read terraform plan file. Please contact your course mentor. "
# }

$plan = (Get-Content -Path $tfPlanJsonPath | ConvertFrom-Json)

Write-Output "Readinig execution plan..."
Get-Content -Path $tfPlanJsonPath
$plan
$plan = (Get-Content -Path $tfPlanPath | ConvertFrom-Json)

$vpc = $plan.resource_changes | Where-Object {$_.type -eq "aws_vpc"}
if ($vpc -and ($vpc.Count -eq 1 )) {
Expand Down
1 change: 1 addition & 0 deletions tfPlan.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"format_version":"1.1","terraform_version":"1.4.5","planned_values":{"root_module":{"resources":[{"address":"aws_vpc.network","mode":"managed","type":"aws_vpc","name":"network","provider_name":"registry.terraform.io/hashicorp/aws","schema_version":1,"values":{"assign_generated_ipv6_cidr_block":null,"cidr_block":"10.0.0.0/16","enable_dns_support":true,"instance_tenancy":"default","ipv4_ipam_pool_id":null,"ipv4_netmask_length":null,"ipv6_ipam_pool_id":null,"ipv6_netmask_length":null,"tags":null},"sensitive_values":{"tags_all":{}}}]}},"resource_changes":[{"address":"aws_vpc.network","mode":"managed","type":"aws_vpc","name":"network","provider_name":"registry.terraform.io/hashicorp/aws","change":{"actions":["create"],"before":null,"after":{"assign_generated_ipv6_cidr_block":null,"cidr_block":"10.0.0.0/16","enable_dns_support":true,"instance_tenancy":"default","ipv4_ipam_pool_id":null,"ipv4_netmask_length":null,"ipv6_ipam_pool_id":null,"ipv6_netmask_length":null,"tags":null},"after_unknown":{"arn":true,"default_network_acl_id":true,"default_route_table_id":true,"default_security_group_id":true,"dhcp_options_id":true,"enable_dns_hostnames":true,"enable_network_address_usage_metrics":true,"id":true,"ipv6_association_id":true,"ipv6_cidr_block":true,"ipv6_cidr_block_network_border_group":true,"main_route_table_id":true,"owner_id":true,"tags_all":true},"before_sensitive":false,"after_sensitive":{"tags_all":{}}}}],"configuration":{"provider_config":{"aws":{"name":"aws","full_name":"registry.terraform.io/hashicorp/aws","version_constraint":"~\u003e 5.0"}},"root_module":{"resources":[{"address":"aws_vpc.network","mode":"managed","type":"aws_vpc","name":"network","provider_config_key":"aws","expressions":{"cidr_block":{"constant_value":"10.0.0.0/16"}},"schema_version":1}]}}}
Binary file removed tfplan
Binary file not shown.

0 comments on commit f7974a7

Please sign in to comment.