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

Support for projects in EgressSource #12532

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
371b506
Support for resource in EgressSource
Angelina612 Dec 2, 2024
e4d51a7
Merge branch 'GoogleCloudPlatform:main' into acm-egress-resource
Angelina612 Dec 10, 2024
3e68746
Merge branch 'GoogleCloudPlatform:main' into acm-egress-resource
Angelina612 Dec 11, 2024
53d8e91
Fix lint errors in egressSource resource
Angelina612 Dec 11, 2024
5bf079c
Support for resource in EgressSource
Angelina612 Dec 11, 2024
16a66ee
Support for resource in EgressSource
Angelina612 Dec 11, 2024
aa62ddb
Merge branch 'acm-egress-resource' of https://github.com/Angelina612/…
Angelina612 Dec 12, 2024
5ad22d9
Merge branch 'acm-egress-resource' of https://github.com/Angelina612/…
Angelina612 Dec 12, 2024
fe8d264
Merge branch 'acm-egress-resource' of https://github.com/Angelina612/…
Angelina612 Dec 12, 2024
68bfdb6
Revert "Merge branch 'acm-egress-resource' of https://github.com/Ange…
Angelina612 Dec 12, 2024
74250fc
Merge branch 'GoogleCloudPlatform:main' into acm-egress-resource
Angelina612 Dec 12, 2024
74af8d2
Added acceptance tests for egress resource.
Angelina612 Dec 12, 2024
220c252
Added acceptance tests for egress resource.
Angelina612 Dec 12, 2024
1953d68
Merge branch 'acm-egress-resource' of https://github.com/Angelina612/…
Angelina612 Dec 12, 2024
2410414
Fix go formatting
Angelina612 Dec 12, 2024
b358082
Refactor project number retrieval in access context manager tests
Angelina612 Dec 12, 2024
48b1fcd
Refactor project number retrieval in access context manager tests
Angelina612 Dec 12, 2024
481de3a
Merge branch 'acm-egress-resource' of https://github.com/Angelina612/…
Angelina612 Dec 12, 2024
8fab091
Merge branch 'acm-egress-resource' of https://github.com/Angelina612/…
Angelina612 Dec 12, 2024
6fd3a87
Merge branch 'acm-egress-resource' of https://github.com/Angelina612/…
Angelina612 Dec 12, 2024
0b48155
Merge branch 'GoogleCloudPlatform:main' into acm-egress-resource
Angelina612 Dec 30, 2024
072f071
Merge branch 'GoogleCloudPlatform:main' into acm-egress-resource
Angelina612 Dec 30, 2024
5c1e466
Merge branch 'GoogleCloudPlatform:main' into acm-egress-resource
Angelina612 Jan 6, 2025
dbf5f79
Merge branch 'GoogleCloudPlatform:main' into acm-egress-resource
Angelina612 Jan 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions mmv1/products/accesscontextmanager/ServicePerimeter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,15 @@ properties:
- name: 'accessLevel'
type: String
description: 'An AccessLevel resource name that allows resources outside the ServicePerimeter to be accessed from the inside.'
- name: 'resource'
type: String
description: |
A Google Cloud resource that is allowed to egress the perimeter.
Requests from these resources are allowed to access data outside the perimeter.
Currently only projects are allowed. Project format: `projects/{project_number}`.
The resource may be in any Google Cloud organization, not just the
organization that the perimeter is defined in. `*` is not allowed, the
case of allowing all Google Cloud resources only is not supported.
- name: 'sourceRestriction'
type: Enum
description: 'Whether to enforce traffic restrictions based on `sources` field. If the `sources` field is non-empty, then this field must be set to `SOURCE_RESTRICTION_ENABLED`.'
Expand Down Expand Up @@ -693,6 +702,15 @@ properties:
- name: 'accessLevel'
type: String
description: 'An AccessLevel resource name that allows resources outside the ServicePerimeter to be accessed from the inside.'
- name: 'resource'
type: String
description: |
A Google Cloud resource that is allowed to egress the perimeter.
Requests from these resources are allowed to access data outside the perimeter.
Currently only projects are allowed. Project format: `projects/{project_number}`.
The resource may be in any Google Cloud organization, not just the
organization that the perimeter is defined in. `*` is not allowed, the
case of allowing all Google Cloud resources only is not supported.
- name: 'sourceRestriction'
type: Enum
description: 'Whether to enforce traffic restrictions based on `sources` field. If the `sources` field is non-empty, then this field must be set to `SOURCE_RESTRICTION_ENABLED`.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ properties:
- name: 'accessLevel'
type: String
description: 'An AccessLevel resource name that allows resources outside the ServicePerimeter to be accessed from the inside.'
- name: 'resource'
type: String
description: |
A Google Cloud resource that is allowed to egress the perimeter.
Requests from these resources are allowed to access data outside the perimeter.
Currently only projects are allowed. Project format: `projects/{project_number}`.
The resource may be in any Google Cloud organization, not just the
organization that the perimeter is defined in. `*` is not allowed, the
case of allowing all Google Cloud resources only is not supported.
- name: 'sourceRestriction'
type: Enum
description: 'Whether to enforce traffic restrictions based on `sources` field. If the `sources` field is non-empty, then this field must be set to `SOURCE_RESTRICTION_ENABLED`.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ properties:
- name: 'accessLevel'
type: String
description: 'An AccessLevel resource name that allows resources outside the ServicePerimeter to be accessed from the inside.'
- name: 'resource'
type: String
description: |
A Google Cloud resource that is allowed to egress the perimeter.
Requests from these resources are allowed to access data outside the perimeter.
Currently only projects are allowed. Project format: `projects/{project_number}`.
The resource may be in any Google Cloud organization, not just the
organization that the perimeter is defined in. `*` is not allowed, the
case of allowing all Google Cloud resources only is not supported.
- name: 'sourceRestriction'
type: Enum
description: 'Whether to enforce traffic restrictions based on `sources` field. If the `sources` field is non-empty, then this field must be set to `SOURCE_RESTRICTION_ENABLED`.'
Expand Down
18 changes: 18 additions & 0 deletions mmv1/products/accesscontextmanager/ServicePerimeters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,15 @@ properties:
- name: 'accessLevel'
type: String
description: 'An AccessLevel resource name that allows resources outside the ServicePerimeter to be accessed from the inside.'
- name: 'resource'
type: String
description: |
A Google Cloud resource that is allowed to egress the perimeter.
Requests from these resources are allowed to access data outside the perimeter.
Currently only projects are allowed. Project format: `projects/{project_number}`.
The resource may be in any Google Cloud organization, not just the
organization that the perimeter is defined in. `*` is not allowed, the
case of allowing all Google Cloud resources only is not supported.
- name: 'sourceRestriction'
type: Enum
description: 'Whether to enforce traffic restrictions based on `sources` field. If the `sources` field is non-empty, then this field must be set to `SOURCE_RESTRICTION_ENABLED`.'
Expand Down Expand Up @@ -673,6 +682,15 @@ properties:
- name: 'accessLevel'
type: String
description: 'An AccessLevel resource name that allows resources outside the ServicePerimeter to be accessed from the inside.'
- name: 'resource'
type: String
description: |
A Google Cloud resource that is allowed to egress the perimeter.
Requests from these resources are allowed to access data outside the perimeter.
Currently only projects are allowed. Project format: `projects/{project_number}`.
The resource may be in any Google Cloud organization, not just the
organization that the perimeter is defined in. `*` is not allowed, the
case of allowing all Google Cloud resources only is not supported.
- name: 'sourceRestriction'
type: Enum
description: 'Whether to enforce traffic restrictions based on `sources` field. If the `sources` field is non-empty, then this field must be set to `SOURCE_RESTRICTION_ENABLED`.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ func flattenAccessContextManagerServicePerimetersServicePerimetersStatusEgressPo
}
transformed = append(transformed, map[string]interface{}{
"access_level": flattenAccessContextManagerServicePerimetersServicePerimetersStatusEgressPoliciesEgressFromSourcesAccessLevel(original["accessLevel"], d, config),
"resource": flattenAccessContextManagerServicePerimetersServicePerimetersStatusEgressPoliciesEgressFromSourcesResource(original["resource"], d, config),
})
}
return transformed
Expand All @@ -349,6 +350,10 @@ func flattenAccessContextManagerServicePerimetersServicePerimetersStatusEgressPo
return v
}

