Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scaleway_instance_private_nic : resource (instance) server not found #1151

Closed
tisc0 opened this issue Mar 24, 2022 · 5 comments · Fixed by #1328
Closed

scaleway_instance_private_nic : resource (instance) server not found #1151

tisc0 opened this issue Mar 24, 2022 · 5 comments · Fixed by #1328
Assignees
Labels
bug instance Instance issues, bugs and feature requests vpc Virtual Private Cloud (VPC) issues, bugs and feature requests
Milestone

Comments

@tisc0
Copy link

tisc0 commented Mar 24, 2022

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

Terraform v1.1.7 on linux_amd64

  • provider registry.terraform.io/hashicorp/kubernetes v2.1.0
  • provider registry.terraform.io/hashicorp/random v3.1.2
  • provider registry.terraform.io/scaleway/scaleway v2.2.0

Affected Resource(s)

scaleway_instance_private_nic

Terraform Configuration Files

resource "scaleway_vpc_public_gateway_ip" "gw-runners" {
    reverse = "example.com"
    tags = ["demo", "terraform"]
    zone = "fr-par-2"
}

resource "scaleway_vpc_private_network" "vpc-runners" {
  name = "vpc_runners"
  zone = "fr-par-2"
}


resource "scaleway_vpc_public_gateway" "gw-runners" {
    name = "public_gateway_runners"
    type = "VPC-GW-M"
    tags = ["runners", "terraform"]
    zone = "fr-par-2"
    ip_id = scaleway_vpc_public_gateway_ip.gw-runners.id
}

resource "scaleway_vpc_public_gateway_dhcp" "dhcp-runners" {
  subnet = "192.168.xx.0/24"
  zone = "fr-par-2"
  depends_on = [scaleway_vpc_public_gateway.gw-runners]
}

resource "scaleway_vpc_gateway_network" "main" {
  gateway_id = scaleway_vpc_public_gateway.gw-runners.id
  private_network_id = scaleway_vpc_private_network.vpc-runners.id
  dhcp_id = scaleway_vpc_public_gateway_dhcp.dhcp-runners.id
  zone = "fr-par-2"
}

resource "scaleway_instance_server" "this" {
  name  = "gitlab-runner"
  type  = var.instance_type
  image = var.image
  zone = "fr-par-2"
  tags = concat(var.tags, ["gitlab-runner"])

  root_volume {
    size_in_gb = var.size_dd_in_gb
  }
}

resource "scaleway_instance_private_nic" "pnic01" {
    server_id                = scaleway_instance_server.this.id
    private_network_id = scaleway_vpc_private_network.vpc-runners.id
}

resource "scaleway_vpc_public_gateway_pat_rule" "runner" {
  gateway_id = scaleway_vpc_public_gateway.gw-runners.id
  #private_ip = scaleway_vpc_public_gateway_dhcp.dhcp-runners.address
  private_ip = scaleway_instance_private_nic.pnic01.mac_address            #NOT SURE WHAT TO USE HERE ACTUALLY
  private_port = 22xx
  public_port = 22
  protocol = "both"
  zone = "fr-par-2"
  depends_on = [scaleway_vpc_gateway_network.main, scaleway_vpc_private_network.vpc-runners]
}

Debug Output

https://gist.github.com/tisc0/027c247c76b1fda68c0a4725db13a44a

=> the instance with the ID in this log is properly created.

Expected Behavior

The instance should be found, and the private nic added to the instance.

Actual Behavior

The instance is not found.

Steps to Reproduce

  1. terraform apply

References

Realized I did follow the same advice given here #1040 but without success

Thanks for helping !

@tisc0 tisc0 changed the title scaleway_instance_private_nic.pnic01 resource server not found scaleway_instance_private_nic : resource (instance) server not found Mar 24, 2022
@tisc0
Copy link
Author

tisc0 commented Mar 24, 2022

Seems to work on fr-par-1.
Still wondering what should be the private_ip for scaleway_vpc_public_gateway_pat_rule, though.

@remyleone
Copy link
Member

Hello, could you try with the private network syntax: https://registry.terraform.io/providers/scaleway/scaleway/latest/docs/resources/instance_server#with-private-network. We want to deprecate NIC as it is an implementation detail and focus on the private network abstraction.

@tisc0
Copy link
Author

tisc0 commented Mar 28, 2022

Hi @remyleone , and thanks for your answer.
As I said, it works on paris1, seems to be a problem with paris2 DC.
But I switched like you proposed, and it works too.

From there, though, I still can't figure out how to find the private IP that have been given by the Gateway DHCP, to pass on scaleway_vpc_public_gateway_pat_rule:

resource "scaleway_instance_server" "this" {
  name  = "gitlab-runner"
  type  = var.instance_type
  image = var.image
  zone = "fr-par-1"
  tags = concat(var.tags, ["gitlab-runner"])

  root_volume {
    size_in_gb = var.size_dd_in_gb
  }

  private_network {
    pn_id = scaleway_vpc_private_network.vpc-runners.id
  }

  security_group_id = scaleway_instance_security_group.this.id
}

