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 f0600ee..0000000 Binary files a/tfplan and /dev/null differ