Skip to content

Commit 6966ef6

Browse files
author
sprioriello
committed
Fixing comment 'issue: Please populate the Computed fields in Create' by deiga
1 parent 47c58fa commit 6966ef6

4 files changed

Lines changed: 88 additions & 71 deletions

github/resource_github_enterprise_security_configuration.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,7 @@ func resourceGithubEnterpriseSecurityConfigurationCreate(ctx context.Context, d
273273
"id": configuration.GetID(),
274274
})
275275

276-
if err = d.Set("target_type", configuration.GetTargetType()); err != nil {
277-
return diag.FromErr(err)
278-
}
279-
280-
return nil
276+
return resourceGithubEnterpriseSecurityConfigurationRead(ctx, d, meta)
281277
}
282278

283279
func resourceGithubEnterpriseSecurityConfigurationRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
@@ -405,7 +401,6 @@ func resourceGithubEnterpriseSecurityConfigurationRead(ctx context.Context, d *s
405401

406402
func resourceGithubEnterpriseSecurityConfigurationUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
407403
client := meta.(*Owner).v3client
408-
enterprise := d.Get("enterprise_slug").(string)
409404

410405
enterprise, idStr, err := parseID2(d.Id())
411406
if err != nil {
@@ -424,7 +419,7 @@ func resourceGithubEnterpriseSecurityConfigurationUpdate(ctx context.Context, d
424419

425420
config := expandEnterpriseCodeSecurityConfiguration(d)
426421

427-
configuration, _, err := client.Enterprise.UpdateCodeSecurityConfiguration(ctx, enterprise, id, config)
422+
_, _, err = client.Enterprise.UpdateCodeSecurityConfiguration(ctx, enterprise, id, config)
428423
if err != nil {
429424
tflog.Error(ctx, fmt.Sprintf("Failed to update enterprise code security configuration: %s/%d", enterprise, id), map[string]any{
430425
"enterprise": enterprise,
@@ -439,11 +434,7 @@ func resourceGithubEnterpriseSecurityConfigurationUpdate(ctx context.Context, d
439434
"id": id,
440435
})
441436

442-
if err = d.Set("target_type", configuration.GetTargetType()); err != nil {
443-
return diag.FromErr(err)
444-
}
445-
446-
return nil
437+
return resourceGithubEnterpriseSecurityConfigurationRead(ctx, d, meta)
447438
}
448439

449440
func resourceGithubEnterpriseSecurityConfigurationDelete(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {

github/resource_github_enterprise_security_configuration_test.go

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66

77
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
88
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
9+
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
10+
"github.com/hashicorp/terraform-plugin-testing/statecheck"
11+
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
912
)
1013

1114
func TestAccGithubEnterpriseSecurityConfiguration(t *testing.T) {
@@ -35,12 +38,16 @@ func TestAccGithubEnterpriseSecurityConfiguration(t *testing.T) {
3538
Steps: []resource.TestStep{
3639
{
3740
Config: config,
38-
Check: resource.ComposeTestCheckFunc(
39-
resource.TestCheckResourceAttr("github_enterprise_security_configuration.test", "name", configName),
40-
resource.TestCheckResourceAttr("github_enterprise_security_configuration.test", "description", "Test configuration"),
41-
resource.TestCheckResourceAttr("github_enterprise_security_configuration.test", "advanced_security", "enabled"),
42-
resource.TestCheckResourceAttr("github_enterprise_security_configuration.test", "enforcement", "enforced"),
43-
),
41+
ConfigStateChecks: []statecheck.StateCheck{
42+
statecheck.ExpectKnownValue("github_enterprise_security_configuration.test",
43+
tfjsonpath.New("name"), knownvalue.StringExact(configName)),
44+
statecheck.ExpectKnownValue("github_enterprise_security_configuration.test",
45+
tfjsonpath.New("description"), knownvalue.StringExact("Test configuration")),
46+
statecheck.ExpectKnownValue("github_enterprise_security_configuration.test",
47+
tfjsonpath.New("advanced_security"), knownvalue.StringExact("enabled")),
48+
statecheck.ExpectKnownValue("github_enterprise_security_configuration.test",
49+
tfjsonpath.New("enforcement"), knownvalue.StringExact("enforced")),
50+
},
4451
},
4552
{
4653
ResourceName: "github_enterprise_security_configuration.test",
@@ -72,17 +79,21 @@ func TestAccGithubEnterpriseSecurityConfiguration(t *testing.T) {
7279
Steps: []resource.TestStep{
7380
{
7481
Config: configBefore,
75-
Check: resource.ComposeTestCheckFunc(
76-
resource.TestCheckResourceAttr("github_enterprise_security_configuration.test", "name", configName),
77-
resource.TestCheckResourceAttr("github_enterprise_security_configuration.test", "advanced_security", "disabled"),
78-
),
82+
ConfigStateChecks: []statecheck.StateCheck{
83+
statecheck.ExpectKnownValue("github_enterprise_security_configuration.test",
84+
tfjsonpath.New("name"), knownvalue.StringExact(configName)),
85+
statecheck.ExpectKnownValue("github_enterprise_security_configuration.test",
86+
tfjsonpath.New("advanced_security"), knownvalue.StringExact("disabled")),
87+
},
7988
},
8089
{
8190
Config: configAfter,
82-
Check: resource.ComposeTestCheckFunc(
83-
resource.TestCheckResourceAttr("github_enterprise_security_configuration.test", "name", configNameUpdated),
84-
resource.TestCheckResourceAttr("github_enterprise_security_configuration.test", "advanced_security", "enabled"),
85-
),
91+
ConfigStateChecks: []statecheck.StateCheck{
92+
statecheck.ExpectKnownValue("github_enterprise_security_configuration.test",
93+
tfjsonpath.New("name"), knownvalue.StringExact(configNameUpdated)),
94+
statecheck.ExpectKnownValue("github_enterprise_security_configuration.test",
95+
tfjsonpath.New("advanced_security"), knownvalue.StringExact("enabled")),
96+
},
8697
},
8798
},
8899
})
@@ -117,12 +128,16 @@ func TestAccGithubEnterpriseSecurityConfiguration(t *testing.T) {
117128
Steps: []resource.TestStep{
118129
{
119130
Config: config,
120-
Check: resource.ComposeTestCheckFunc(
121-
resource.TestCheckResourceAttr("github_enterprise_security_configuration.test", "name", configName),
122-
resource.TestCheckResourceAttr("github_enterprise_security_configuration.test", "dependency_graph_autosubmit_action_options.0.labeled_runners", "true"),
123-
resource.TestCheckResourceAttr("github_enterprise_security_configuration.test", "code_scanning_default_setup_options.0.runner_type", "labeled"),
124-
resource.TestCheckResourceAttr("github_enterprise_security_configuration.test", "code_scanning_default_setup_options.0.runner_label", "code-scanning"),
125-
),
131+
ConfigStateChecks: []statecheck.StateCheck{
132+
statecheck.ExpectKnownValue("github_enterprise_security_configuration.test",
133+
tfjsonpath.New("name"), knownvalue.StringExact(configName)),
134+
statecheck.ExpectKnownValue("github_enterprise_security_configuration.test",
135+
tfjsonpath.New("dependency_graph_autosubmit_action_options").AtSliceIndex(0).AtMapKey("labeled_runners"), knownvalue.Bool(true)),
136+
statecheck.ExpectKnownValue("github_enterprise_security_configuration.test",
137+
tfjsonpath.New("code_scanning_default_setup_options").AtSliceIndex(0).AtMapKey("runner_type"), knownvalue.StringExact("labeled")),
138+
statecheck.ExpectKnownValue("github_enterprise_security_configuration.test",
139+
tfjsonpath.New("code_scanning_default_setup_options").AtSliceIndex(0).AtMapKey("runner_label"), knownvalue.StringExact("code-scanning")),
140+
},
126141
},
127142
{
128143
ResourceName: "github_enterprise_security_configuration.test",
@@ -150,10 +165,12 @@ func TestAccGithubEnterpriseSecurityConfiguration(t *testing.T) {
150165
Steps: []resource.TestStep{
151166
{
152167
Config: config,
153-
Check: resource.ComposeTestCheckFunc(
154-
resource.TestCheckResourceAttr("github_enterprise_security_configuration.test", "name", configName),
155-
resource.TestCheckResourceAttrSet("github_enterprise_security_configuration.test", "target_type"),
156-
),
168+
ConfigStateChecks: []statecheck.StateCheck{
169+
statecheck.ExpectKnownValue("github_enterprise_security_configuration.test",
170+
tfjsonpath.New("name"), knownvalue.StringExact(configName)),
171+
statecheck.ExpectKnownValue("github_enterprise_security_configuration.test",
172+
tfjsonpath.New("target_type"), knownvalue.NotNull()),
173+
},
157174
},
158175
},
159176
})

github/resource_github_organization_security_configuration.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,7 @@ func resourceGithubOrganizationSecurityConfigurationCreate(ctx context.Context,
328328
"id": configuration.GetID(),
329329
})
330330

331-
if err = d.Set("target_type", configuration.GetTargetType()); err != nil {
332-
return diag.FromErr(err)
333-
}
334-
335-
return nil
331+
return resourceGithubOrganizationSecurityConfigurationRead(ctx, d, meta)
336332
}
337333

338334
func resourceGithubOrganizationSecurityConfigurationRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
@@ -494,7 +490,7 @@ func resourceGithubOrganizationSecurityConfigurationUpdate(ctx context.Context,
494490

495491
config := expandCodeSecurityConfiguration(d)
496492

497-
configuration, _, err := client.Organizations.UpdateCodeSecurityConfiguration(ctx, org, id, config)
493+
_, _, err = client.Organizations.UpdateCodeSecurityConfiguration(ctx, org, id, config)
498494
if err != nil {
499495
tflog.Error(ctx, fmt.Sprintf("Failed to update organization code security configuration: %s/%d", org, id), map[string]any{
500496
"organization": org,
@@ -509,11 +505,7 @@ func resourceGithubOrganizationSecurityConfigurationUpdate(ctx context.Context,
509505
"id": id,
510506
})
511507

512-
if err = d.Set("target_type", configuration.GetTargetType()); err != nil {
513-
return diag.FromErr(err)
514-
}
515-
516-
return nil
508+
return resourceGithubOrganizationSecurityConfigurationRead(ctx, d, meta)
517509
}
518510

519511
func resourceGithubOrganizationSecurityConfigurationDelete(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {

github/resource_github_organization_security_configuration_test.go

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66

77
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
88
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
9+
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
10+
"github.com/hashicorp/terraform-plugin-testing/statecheck"
11+
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
912
)
1013

1114
func TestAccGithubOrganizationSecurityConfiguration(t *testing.T) {
@@ -34,12 +37,16 @@ func TestAccGithubOrganizationSecurityConfiguration(t *testing.T) {
3437
Steps: []resource.TestStep{
3538
{
3639
Config: config,
37-
Check: resource.ComposeTestCheckFunc(
38-
resource.TestCheckResourceAttr("github_organization_security_configuration.test", "name", configName),
39-
resource.TestCheckResourceAttr("github_organization_security_configuration.test", "description", "Test configuration"),
40-
resource.TestCheckResourceAttr("github_organization_security_configuration.test", "advanced_security", "enabled"),
41-
resource.TestCheckResourceAttr("github_organization_security_configuration.test", "enforcement", "enforced"),
42-
),
40+
ConfigStateChecks: []statecheck.StateCheck{
41+
statecheck.ExpectKnownValue("github_organization_security_configuration.test",
42+
tfjsonpath.New("name"), knownvalue.StringExact(configName)),
43+
statecheck.ExpectKnownValue("github_organization_security_configuration.test",
44+
tfjsonpath.New("description"), knownvalue.StringExact("Test configuration")),
45+
statecheck.ExpectKnownValue("github_organization_security_configuration.test",
46+
tfjsonpath.New("advanced_security"), knownvalue.StringExact("enabled")),
47+
statecheck.ExpectKnownValue("github_organization_security_configuration.test",
48+
tfjsonpath.New("enforcement"), knownvalue.StringExact("enforced")),
49+
},
4350
},
4451
{
4552
ResourceName: "github_organization_security_configuration.test",
@@ -70,17 +77,21 @@ func TestAccGithubOrganizationSecurityConfiguration(t *testing.T) {
7077
Steps: []resource.TestStep{
7178
{
7279
Config: configBefore,
73-
Check: resource.ComposeTestCheckFunc(
74-
resource.TestCheckResourceAttr("github_organization_security_configuration.test", "name", configName),
75-
resource.TestCheckResourceAttr("github_organization_security_configuration.test", "advanced_security", "disabled"),
76-
),
80+
ConfigStateChecks: []statecheck.StateCheck{
81+
statecheck.ExpectKnownValue("github_organization_security_configuration.test",
82+
tfjsonpath.New("name"), knownvalue.StringExact(configName)),
83+
statecheck.ExpectKnownValue("github_organization_security_configuration.test",
84+
tfjsonpath.New("advanced_security"), knownvalue.StringExact("disabled")),
85+
},
7786
},
7887
{
7988
Config: configAfter,
80-
Check: resource.ComposeTestCheckFunc(
81-
resource.TestCheckResourceAttr("github_organization_security_configuration.test", "name", configNameUpdated),
82-
resource.TestCheckResourceAttr("github_organization_security_configuration.test", "advanced_security", "enabled"),
83-
),
89+
ConfigStateChecks: []statecheck.StateCheck{
90+
statecheck.ExpectKnownValue("github_organization_security_configuration.test",
91+
tfjsonpath.New("name"), knownvalue.StringExact(configNameUpdated)),
92+
statecheck.ExpectKnownValue("github_organization_security_configuration.test",
93+
tfjsonpath.New("advanced_security"), knownvalue.StringExact("enabled")),
94+
},
8495
},
8596
},
8697
})
@@ -115,12 +126,16 @@ func TestAccGithubOrganizationSecurityConfiguration(t *testing.T) {
115126
Steps: []resource.TestStep{
116127
{
117128
Config: config,
118-
Check: resource.ComposeTestCheckFunc(
119-
resource.TestCheckResourceAttr("github_organization_security_configuration.test", "name", configName),
120-
resource.TestCheckResourceAttr("github_organization_security_configuration.test", "dependency_graph_autosubmit_action_options.0.labeled_runners", "true"),
121-
resource.TestCheckResourceAttr("github_organization_security_configuration.test", "code_scanning_default_setup_options.0.runner_type", "labeled"),
122-
resource.TestCheckResourceAttr("github_organization_security_configuration.test", "code_scanning_default_setup_options.0.runner_label", "code-scanning"),
123-
),
129+
ConfigStateChecks: []statecheck.StateCheck{
130+
statecheck.ExpectKnownValue("github_organization_security_configuration.test",
131+
tfjsonpath.New("name"), knownvalue.StringExact(configName)),
132+
statecheck.ExpectKnownValue("github_organization_security_configuration.test",
133+
tfjsonpath.New("dependency_graph_autosubmit_action_options").AtSliceIndex(0).AtMapKey("labeled_runners"), knownvalue.Bool(true)),
134+
statecheck.ExpectKnownValue("github_organization_security_configuration.test",
135+
tfjsonpath.New("code_scanning_default_setup_options").AtSliceIndex(0).AtMapKey("runner_type"), knownvalue.StringExact("labeled")),
136+
statecheck.ExpectKnownValue("github_organization_security_configuration.test",
137+
tfjsonpath.New("code_scanning_default_setup_options").AtSliceIndex(0).AtMapKey("runner_label"), knownvalue.StringExact("code-scanning")),
138+
},
124139
},
125140
{
126141
ResourceName: "github_organization_security_configuration.test",
@@ -147,10 +162,12 @@ func TestAccGithubOrganizationSecurityConfiguration(t *testing.T) {
147162
Steps: []resource.TestStep{
148163
{
149164
Config: config,
150-
Check: resource.ComposeTestCheckFunc(
151-
resource.TestCheckResourceAttr("github_organization_security_configuration.test", "name", configName),
152-
resource.TestCheckResourceAttrSet("github_organization_security_configuration.test", "target_type"),
153-
),
165+
ConfigStateChecks: []statecheck.StateCheck{
166+
statecheck.ExpectKnownValue("github_organization_security_configuration.test",
167+
tfjsonpath.New("name"), knownvalue.StringExact(configName)),
168+
statecheck.ExpectKnownValue("github_organization_security_configuration.test",
169+
tfjsonpath.New("target_type"), knownvalue.NotNull()),
170+
},
154171
},
155172
},
156173
})

0 commit comments

Comments
 (0)