Skip to content

Commit

Permalink
add datasources for all generated iam_resources (#7936) (#14662)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
Co-authored-by: Shuya Ma <87669292+shuyama1@users.noreply.github.com>
  • Loading branch information
modular-magician and shuyama1 committed May 19, 2023
1 parent ab08068 commit bbcd741
Show file tree
Hide file tree
Showing 240 changed files with 5,802 additions and 158 deletions.
3 changes: 3 additions & 0 deletions .changelog/7936.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note: new-datasource
`google_**_iam_policy`
```
62 changes: 62 additions & 0 deletions google/datasource_iam_policy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package google

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"fmt"

transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
)

var IamPolicyBaseDataSourceSchema = map[string]*schema.Schema{
"policy_data": {
Type: schema.TypeString,
Computed: true,
},
"etag": {
Type: schema.TypeString,
Computed: true,
},
}

func DataSourceIamPolicy(parentSpecificSchema map[string]*schema.Schema, newUpdaterFunc newResourceIamUpdaterFunc, options ...func(*IamSettings)) *schema.Resource {
settings := &IamSettings{}
for _, o := range options {
o(settings)
}

return &schema.Resource{
Read: DatasourceIamPolicyRead(newUpdaterFunc),
// if non-empty, this will be used to send a deprecation message when the
// datasource is used.
DeprecationMessage: settings.DeprecationMessage,
Schema: mergeSchemas(IamPolicyBaseDataSourceSchema, parentSpecificSchema),
UseJSONNumber: true,
}
}

func DatasourceIamPolicyRead(newUpdaterFunc newResourceIamUpdaterFunc) schema.ReadFunc {
return func(d *schema.ResourceData, meta interface{}) error {
config := meta.(*transport_tpg.Config)

updater, err := newUpdaterFunc(d, config)
if err != nil {
return err
}

policy, err := iamPolicyReadWithRetry(updater)
if err != nil {
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("Resource %q with IAM Policy", updater.DescribeResource()))
}

if err := d.Set("etag", policy.Etag); err != nil {
return fmt.Errorf("Error setting etag: %s", err)
}
if err := d.Set("policy_data", marshalIamPolicy(policy)); err != nil {
return fmt.Errorf("Error setting policy_data: %s", err)
}
d.SetId(updater.GetResourceId())

return nil
}
}
9 changes: 9 additions & 0 deletions google/iam_apigee_environment_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func TestAccApigeeEnvironmentIamPolicyGenerated(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccApigeeEnvironmentIamPolicy_basicGenerated(context),
Check: resource.TestCheckResourceAttrSet("data.google_apigee_environment_iam_policy.foo", "policy_data"),
},
{
ResourceName: "google_apigee_environment_iam_policy.foo",
Expand Down Expand Up @@ -275,6 +276,14 @@ resource "google_apigee_environment_iam_policy" "foo" {
env_id = google_apigee_environment.apigee_environment.name
policy_data = data.google_iam_policy.foo.policy_data
}
data "google_apigee_environment_iam_policy" "foo" {
org_id = google_apigee_environment.apigee_environment.org_id
env_id = google_apigee_environment.apigee_environment.name
depends_on = [
google_apigee_environment_iam_policy.foo
]
}
`, context)
}

Expand Down
10 changes: 10 additions & 0 deletions google/iam_artifact_registry_repository_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func TestAccArtifactRegistryRepositoryIamPolicyGenerated(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccArtifactRegistryRepositoryIamPolicy_basicGenerated(context),
Check: resource.TestCheckResourceAttrSet("data.google_artifact_registry_repository_iam_policy.foo", "policy_data"),
},
{
ResourceName: "google_artifact_registry_repository_iam_policy.foo",
Expand Down Expand Up @@ -159,6 +160,15 @@ resource "google_artifact_registry_repository_iam_policy" "foo" {
repository = google_artifact_registry_repository.my-repo.name
policy_data = data.google_iam_policy.foo.policy_data
}
data "google_artifact_registry_repository_iam_policy" "foo" {
project = google_artifact_registry_repository.my-repo.project
location = google_artifact_registry_repository.my-repo.location
repository = google_artifact_registry_repository.my-repo.name
depends_on = [
google_artifact_registry_repository_iam_policy.foo
]
}
`, context)
}

Expand Down
10 changes: 10 additions & 0 deletions google/iam_bigquery_analytics_hub_data_exchange_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func TestAccBigqueryAnalyticsHubDataExchangeIamPolicyGenerated(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccBigqueryAnalyticsHubDataExchangeIamPolicy_basicGenerated(context),
Check: resource.TestCheckResourceAttrSet("data.google_bigquery_analytics_hub_data_exchange_iam_policy.foo", "policy_data"),
},
{
ResourceName: "google_bigquery_analytics_hub_data_exchange_iam_policy.foo",
Expand Down Expand Up @@ -159,6 +160,15 @@ resource "google_bigquery_analytics_hub_data_exchange_iam_policy" "foo" {
data_exchange_id = google_bigquery_analytics_hub_data_exchange.data_exchange.data_exchange_id
policy_data = data.google_iam_policy.foo.policy_data
}
data "google_bigquery_analytics_hub_data_exchange_iam_policy" "foo" {
project = google_bigquery_analytics_hub_data_exchange.data_exchange.project
location = google_bigquery_analytics_hub_data_exchange.data_exchange.location
data_exchange_id = google_bigquery_analytics_hub_data_exchange.data_exchange.data_exchange_id
depends_on = [
google_bigquery_analytics_hub_data_exchange_iam_policy.foo
]
}
`, context)
}

Expand Down
11 changes: 11 additions & 0 deletions google/iam_bigquery_analytics_hub_listing_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func TestAccBigqueryAnalyticsHubListingIamPolicyGenerated(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccBigqueryAnalyticsHubListingIamPolicy_basicGenerated(context),
Check: resource.TestCheckResourceAttrSet("data.google_bigquery_analytics_hub_listing_iam_policy.foo", "policy_data"),
},
{
ResourceName: "google_bigquery_analytics_hub_listing_iam_policy.foo",
Expand Down Expand Up @@ -199,6 +200,16 @@ resource "google_bigquery_analytics_hub_listing_iam_policy" "foo" {
listing_id = google_bigquery_analytics_hub_listing.listing.listing_id
policy_data = data.google_iam_policy.foo.policy_data
}
data "google_bigquery_analytics_hub_listing_iam_policy" "foo" {
project = google_bigquery_analytics_hub_listing.listing.project
location = google_bigquery_analytics_hub_listing.listing.location
data_exchange_id = google_bigquery_analytics_hub_listing.listing.data_exchange_id
listing_id = google_bigquery_analytics_hub_listing.listing.listing_id
depends_on = [
google_bigquery_analytics_hub_listing_iam_policy.foo
]
}
`, context)
}

Expand Down
10 changes: 10 additions & 0 deletions google/iam_bigquery_connection_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func TestAccBigqueryConnectionConnectionIamPolicyGenerated(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccBigqueryConnectionConnectionIamPolicy_basicGenerated(context),
Check: resource.TestCheckResourceAttrSet("data.google_bigquery_connection_iam_policy.foo", "policy_data"),
},
{
ResourceName: "google_bigquery_connection_iam_policy.foo",
Expand Down Expand Up @@ -173,6 +174,15 @@ resource "google_bigquery_connection_iam_policy" "foo" {
connection_id = google_bigquery_connection.connection.connection_id
policy_data = data.google_iam_policy.foo.policy_data
}
data "google_bigquery_connection_iam_policy" "foo" {
project = google_bigquery_connection.connection.project
location = google_bigquery_connection.connection.location
connection_id = google_bigquery_connection.connection.connection_id
depends_on = [
google_bigquery_connection_iam_policy.foo
]
}
`, context)
}