output "instance_ip_addr" {
  value = data.scaleway_instance_server.this.private_ip
}

resource "scaleway_vpc_public_gateway_pat_rule" "runner" {
  gateway_id = scaleway_vpc_public_gateway.gw-runners.id
  #private_ip = scaleway_vpc_public_gateway_dhcp.dhcp-runners.address
  #private_ip = scaleway_instance_private_nic.pnic01
  #private_ip = data.scaleway_instance_ip.instance_ip.address
  private_ip = data.instance_ip_addr.value
  private_port = 2223
  public_port = 22
  protocol = "both"
  zone = "fr-par-1"
  depends_on = [scaleway_vpc_gateway_network.main, scaleway_vpc_private_network.vpc-runners]
}

With error output:

│ Error: Reference to undeclared resource
│ 
│   on main.tf line 82, in output "instance_ip_addr":82:   value = data.scaleway_instance_server.this.private_ip
│ 
│ A data resource "scaleway_instance_server" "this" has not been declared in
│ the root module.
╵
╷
│ Error: Reference to undeclared resource
│ 
│   on main.tf line 90, in resource "scaleway_vpc_public_gateway_pat_rule" "runner":90:   private_ip = data.instance_ip_addr.value
│ 
│ A data resource "instance_ip_addr" "value" has not been declared in the
│ root module.
╵
ERRO[0001] 1 error occurred:
        * exit status 1

Either I do something dumb... but anyway, thanks for help :)

@remyleone remyleone added bug instance Instance issues, bugs and feature requests labels Apr 15, 2022
@remyleone remyleone added the vpc Virtual Private Cloud (VPC) issues, bugs and feature requests label May 10, 2022
@remyleone remyleone added this to the v2.3.0 milestone May 10, 2022
@Monitob
Copy link
Contributor

Monitob commented May 10, 2022

Hello @tisc0, You use explicitly not declare scaleway_vpc_public_gateway_dhcp_reservation in order to keep fully automated DHCP attribution.

### IP for Public Gateway
resource "scaleway_vpc_public_gateway_ip" "main" {
}

### The Public Gateway with the Attached IP
resource "scaleway_vpc_public_gateway" "main" {
	name  = "tf-test-public-gw"
	type  = "VPC-GW-S"
	ip_id = scaleway_vpc_public_gateway_ip.main.id
}

### Scaleway Private Network
resource "scaleway_vpc_private_network" "pn" {
	name = "private network with a DHCP config"
}

### DHCP Space of VPC
resource "scaleway_vpc_public_gateway_dhcp" "main" {
	subnet = "10.0.0.0/24"
}

### VPC Gateway Network
resource "scaleway_vpc_gateway_network" "main" {
	gateway_id         = scaleway_vpc_public_gateway.main.id
	private_network_id = scaleway_vpc_private_network.pn.id
	dhcp_id            = scaleway_vpc_public_gateway_dhcp.main.id
	cleanup_dhcp       = true
	enable_masquerade  = true
}

### Scaleway Instance
resource "scaleway_instance_server" "main" {
	name        = "Scaleway Terraform Provider"
	type        = "DEV1-S"
	image       = "debian_bullseye"
	enable_ipv6 = false

	private_network {
		pn_id = scaleway_vpc_private_network.pn.id
	}
}

You can check your entries with scw vpc-gw dhcp-entry list

Also you want use the type static with this

resource "scaleway_vpc_public_gateway_dhcp_reservation" "main" {
	gateway_network_id = scaleway_vpc_gateway_network.main.id
	mac_address        = scaleway_instance_server.main.private_network.0.mac_address
	ip_address         = "10.0.0.3" 
}

You use our data source scaleway_vpc_public_gateway_pat_rule to get information from this last but
I notice also that we can not list the dynamic dhcp-entries on our provider. I've just created an issue for this #1268

Let me know if it is more clear for you. I will as for more documentation about this also.

@yfodil
Copy link
Contributor

yfodil commented Jun 20, 2022

Hello @tisc0, regarding the error you encountered with the "scaleway_instance_private_nic" resource, when creating it, only the server_id and private_network_id arguments were entered, what was missing here was the "zone" argument which allows you to specify the availability zone of the resource. By default, if no zone argument is entered, the availability zone of fr-par-1 is assigned, hence the error, the following fixes it:

resource "scaleway_instance_private_nic" "pnic01" {
server_id = scaleway_instance_server.this.id
private_network_id = scaleway_vpc_private_network.vpc-runners.id
zone = "fr-par-2"
}

The resource documentation omitted to mention the need for the zone argument, it's fixed now. Feel free to comment and reopen the issue if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug instance Instance issues, bugs and feature requests vpc Virtual Private Cloud (VPC) issues, bugs and feature requests
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants