-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
adding security policy field to instance #8878
adding security policy field to instance #8878
Conversation
Hello! I am a robot. It looks like you are a: Community Contributor @roaks3, a repository maintainer, has been assigned to review your changes. If you have not received review feedback within 2 business days, please leave a comment on this PR asking them to take a look. You can help make sure that review is quick by doing a self-review and by running impacted tests locally. |
@roaks3 Would you mind helping me out with something here please? The api(https://cloud.google.com/compute/docs/reference/rest/beta/instances/setSecurityPolicy) states that "You can only set a security policy for network interfaces with an access config" and expects something like this:
But the "security_policy" is actually only retrieved inside of the access_configs inside the networkInterface. This field is read_only and the networkInterface might have two access_config: one for ipv4 and another one for ipv6. 1- Setting the security_policy inside the access_config and somehow make sure the user will be setting exactly the same resource "google_compute_instance" "target-vm" {
name = "felipegc-tf-vm"
machine_type = "e2-medium"
zone = "asia-southeast1-a"
desired_status = "RUNNING"
boot_disk {
initialize_params {
image = data.google_compute_image.vmimage.self_link
}
}
network_interface {
network = google_compute_network.net2.self_link
subnetwork = google_compute_subnetwork.subnetipv6.self_link
stack_type = "IPV4_IPV6"
ipv6_access_config {
external_ipv6 = google_compute_address.ipv6-address.address
external_ipv6_prefix_length = 96
name = "external-ipv6-access-config"
network_tier = "PREMIUM"
security_policy = google_compute_region_security_policy.policyforinstance.self_link
}
access_config {
network_tier = "PREMIUM"
nat_ip = google_compute_address.foo.address
security_policy = google_compute_region_security_policy.policyforinstance.self_link
}
}
} 2- Create the "security_policy" field inside the "network_attachment" as a "virtual_field" since it does not exist inside the api/proto and let the "security_policy" inside both access_config as read only? For this option I will check if there is one access_config and take the value from the first one I find to set the value while "flattening" the network_attachment for read operations. For update I will just need to check if there is one access_config. resource "google_compute_instance" "target-vm" {
name = "felipegc-tf-vm"
machine_type = "e2-medium"
zone = "asia-southeast1-a"
desired_status = "RUNNING"
boot_disk {
initialize_params {
image = data.google_compute_image.vmimage.self_link
}
}
network_interface {
network = google_compute_network.net2.self_link
subnetwork = google_compute_subnetwork.subnetipv6.self_link
stack_type = "IPV4_IPV6"
ipv6_access_config {
external_ipv6 = google_compute_address.ipv6-address.address
external_ipv6_prefix_length = 96
name = "external-ipv6-access-config"
network_tier = "PREMIUM"
}
access_config {
network_tier = "PREMIUM"
nat_ip = google_compute_address.foo.address
}
security_policy = google_compute_region_security_policy.policyforinstance2.self_link
}
} |
@felipegc I agree with your point about the second option being easier for the user, but I think this could get complicated if we stray too far from the API behavior. Can there be separate security policies, one for |
The api does not prevent anything. It basically applies the security policy to the whole network interface. If the network interface has 2 access config(one for ipv4 and another one for ipv6) it will apply for both of them. The security_field is read only inside the access_config, which means if we set the security_policy, all access_configs inside the network_interface will have the same value. Actually I believe the second option follows the api more than the first one. |
To clarify: does the API support a different security_policy in each *access_config, or does it force all *access_config to use the same security_policy? |
It force all access_config to use the same security_policy. |
Ok thanks! My personal read here is that your Option 2 is more intuitive, and perhaps the API should have been modeled that way, but I think Option 1 more closely matches where the API is today. Particularly, it seems that the API considers the I would recommend proceeding with Option 1 here, but I'll consult with the team in case there are existing patterns I'm unaware of. Thanks for taking the time to consider the best solution here. |
Agreed. I proceeded with solution one and all tests I created are passing. Thanks for the help |
Ok, so I've got an update after speaking with the team. Here's the way we'd like to move forward:
We believe this strategy will be closest to the API, and prevent difficulties in keeping all fields in sync (for example, if I did look through your current implementation, which looks good. I think you would just need to tweak it a bit to achieve the desired model. |
I will also be on PTO coming up, so re-rolling the reviewer |
Hi there, I'm the Modular magician. I've detected the following information about your changes: Diff reportYour PR generated some diffs in downstreams - here they are. Terraform GA: Diff ( 2 files changed, 5 insertions(+)) Missing test reportYour PR includes resource fields which are not covered by any test. Resource: resource "google_compute_instance_from_machine_image" "primary" {
network_interface {
access_config {
security_policy = # value needed
}
ipv6_access_config {
security_policy = # value needed
}
}
}
Resource: resource "google_compute_instance_from_template" "primary" {
network_interface {
access_config {
security_policy = # value needed
}
ipv6_access_config {
security_policy = # value needed
}
}
}
|
|
mmv1/third_party/terraform/services/compute/compute_instance_network_interface_helpers.go.erb
Outdated
Show resolved
Hide resolved
mmv1/third_party/terraform/services/compute/resource_compute_instance_test.go.erb
Outdated
Show resolved
Hide resolved
mmv1/third_party/terraform/services/compute/resource_compute_instance_test.go.erb
Outdated
Show resolved
Hide resolved
mmv1/third_party/terraform/services/compute/resource_compute_instance.go.erb
Show resolved
Hide resolved
mmv1/third_party/terraform/services/compute/resource_compute_instance.go.erb
Show resolved
Hide resolved
Hi there, I'm the Modular magician. I've detected the following information about your changes: Diff reportYour PR generated some diffs in downstreams - here they are. Terraform GA: Diff ( 2 files changed, 2 insertions(+)) Missing test reportYour PR includes resource fields which are not covered by any test. Resource: resource "google_compute_instance_from_machine_image" "primary" {
network_interface {
security_policy = # value needed
}
}
Resource: resource "google_compute_instance_from_template" "primary" {
network_interface {
security_policy = # value needed
}
}
|
Tests analyticsTotal tests: Action takenFound 5 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected testsTestAccBigQueryDataTable_bigtable|TestAccBigtableAppProfile_bigtableAppProfileSingleclusterExample|TestAccBigtableAppProfile_bigtableAppProfileMulticlusterExample|TestAccBigtableAppProfile_bigtableAppProfileAnyclusterExample|TestAccHealthcareDatasetIamPolicy |
Rerun these tests in REPLAYING mode to catch issues
|
Hi @zli82016 are these failures related to my code? |
They are not. Sorry, can you please resolve the conflicts? Thanks. |
…-policy-in-instance
mmv1/third_party/terraform/services/compute/compute_instance_helpers.go.erb
Outdated
Show resolved
Hide resolved
mmv1/third_party/terraform/services/compute/compute_instance_helpers.go.erb
Outdated
Show resolved
Hide resolved
mmv1/third_party/terraform/services/compute/resource_compute_instance_test.go.erb
Show resolved
Hide resolved
Hi there, I'm the Modular magician. I've detected the following information about your changes: Diff reportYour PR generated some diffs in downstreams - here they are. Terraform GA: Diff ( 2 files changed, 2 insertions(+)) Missing test reportYour PR includes resource fields which are not covered by any test. Resource: resource "google_compute_instance_from_machine_image" "primary" {
network_interface {
security_policy = # value needed
}
}
Resource: resource "google_compute_instance_from_template" "primary" {
network_interface {
security_policy = # value needed
}
}
|
Tests analyticsTotal tests: Action takenFound 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected testsTestAccComputeInstanceNetworkIntefaceWithSecurityPolicy |
Rerun these tests in REPLAYING mode to catch issues
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks.
* adding security policy field to networkInterfaceAccessConfig * adding security policy to networkInterface instead of networkInterfaceAccessConfig * finishing solution 1 and adding integration tests and doc * cleanups for solution 1 * wrapping update security policy for beta * replacing the networks in tests * fixing code review by implementing the solution two * replacing networks in tests * fixing nic read for instance_template resource * adding checking for access config security policy while flattening to prevent the instance template to break * fixing error while creating instance with empty security_policy * changing region for tests which use network_edge_security_service * comment all failing tests but one to test if it runs alone * making the tests running serially * fixing the tests to be called only by the serial one * fixing code review comments * fixing missing compute_image data from merge * fixing code review
Fixes: hashicorp/terraform-provider-google#15719
If this PR is for Terraform, I acknowledge that I have:
make test
andmake lint
in the generated providers to ensure it passes unit and linter tests.Release Note Template for Downstream PRs (will be copied)