From f7974a7a0bfac8e6a7dab3cf1657a79e690118c5 Mon Sep 17 00:00:00 2001 From: Bohdan Mateiko Date: Fri, 8 Nov 2024 20:21:29 +0200 Subject: [PATCH] updates test script and task description --- .gitignore | 2 +- README.md | 12 +++++++++--- tests/test-tf-plan.ps1 | 21 ++------------------- tfPlan.json | 1 + tfplan | Bin 2727 -> 0 bytes 5 files changed, 13 insertions(+), 23 deletions(-) create mode 100644 tfPlan.json delete mode 100644 tfplan diff --git a/.gitignore b/.gitignore index 68f1b58..7baab11 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ .terraform/* .terraform.lock.hcl terraform.tfstate -tfPlan.json +tfPlan diff --git a/README.md b/README.md index deba715..200d82b 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/tests/test-tf-plan.ps1 b/tests/test-tf-plan.ps1 index 5d114ed..a64e2cd 100644 --- a/tests/test-tf-plan.ps1 +++ b/tests/test-tf-plan.ps1 @@ -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 )) { diff --git a/tfPlan.json b/tfPlan.json new file mode 100644 index 0000000..45a8194 --- /dev/null +++ b/tfPlan.json @@ -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}]}}} diff --git a/tfplan b/tfplan deleted file mode 100644 index f0600eec6745bd5e8353ea4dfa919f3d5b1278b1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2727 zcmd5;c{~)_9v>$AkS%pB*{XOdzTbm@0ryA(_}Q(z;JhHq&-kJ44cWYQ6i@yMesX{EQZ`7Xb}aO|m&&VmaB^li?juY3(}wH@BEm!YktKD> zNV1w5pCfzJQroKy&pRf4i8!}(hrD*5tRJ04@Y61g)+NND4>Ig4PHF%C)aeYGekZV@z+?lX`bkI7Hs;?vNuh2(uW7A;b=2DUt8httLkH zi~T~?9GB7RlPS4*uppgb&$Fnc9q04l0OW)r1k#v(twnp*Cpe50gHvTnf8BT#$)~Bw z-CjYS78FNF9OzzpNmD#Bm3OG4s|~^h0I*mH7$5(TnR+ONJ-WgT03g1rG2fpWhZ4LA z=uMF=QW^!hkAf~TjiH@Kl3E)U9W64Dccf72r(WR~Crd(t*U8I(i}Kmt-%DYE*bAQA4=G~#+h$D)zHLx`v-vuzMHg9 zK5Z0iH4%lrB;T6RUJj5JVsuoAbX_nVy(RGIuIuG_aG;nSu?aW_)$o%_f+RonoiBU* zG^e6XIDiNvWX!`-oe~PW2FBM%9TXC$XqF6pz$$5oXnRjgzms5`VK)eE)m+~^;j!BC7c+qNs zT=Ze{;!gN-w{;`W{EI!ejr=IWBgxf&c=g~wv-z{j@}1X5W%`TK^6xSk?@KYcllxJm zllje>$K~xHr2~~I>m&9q0?^;%1}*=1Fv^JZrMKXkiIPPK`a{^zYwDj>2F98jtt( z#o@8wKpYAKK936ARM=sVQC18S=KCBCd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