Expand Down
10 changes: 10 additions & 0 deletions google/iam_bigquery_datapolicy_data_policy_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func TestAccBigqueryDatapolicyDataPolicyIamPolicyGenerated(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccBigqueryDatapolicyDataPolicyIamPolicy_basicGenerated(context),
Check: resource.TestCheckResourceAttrSet("data.google_bigquery_datapolicy_data_policy_iam_policy.foo", "policy_data"),
},
{
ResourceName: "google_bigquery_datapolicy_data_policy_iam_policy.foo",
Expand Down Expand Up @@ -185,6 +186,15 @@ resource "google_bigquery_datapolicy_data_policy_iam_policy" "foo" {
data_policy_id = google_bigquery_datapolicy_data_policy.data_policy.data_policy_id
policy_data = data.google_iam_policy.foo.policy_data
}
data "google_bigquery_datapolicy_data_policy_iam_policy" "foo" {
project = google_bigquery_datapolicy_data_policy.data_policy.project
location = google_bigquery_datapolicy_data_policy.data_policy.location
data_policy_id = google_bigquery_datapolicy_data_policy.data_policy.data_policy_id
depends_on = [
google_bigquery_datapolicy_data_policy_iam_policy.foo
]
}
`, context)
}

Expand Down
10 changes: 10 additions & 0 deletions google/iam_bigquery_table_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func TestAccBigQueryTableIamPolicyGenerated(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccBigQueryTableIamPolicy_basicGenerated(context),
Check: resource.TestCheckResourceAttrSet("data.google_bigquery_table_iam_policy.foo", "policy_data"),
},
{
ResourceName: "google_bigquery_table_iam_policy.foo",
Expand Down Expand Up @@ -459,6 +460,15 @@ resource "google_bigquery_table_iam_policy" "foo" {
table_id = google_bigquery_table.test.table_id
policy_data = data.google_iam_policy.foo.policy_data
}
data "google_bigquery_table_iam_policy" "foo" {
project = google_bigquery_table.test.project
dataset_id = google_bigquery_table.test.dataset_id
table_id = google_bigquery_table.test.table_id
depends_on = [
google_bigquery_table_iam_policy.foo
]
}
`, context)
}

Expand Down
9 changes: 9 additions & 0 deletions google/iam_binary_authorization_attestor_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func TestAccBinaryAuthorizationAttestorIamPolicyGenerated(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccBinaryAuthorizationAttestorIamPolicy_basicGenerated(context),
Check: resource.TestCheckResourceAttrSet("data.google_binary_authorization_attestor_iam_policy.foo", "policy_data"),
},
{
ResourceName: "google_binary_authorization_attestor_iam_policy.foo",
Expand Down Expand Up @@ -215,6 +216,14 @@ resource "google_binary_authorization_attestor_iam_policy" "foo" {
attestor = google_binary_authorization_attestor.attestor.name
policy_data = data.google_iam_policy.foo.policy_data
}
data "google_binary_authorization_attestor_iam_policy" "foo" {
project = google_binary_authorization_attestor.attestor.project
attestor = google_binary_authorization_attestor.attestor.name
depends_on = [
google_binary_authorization_attestor_iam_policy.foo
]
}
`, context)
}

Expand Down
10 changes: 10 additions & 0 deletions google/iam_cloud_run_service_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func TestAccCloudRunServiceIamPolicyGenerated(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccCloudRunServiceIamPolicy_basicGenerated(context),
Check: resource.TestCheckResourceAttrSet("data.google_cloud_run_service_iam_policy.foo", "policy_data"),
},
{
ResourceName: "google_cloud_run_service_iam_policy.foo",
Expand Down Expand Up @@ -184,6 +185,15 @@ resource "google_cloud_run_service_iam_policy" "foo" {
service = google_cloud_run_service.default.name
policy_data = data.google_iam_policy.foo.policy_data
}
data "google_cloud_run_service_iam_policy" "foo" {
location = google_cloud_run_service.default.location
project = google_cloud_run_service.default.project
service = google_cloud_run_service.default.name
depends_on = [
google_cloud_run_service_iam_policy.foo
]
}
`, context)
}

Expand Down
10 changes: 10 additions & 0 deletions google/iam_cloud_run_v2_job_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func TestAccCloudRunV2JobIamPolicyGenerated(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccCloudRunV2JobIamPolicy_basicGenerated(context),
Check: resource.TestCheckResourceAttrSet("data.google_cloud_run_v2_job_iam_policy.foo", "policy_data"),
},
{
ResourceName: "google_cloud_run_v2_job_iam_policy.foo",
Expand Down Expand Up @@ -183,6 +184,15 @@ resource "google_cloud_run_v2_job_iam_policy" "foo" {
name = google_cloud_run_v2_job.default.name
policy_data = data.google_iam_policy.foo.policy_data
}
data "google_cloud_run_v2_job_iam_policy" "foo" {
project = google_cloud_run_v2_job.default.project
location = google_cloud_run_v2_job.default.location
name = google_cloud_run_v2_job.default.name
depends_on = [
google_cloud_run_v2_job_iam_policy.foo
]
}
`, context)
}

Expand Down
10 changes: 10 additions & 0 deletions google/iam_cloud_run_v2_service_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func TestAccCloudRunV2ServiceIamPolicyGenerated(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccCloudRunV2ServiceIamPolicy_basicGenerated(context),
Check: resource.TestCheckResourceAttrSet("data.google_cloud_run_v2_service_iam_policy.foo", "policy_data"),
},
{
ResourceName: "google_cloud_run_v2_service_iam_policy.foo",
Expand Down Expand Up @@ -169,6 +170,15 @@ resource "google_cloud_run_v2_service_iam_policy" "foo" {
name = google_cloud_run_v2_service.default.name
policy_data = data.google_iam_policy.foo.policy_data
}
data "google_cloud_run_v2_service_iam_policy" "foo" {
project = google_cloud_run_v2_service.default.project
location = google_cloud_run_v2_service.default.location
name = google_cloud_run_v2_service.default.name
depends_on = [
google_cloud_run_v2_service_iam_policy.foo
]
}
`, context)
}

Expand Down
10 changes: 10 additions & 0 deletions google/iam_cloud_tasks_queue_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func TestAccCloudTasksQueueIamPolicyGenerated(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccCloudTasksQueueIamPolicy_basicGenerated(context),
Check: resource.TestCheckResourceAttrSet("data.google_cloud_tasks_queue_iam_policy.foo", "policy_data"),
},
{
ResourceName: "google_cloud_tasks_queue_iam_policy.foo",
Expand Down Expand Up @@ -155,6 +156,15 @@ resource "google_cloud_tasks_queue_iam_policy" "foo" {
name = google_cloud_tasks_queue.default.name
policy_data = data.google_iam_policy.foo.policy_data
}
data "google_cloud_tasks_queue_iam_policy" "foo" {
project = google_cloud_tasks_queue.default.project
location = google_cloud_tasks_queue.default.location
name = google_cloud_tasks_queue.default.name
depends_on = [
google_cloud_tasks_queue_iam_policy.foo
]
}
`, context)
}

Expand Down
10 changes: 10 additions & 0 deletions google/iam_cloudfunctions2_function_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func TestAccCloudfunctions2functionIamPolicyGenerated(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccCloudfunctions2functionIamPolicy_basicGenerated(context),
Check: resource.TestCheckResourceAttrSet("data.google_cloudfunctions2_function_iam_policy.foo", "policy_data"),
},
{
ResourceName: "google_cloudfunctions2_function_iam_policy.foo",
Expand Down Expand Up @@ -247,6 +248,15 @@ resource "google_cloudfunctions2_function_iam_policy" "foo" {
cloud_function = google_cloudfunctions2_function.function.name
policy_data = data.google_iam_policy.foo.policy_data
}
data "google_cloudfunctions2_function_iam_policy" "foo" {
project = google_cloudfunctions2_function.function.project
location = google_cloudfunctions2_function.function.location
cloud_function = google_cloudfunctions2_function.function.name
depends_on = [
google_cloudfunctions2_function_iam_policy.foo
]
}
`, context)
}

Expand Down
Loading

0 comments on commit bbcd741

Please sign in to comment.