Managing Applications and Infrastructure with Terraform-Deploying Infrastructure with Terraform-(2)Terraform for AWS-(14)Outputs and the Join Function

2018年10月04日


Managing Applications and Infrastructure with Terraform-Deploying Infrastructure with Terraform
2. Terraform for AWS
14. Outputs and the Join Function

Edit the outputs.tf file.

#---root/outputs.tf
 
 
#---storage outputs
 
output "Bucket_Name" {
    value = module.storage.bucketname
}
 
#---Networking Outputs
 
output "Public_Subnets" {
    value = join(", ", module.networking.public_subnets)
}
 
output "Subnet_IPs" {
    value = join(", ", module.networking.subnet_ips)
}
 
output "Public_Security_Group" {
    value = module.networking.public_sg
}
 
#---Compute Outputs
 
output "Public_Instance_IDs" {
    value = module.compute.server_id
}
 
output "Public_Instance_IPs" {
    value = module.compute.server_ip
}

Edit the compute/outputs.tf file.
#---compute/outputs.tf

output "server_id" {
    value = join(", ", aws_instance.tf_server.*.id)
}

output "server_ip" {
    value = join(", ", aws_instance.tf_server.*.public_ip)
}

ec2-user:~/environment/AWS $ terraform show | grep public_ip
    associate_public_ip_address  = true
    public_ip                    = "18.236.130.232"
    associate_public_ip_address  = true
    public_ip                    = "54.184.238.83"
    map_public_ip_on_launch         = true
    map_public_ip_on_launch         = true

ec2-user:~/environment/AWS $ terraform apply
module.storage.random_id.tf_bucket_id: Refreshing state... [id=4xI]
module.compute.data.aws_ami.server_ami: Refreshing state... [id=ami-01fee56b22f308154]
module.networking.data.aws_availability_zones.available: Refreshing state... [id=2020-10-10 01:20:18.106671746 +0000 UTC]
module.storage.aws_s3_bucket.tf_code: Refreshing state... [id=la-terrafrom-58130]
module.networking.aws_vpc.tf_vpc: Refreshing state... [id=vpc-0c0f2da28642867e2]
module.compute.aws_key_pair.tf_auth: Refreshing state... [id=tf_key]
module.networking.aws_internet_gateway.tf_internet_gateway: Refreshing state... [id=igw-0818bad4ef2e5e206]
module.networking.aws_subnet.tf_public_subnet[1]: Refreshing state... [id=subnet-0e8c8b7fbe145ccd4]
module.networking.aws_default_route_table.tf_private_rt: Refreshing state... [id=rtb-0566a0d7669788905]
module.networking.aws_subnet.tf_public_subnet[0]: Refreshing state... [id=subnet-0c77cbd47f0f92385]
module.networking.aws_security_group.tf_public_sg: Refreshing state... [id=sg-08b6452d00a14dc79]
module.networking.aws_route_table.tf_public_rt: Refreshing state... [id=rtb-0ee0f448101c559a6]
module.compute.data.template_file.user-init[0]: Refreshing state... [id=57df141e108f0b6cf1703691b1a5a736ca3a01b0eb84e07196d778d405c36d19]
module.compute.data.template_file.user-init[1]: Refreshing state... [id=757bacc9f6377916bf38eff5b6acdb9ae2756c56859b9c203d8de26eff4865d4]
module.networking.aws_route_table_association.tf_public_assoc[1]: Refreshing state... [id=rtbassoc-0f08e4f20a29c75dc]
module.networking.aws_route_table_association.tf_public_assoc[0]: Refreshing state... [id=rtbassoc-069833977e56c8e1f]
module.compute.aws_instance.tf_server[1]: Refreshing state... [id=i-08364976098583f3b]
module.compute.aws_instance.tf_server[0]: Refreshing state... [id=i-043f7e57528e1a6a3]

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:

Terraform will perform the following actions:

Plan: 0 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + Public_Instance_IDs   = "i-043f7e57528e1a6a3, i-08364976098583f3b"
  + Public_Instance_IPs   = "18.236.130.232, 54.184.238.83"
  + Public_Security_Group = "sg-08b6452d00a14dc79"
  + Public_Subnets        = "subnet-0c77cbd47f0f92385, subnet-0e8c8b7fbe145ccd4"
  + Subnet_IPs            = "10.123.1.0/24, 10.123.2.0/24"

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes


Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

Bucket_Name = la-terrafrom-58130
Public_Instance_IDs = i-043f7e57528e1a6a3, i-08364976098583f3b
Public_Instance_IPs = 18.236.130.232, 54.184.238.83
Public_Security_Group = sg-08b6452d00a14dc79
Public_Subnets = subnet-0c77cbd47f0f92385, subnet-0e8c8b7fbe145ccd4
Subnet_IPs = 10.123.1.0/24, 10.123.2.0/24



Category: orchestration Tags: public

Upvote


Downvote