Skip to content

Instantly share code, notes, and snippets.

@bizmate
Last active September 15, 2017 09:21
Show Gist options
  • Save bizmate/9bdf7de4a00ef2339807ec1ba2cc075d to your computer and use it in GitHub Desktop.
Save bizmate/9bdf7de4a00ef2339807ec1ba2cc075d to your computer and use it in GitHub Desktop.
Terraform issues
TF_LOG=trace && terraform destroy -force -target=aws_instance.pivot_gocd_agent
aws_vpc.vpc_pivot_dev: Refreshing state... (ID: vpc-4ab68733)
aws_key_pair.auth: Refreshing state... (ID: terraform-diego)
aws_subnet.subnet_pivot_dev: Refreshing state... (ID: subnet-e9c91e8d)
aws_security_group.pivot_dev: Refreshing state... (ID: sg-14f7a364)
aws_instance.pivot_gocd_agent: Refreshing state... (ID: i-0c7e6381e1247acec)
aws_eip_association.eip_assoc: Destroying... (ID: eipassoc-c4186cf0)
Error applying plan:
1 error(s) occurred:
* aws_eip_association.eip_assoc (destroy): 1 error(s) occurred:
* aws_eip_association.eip_assoc: Error deleting Elastic IP association: InvalidAssociationID.NotFound: The association ID 'eipassoc-c4186cf0' does not exist
status code: 400, request id: bd68f61b-c8df-4781-a756-35449101af92
Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
provider "aws" {
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret}"
region = "${var.region}"
}
# Create a VPC to launch our instances into
resource "aws_vpc" "vpc_pivot_dev" {
tags {
Name = "Pivot VPC"
}
cidr_block = "10.0.0.0/16"
}
# Create an internet gateway to give our subnet access to the outside world
resource "aws_internet_gateway" "gateway_pivot_dev" {
tags {
Name = "Pivot Gateway"
}
vpc_id = "${aws_vpc.vpc_pivot_dev.id}"
}
# Grant the VPC internet access on its main route table
resource "aws_route" "internet_access" {
route_table_id = "${aws_vpc.vpc_pivot_dev.main_route_table_id}"
destination_cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.gateway_pivot_dev.id}"
}
# Create a subnet to launch our instances into
resource "aws_subnet" "subnet_pivot_dev" {
vpc_id = "${aws_vpc.vpc_pivot_dev.id}"
cidr_block = "10.0.1.0/24"
map_public_ip_on_launch = true
}
resource "aws_key_pair" "auth" {
key_name = "${var.key_name}"
public_key = "${file(var.public_key_path)}"
}
# Our default security group to access
# the instances over SSH and HTTP
resource "aws_security_group" "pivot_dev" {
name = "terraform pivot dev"
description = "Used in the terraform"
vpc_id = "${aws_vpc.vpc_pivot_dev.id}"
# SSH access from anywhere
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# HTTP access from anywhere
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# outbound internet access
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_network_interface" "pivot_agent_network_interface" {
subnet_id = "${aws_subnet.subnet_pivot_dev.id}"
private_ips = ["10.0.1.10"]
}
resource "aws_eip" "pivot_agent_public_ip" {
#id = "eipalloc-57b6b864"
vpc = true
network_interface = "${aws_network_interface.pivot_agent_network_interface.id}"
associate_with_private_ip = "10.0.1.10"
# associate_with_private_ip = "${element(aws_instance.pivot_gocd_agent.*.private_ip, count.index)}" # "10.0.1.10"
lifecycle {
prevent_destroy = true
}
}
resource "aws_eip_association" "eip_assoc" {
instance_id = "${aws_instance.pivot_gocd_agent.id}"
allocation_id = "${aws_eip.pivot_agent_public_ip.id}"
}
resource "aws_instance" "pivot_gocd_agent" {
# ami = "ami-cb4b94dd" # debian jessie 8
ami = "ami-1d4e7a66" # ubuntu 16.04 lts hvm:ebs-ssd
instance_type = "t2.medium"
tags {
Name = "GoCD Agent for Pivot"
}
# The name of our SSH keypair we created above.
# key_name = "${aws_key_pair.auth.id}"
key_name = "${aws_key_pair.auth.key_name}"
# Our Security group to allow HTTP and SSH access
vpc_security_group_ids = ["${aws_security_group.pivot_dev.id}"]
# We're going to launch into the same subnet as our ELB. In a production
# environment it's more common to have a separate private subnet for
# backend instances.
subnet_id = "${aws_subnet.subnet_pivot_dev.id}"
#private_ip = "10.0.1.10"
connection {
# The default username for our AMI
user = "ubuntu"
# type = "ssh"
# private_key = "${file("/Users/bizmate/.ssh/id_rsa.pem")}"
# The connection will use the local SSH agent for authentication.
}
provisioner "remote-exec" {
scripts = [
"./bin/provision.sh"
]
}
provisioner "file" {
source = "config/gocd_agent.conf"
destination = "/tmp/gocd_agent.conf"
}
provisioner "file" {
source = "config/autoregister.properties"
destination = "/tmp/autoregister.properties"
}
# /var/lib/go-agent/config
# /etc/default/go-agent
provisioner "remote-exec" {
scripts = [
"./bin/start.sh"
]
}
lifecycle {
create_before_destroy = "true"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment