github.com/swisspost/terratest@v0.0.0-20230214120104-7ec6de2e1ae0/examples/terraform-aws-ec2-windows-example/README.md (about)

     1  # Windows Instance Example
     2  
     3  This folder provides a Packer template that can be used to build an Amazon Machine Image (AMI) of a Windows 2016 Server that comes pre-installed with: 
     4  
     5  - The [Chocolately package manager](https://chocolatey.org/why-chocolatey) which makes it easy to install additional software packages onto Windows
     6  - Git
     7  - Python 3
     8  
     9  In addition, this folder provides an example of how to launch a Windows instance based off this AMI that can be connected to via a Remote Desktop Protocol (RDP) client for the purposes of testing software or experimentation. 
    10  
    11  This setup is ideal for "hot-reloading" code that you're actively developing and testing it against the Windows server. You can develop your code in your usual environment, perhaps a Mac or Linux laptop, yet see your changes reflected on the Windows server in seconds, by sharing a folder from your development machine with the Windows server via the RDP client. 
    12  
    13  ## Quick start 
    14  
    15  Pre-requistes: 
    16  
    17  - [Packer version v1.8.1 or newer](https://github.com/hashicorp/packer)
    18  - [Terraform v1.0 or newer](https://github.com/hashicorp/terraform)
    19  - An AWS account with valid security credentials
    20  
    21  First, we'll build the AMI for the Windows Instance. Change into the packer directory: 
    22  
    23  `cd packer` 
    24  
    25  In order to build an Amazon Machine Image with Packer, you'll need to export your AWS account credentials. You can export your AWS credentials as the environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. 
    26  
    27  For more information on authenticating to your AWS account from the command line, see our blog post [Authenticating to AWS with Environment Variables](https://blog.gruntwork.io/authenticating-to-aws-with-environment-variables-e793d6f6d02e).
    28  
    29  With your credentials properly exported, you can now run the packer build: 
    30  
    31  `packer build build.pkr.hcl`
    32  
    33  This may take upwards of 25 minutes to complete, but generally completes in about 5 minutes. Keep an eye on your EC2 dashboard and ensure that you have selected the correct region and that you are on the AMI view. Once your AMI status has changed from "Pending" to "Available", you can copy your AMI ID. 
    34  
    35  Create a new file named `terraform.tfvars` in this same directory and enter the following variables: 
    36  
    37  ```hcl
    38  ami_id           = "<the AMI ID you copied in the previous step>"
    39  region           = "us-east-1"
    40  root_volume_size = 100
    41  ```
    42  Save the file. 
    43  
    44  You're now ready to run terraform plan and check the output before proceeding: 
    45  
    46  `terraform plan`
    47  
    48  Take a look at the plan output and ensure everything looks correct. You should see a single EC2 instance being created along with supporting resources such as a security group and security group rules. 
    49  
    50  Once you're satisfied that the plan looks good, run terraform apply to create the infrastructure: 
    51  
    52  `terraform apply --auto-approve`
    53  
    54  Once your resources apply successfully you'll see a similar output message containing the public IPv4 address of your Windows instance: 
    55  
    56  `instance_ip = "35.84.139.82"`
    57