Can't change instance network using terraform in gcp - terraform-provider-gcp

I have a couple of unmanaged compute instances belonging to an instance group. I created them using terraform and when I tried to modify the instances networks (put them into another vpc) I got this error:
Error: Error updating network interface: googleapi: Error 400: The instance resource 'projects/my-varan-project/zones/europe-west1-b/instances/test-vm-1' is already being used by 'projects/my-varan-project/zones/europe-west1-b/instanceGroups/test-ig-1', resourceInUseByAnotherResource
Any thoughts?

Related

Error: 400-RelatedResourceNotAuthorizedOrNotFound, Unable to create integration instance in Oracle Cloud

I'm trying to create OIC instance using terraform and for idcs_at variable I have passed the IDCS Access token which has Identity Domain Administrators Access, and I'm the administrator of OCI account, but getting attached error.

terraform apply fails while creating a resource that exists already

I am working on terraform with openstack as the cloud provider. I have a deploy.tf script that creates a role:
resource "openstack_identity_role_v3" "role_example" {
name = "creator"
}
My finding on how terraform creates resources:
If the role does not exist in openstack, terraform creates one with
no problem.
If the role exists in openstack and is created with the
same terraform script, ie. terraform.state has an entry of it,
terraform returns with no errors.
my issue is: if I remove the state file or if the role is created out of bands either manually or by some other terraform script.I get the following error:
* openstack_identity_role_v3.role_example: Error creating OpenStack role: Expected HTTP response code [201] when accessing [POST https://<example-openstack-url>/v3/roles], but got 409 instead
{"error": {"message": "Conflict occurred attempting to store role - Duplicate Entry", "code": 409, "title": "Conflict"}}
I am trying to find a workaround so that if the role doesn't exist, terraform apply creates it, and if it already exists, despite having created manually or by any other terraform deployment script, terraform skips its creation and throw no error.

Cyclic dependency between Packer and Terraform for non-default VPC

My deployment workflow is first creating ami with Packer, then deploy using Terraform.
I have a EC2-class, which was created before 2013, so there's no default VPC configured.
When I run packer build packer.json, the tool complains that
amazon-ebs: Adding tag: "Name": "Packer Builder"
==> amazon-ebs: Error launching source instance: VPCResourceNotSpecified: The specified instance type can only be used in a VPC. A subnet ID or network interface ID is required to carry out the request.
==> amazon-ebs: status code: 400, request id: 35ca5736-f808-4bb9-9a34-3dca24b59259
I was planning to create VPC with Terraform. So the question is, what is the order of execution? Run Terraform first, then Packer. Or run in reverse order? Or, we split out the network configuration (VPC), use Terraform to deploy it once, then followed by Packer, and then terraform the rest of the servers?
Update:
If I use the strategy:
run Network module (mostly static things), followed by Packer, and then run "Frequently changing things" module, how do I share state between Terraform and Packer? Meaning, once I created a new VPC, how do I let Packer know about this new vpc_id? Do I need to modify every Packer file?
The general advice is to split the terraform configuration into reasonable sized parts.
For a small setup it's reasonable is to split it into mostly static things (VPC, subnet, routes, etc). Frequently changing things (EC2, SG, etc). This would also solve your dependency cycle.

Terraform google 'compute.subnetworks.use' permission issue

I am trying to create an instance inside Google cloud using terraform and continue to run into a 'compute.subnetworks.use' permission error whenever I apply. The segement of code in question is below:
network_interface {
subnetwork_project = "hp-cof-st-core-sbx-dev"
subnetwork = "net-cof-st-core-sbx-dev-entfacing-ue4-1"
}
I want to create an instance using a subnet through "the network shared with me setting". An example of how the it is configured through the portal is given below:
Configuration within the google portal 1
Whenever I attempt to configure this within terraform i am given the following message:
Error: Error applying plan:
1 error(s) occurred:
google_compute_instance.default: 1 error(s) occurred:
google_compute_instance.default: Error creating instance: googleapi: Error 403: Required 'compute.subnetworks.use' permission for 'projects/hp-cof-st-core-sbx-dev/regions/us-east4-a/subnetworks/net-cof-st-core-sbx-dev-entfacing-ue4-1', forbidden
The service account you are using to create the instance must have the editor or admin role to create an instance. You can update this by going to the IAM and Admin menu and changing the role to Editor or Admin.

When provisioning the AWS instance with the help of Terraform is giving me an error when I use community AMI id

I am getting this error when I provision the same "Error launching source instance: UnsupportedOperation: The instance configuration for this AWS Marketplace product is not supported."
Any idea?
This is resolved by increasing the instance type to large type.

Resources