func flattenAccessContextManagerServicePerimetersServicePerimetersStatusEgressPoliciesEgressFromSourcesResource(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenAccessContextManagerServicePerimetersServicePerimetersStatusEgressPoliciesEgressFromSourceRestriction(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
Expand Down Expand Up @@ -713,6 +718,7 @@ func flattenAccessContextManagerServicePerimetersServicePerimetersSpecEgressPoli
}
transformed = append(transformed, map[string]interface{}{
"access_level": flattenAccessContextManagerServicePerimetersServicePerimetersSpecEgressPoliciesEgressFromSourcesAccessLevel(original["accessLevel"], d, config),
"resource": flattenAccessContextManagerServicePerimetersServicePerimetersSpecEgressPoliciesEgressFromSourcesResource(original["resource"], d, config),
})
}
return transformed
Expand All @@ -721,6 +727,10 @@ func flattenAccessContextManagerServicePerimetersServicePerimetersSpecEgressPoli
return v
}

func flattenAccessContextManagerServicePerimetersServicePerimetersSpecEgressPoliciesEgressFromSourcesResource(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenAccessContextManagerServicePerimetersServicePerimetersSpecEgressPoliciesEgressFromSourceRestriction(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ func testAccAccessContextManagerServicePerimeterDryRunEgressPolicy_basicTest(t *
//projects := acctest.BootstrapServicePerimeterProjects(t, 1)
policyTitle := acctest.RandString(t, 10)
perimeterTitle := "perimeter"
projectNumber := envvar.GetTestProjectNumberFromEnv()

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
Steps: []resource.TestStep{
{
Config: testAccAccessContextManagerServicePerimeterDryRunEgressPolicy_basic(org, policyTitle, perimeterTitle),
Config: testAccAccessContextManagerServicePerimeterDryRunEgressPolicy_basic(org, policyTitle, perimeterTitle, projectNumber),
},
{
Config: testAccAccessContextManagerServicePerimeterDryRunEgressPolicy_destroy(org, policyTitle, perimeterTitle),
Expand Down Expand Up @@ -83,7 +84,7 @@ func testAccCheckAccessContextManagerServicePerimeterDryRunEgressPolicyDestroyPr
}
}

func testAccAccessContextManagerServicePerimeterDryRunEgressPolicy_basic(org, policyTitle, perimeterTitleName string) string {
func testAccAccessContextManagerServicePerimeterDryRunEgressPolicy_basic(org, policyTitle, perimeterTitleName, projectNumber string) string {
return fmt.Sprintf(`
%s

Expand Down Expand Up @@ -127,7 +128,17 @@ resource "google_access_context_manager_service_perimeter_dry_run_egress_policy"
depends_on = [google_access_context_manager_service_perimeter_dry_run_egress_policy.test-access1]
}

`, testAccAccessContextManagerServicePerimeterDryRunEgressPolicy_destroy(org, policyTitle, perimeterTitleName))
resource "google_access_context_manager_service_perimeter_dry_run_egress_policy" "test-access3" {
perimeter = google_access_context_manager_service_perimeter.test-access.name
egress_from {
sources {
resource = "projects/%s"
}
source_restriction = "SOURCE_RESTRICTION_ENABLED"
}
}

`, testAccAccessContextManagerServicePerimeterDryRunEgressPolicy_destroy(org, policyTitle, perimeterTitleName), projectNumber)
}

func testAccAccessContextManagerServicePerimeterDryRunEgressPolicy_destroy(org, policyTitle, perimeterTitleName string) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ func testAccAccessContextManagerServicePerimeterEgressPolicy_basicTest(t *testin
//projects := acctest.BootstrapServicePerimeterProjects(t, 1)
policyTitle := acctest.RandString(t, 10)
perimeterTitle := "perimeter"
projectNumber := envvar.GetTestProjectNumberFromEnv()

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
Steps: []resource.TestStep{
{
Config: testAccAccessContextManagerServicePerimeterEgressPolicy_basic(org, policyTitle, perimeterTitle),
Config: testAccAccessContextManagerServicePerimeterEgressPolicy_basic(org, policyTitle, perimeterTitle, projectNumber),
},
{
Config: testAccAccessContextManagerServicePerimeterEgressPolicy_destroy(org, policyTitle, perimeterTitle),
Expand Down Expand Up @@ -85,7 +86,7 @@ func testAccCheckAccessContextManagerServicePerimeterEgressPolicyDestroyProducer
}
}

func testAccAccessContextManagerServicePerimeterEgressPolicy_basic(org, policyTitle, perimeterTitleName string) string {
func testAccAccessContextManagerServicePerimeterEgressPolicy_basic(org, policyTitle, perimeterTitleName, projectNumber string) string {
return fmt.Sprintf(`
%s

Expand Down Expand Up @@ -129,7 +130,17 @@ resource "google_access_context_manager_service_perimeter_egress_policy" "test-a
}
}

`, testAccAccessContextManagerServicePerimeterEgressPolicy_destroy(org, policyTitle, perimeterTitleName))
resource "google_access_context_manager_service_perimeter_egress_policy" "test-access3" {
perimeter = google_access_context_manager_service_perimeter.test-access.name
egress_from {
sources {
resource = "projects/%s"
}
source_restriction = "SOURCE_RESTRICTION_ENABLED"
}
}

`, testAccAccessContextManagerServicePerimeterEgressPolicy_destroy(org, policyTitle, perimeterTitleName), projectNumber)
}

func testAccAccessContextManagerServicePerimeterEgressPolicy_destroy(org, policyTitle, perimeterTitleName string) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func testAccAccessContextManagerServicePerimeter_basicTest(t *testing.T) {

func testAccAccessContextManagerServicePerimeter_updateTest(t *testing.T) {
org := envvar.GetTestOrgFromEnv(t)
projectNumber := envvar.GetTestProjectNumberFromEnv()

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
Expand All @@ -61,7 +62,7 @@ func testAccAccessContextManagerServicePerimeter_updateTest(t *testing.T) {
ImportStateVerify: true,
},
{
Config: testAccAccessContextManagerServicePerimeter_updateAllowed(org, "my policy", "level", "perimeter"),
Config: testAccAccessContextManagerServicePerimeter_updateAllowed(org, "my policy", "level", "perimeter", projectNumber),
},
{
ResourceName: "google_access_context_manager_service_perimeter.test-access",
Expand All @@ -77,7 +78,7 @@ func testAccAccessContextManagerServicePerimeter_updateTest(t *testing.T) {
ImportStateVerify: true,
},
{
Config: testAccAccessContextManagerServicePerimeter_updateAllowed(org, "my policy", "level", "perimeter"),
Config: testAccAccessContextManagerServicePerimeter_updateAllowed(org, "my policy", "level", "perimeter", projectNumber),
},
{
ResourceName: "google_access_context_manager_service_perimeter.test-access",
Expand Down Expand Up @@ -182,7 +183,7 @@ resource "google_access_context_manager_service_perimeter" "test-access" {
`, org, policyTitle, levelTitleName, levelTitleName, perimeterTitleName, perimeterTitleName)
}

func testAccAccessContextManagerServicePerimeter_updateAllowed(org, policyTitle, levelTitleName, perimeterTitleName string) string {
func testAccAccessContextManagerServicePerimeter_updateAllowed(org, policyTitle, levelTitleName, perimeterTitleName, projectNumber string) string {
return fmt.Sprintf(`
resource "google_access_context_manager_access_policy" "test-access" {
parent = "organizations/%s"
Expand Down Expand Up @@ -267,6 +268,11 @@ resource "google_access_context_manager_service_perimeter" "test-access" {
sources {
access_level = google_access_context_manager_access_level.test-access.name
}

sources {
resource = "projects/%s"
}

source_restriction = "SOURCE_RESTRICTION_ENABLED"
}
egress_to {
Expand Down Expand Up @@ -347,6 +353,11 @@ resource "google_access_context_manager_service_perimeter" "test-access" {
sources {
access_level = google_access_context_manager_access_level.test-access.name
}

sources {
resource = "projects/%s"
}

source_restriction = "SOURCE_RESTRICTION_ENABLED"
}
egress_to {
Expand All @@ -369,7 +380,7 @@ resource "google_access_context_manager_service_perimeter" "test-access" {
}
}
}
`, org, policyTitle, levelTitleName, levelTitleName, perimeterTitleName, perimeterTitleName)
`, org, policyTitle, levelTitleName, levelTitleName, perimeterTitleName, perimeterTitleName, projectNumber, projectNumber)
}

func testAccAccessContextManagerServicePerimeter_updateDryrun(org, policyTitle, levelTitleName, perimeterTitleName string) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
// can exist, they need to be run serially. See AccessPolicy for the test runner.
func testAccAccessContextManagerServicePerimeters_basicTest(t *testing.T) {
org := envvar.GetTestOrgFromEnv(t)
projectNumber := envvar.GetTestProjectNumberFromEnv()

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
Expand All @@ -32,7 +33,7 @@ func testAccAccessContextManagerServicePerimeters_basicTest(t *testing.T) {
ImportStateVerifyIgnore: []string{"service_perimeters"},
},
{
Config: testAccAccessContextManagerServicePerimeters_update(org, "my policy", "level", "storage_perimeter", "bigquery_perimeter", "bigtable_perimeter", "bigquery_omni_perimeter"),
Config: testAccAccessContextManagerServicePerimeters_update(org, "my policy", "level", "storage_perimeter", "bigquery_perimeter", "bigtable_perimeter", "bigquery_omni_perimeter", projectNumber),
},
{
ResourceName: "google_access_context_manager_service_perimeters.test-access",
Expand Down Expand Up @@ -153,7 +154,7 @@ resource "google_access_context_manager_service_perimeters" "test-access" {
`, org, policyTitle, levelTitleName, levelTitleName, perimeterTitleName1, perimeterTitleName1, perimeterTitleName2, perimeterTitleName2, perimeterTitleName3, perimeterTitleName3)
}

func testAccAccessContextManagerServicePerimeters_update(org, policyTitle, levelTitleName, perimeterTitleName1, perimeterTitleName2, perimeterTitleName3, perimeterTitleName4 string) string {
func testAccAccessContextManagerServicePerimeters_update(org, policyTitle, levelTitleName, perimeterTitleName1, perimeterTitleName2, perimeterTitleName3, perimeterTitleName4, projectNumber string) string {
return fmt.Sprintf(`
resource "google_access_context_manager_access_policy" "test-access" {
parent = "organizations/%s"
Expand Down Expand Up @@ -285,6 +286,14 @@ resource "google_access_context_manager_service_perimeters" "test-access" {
resources = ["*"]
}
}
egress_policies {
egress_from {
sources {
resource = "projects/%s"
}
source_restriction = "SOURCE_RESTRICTION_ENABLED"
}
}
}
status {
restricted_services = ["bigquery.googleapis.com", "storage.googleapis.com"]
Expand Down Expand Up @@ -361,10 +370,18 @@ resource "google_access_context_manager_service_perimeters" "test-access" {
resources = ["*"]
}
}
egress_policies {
egress_from {
sources {
resource = "projects/%s"
}
source_restriction = "SOURCE_RESTRICTION_ENABLED"
}
}
}
}
}
`, org, policyTitle, levelTitleName, levelTitleName, perimeterTitleName1, perimeterTitleName1, perimeterTitleName2, perimeterTitleName2, perimeterTitleName3, perimeterTitleName3, perimeterTitleName4, perimeterTitleName4)
`, org, policyTitle, levelTitleName, levelTitleName, perimeterTitleName1, perimeterTitleName1, perimeterTitleName2, perimeterTitleName2, perimeterTitleName3, perimeterTitleName3, perimeterTitleName4, perimeterTitleName4, projectNumber, projectNumber)
}

func testAccAccessContextManagerServicePerimeters_empty(org, policyTitle, levelTitleName string) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"sources": [
{
"accessLevel": "accessPolicies/987654/accessLevels/restrict_storage"
},
{
"resource": "projects/4321"
}
]
}
Expand Down
Loading
Loading