Skip to content

Commit

Permalink
Run version guard checks on PRs (#10347)
Browse files Browse the repository at this point in the history
  • Loading branch information
roaks3 authored Apr 4, 2024
1 parent ee547c9 commit e200cd1
Show file tree
Hide file tree
Showing 23 changed files with 135 additions and 86 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/mmv1-check-templates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: mmv1-check-templates

permissions: read-all

on:
pull_request:
paths:
- 'mmv1/**/*.erb'

jobs:
version-guard-check:
runs-on: ubuntu-22.04
steps:
- name: Checkout Repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.2
with:
path: repo
fetch-depth: 0
- name: Merge base branch
id: pull_request
run: |
cd repo
git config user.name "modular-magician"
git config user.email "magic-modules@google.com"
git fetch origin ${{ github.base_ref }} # Fetch the base branch
git merge --no-ff origin/${{ github.base_ref }} # Merge with the base branch
- name: Check for invalid version guards
run: |
cd repo/tools/template-check
git diff --name-only origin/${{ github.base_ref }} ../../*.erb | sed 's=^=../../=g' | go run main.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,9 @@ func expandConfidentialInstanceConfig(d tpgresource.TerraformResourceData) *comp
prefix := "confidential_instance_config.0"
return &compute.ConfidentialInstanceConfig{
EnableConfidentialCompute: d.Get(prefix + ".enable_confidential_compute").(bool),
<% unless version == "ga" %>
<% unless version == "ga" -%>
ConfidentialInstanceType: d.Get(prefix + ".confidential_instance_type").(string),
<% end %>
<% end -%>
}
}

Expand All @@ -590,9 +590,9 @@ func flattenConfidentialInstanceConfig(ConfidentialInstanceConfig *compute.Confi

return []map[string]interface{}{{
"enable_confidential_compute": ConfidentialInstanceConfig.EnableConfidentialCompute,
<% unless version == "ga" %>
<% unless version == "ga" -%>
"confidential_instance_type": ConfidentialInstanceConfig.ConfidentialInstanceType,
<% end %>
<% end -%>
}}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% autogen_exception -%>
package compute_test
<% if version != "ga" -%>
<% unless version == "ga" -%>

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -994,13 +994,13 @@ be from 0 to 999,999,999 inclusive.`,
Description: `The Confidential VM config being used by the instance. on_host_maintenance has to be set to TERMINATE or this will fail to create.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
<% if version == "ga" %>
<% if version == "ga" -%>
"enable_confidential_compute": {
Type: schema.TypeBool,
Required: true,
Description: `Defines whether the instance should have confidential compute enabled.`,
},
<% else %>
<% else -%>
"enable_confidential_compute": {
Type: schema.TypeBool,
Optional: true,
Expand All @@ -1016,7 +1016,7 @@ be from 0 to 999,999,999 inclusive.`,
If SEV_SNP, min_cpu_platform = "AMD Milan" is currently required.`,
AtLeastOneOf: []string{"confidential_instance_config.0.enable_confidential_compute", "confidential_instance_config.0.confidential_instance_type"},
},
<% end %>
<% end -%>
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,11 @@ func testAccCheckComputeInstanceGroupMembershipDestroyed(t *testing.T, instanceG
func testAccComputeInstanceGroupMembershipListMembership(t *testing.T, instanceGroupId string) (map[string]struct{}, error) {
config := acctest.GoogleProviderConfig(t)

url := fmt.Sprintf("https://www.googleapis.com/compute/<% if version == 'ga' %>v1<% else %>beta<% end %>/%s/listInstances", instanceGroupId)
<% if version == 'ga' -%>
url := fmt.Sprintf("https://www.googleapis.com/compute/v1/%s/listInstances", instanceGroupId)
<% else -%>
url := fmt.Sprintf("https://www.googleapis.com/compute/beta/%s/listInstances", instanceGroupId)
<% end -%>
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "POST",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ Google Cloud KMS.`,
Description: `The name of the subnetwork to attach this interface to. The subnetwork must exist in the same region this instance will be created in. Either network or subnetwork must be provided.`,
},

<% if version == 'beta' -%>
<% unless version == 'ga' -%>
"network_attachment": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -870,14 +870,14 @@ be from 0 to 999,999,999 inclusive.`,
Description: `The Confidential VM config being used by the instance. on_host_maintenance has to be set to TERMINATE or this will fail to create.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
<% if version == "ga" %>
<% if version == "ga" -%>
"enable_confidential_compute": {
Type: schema.TypeBool,
Required: true,
ForceNew: true,
Description: `Defines whether the instance should have confidential compute enabled.`,
},
<% else %>
<% else -%>
"enable_confidential_compute": {
Type: schema.TypeBool,
Optional: true,
Expand All @@ -895,7 +895,7 @@ be from 0 to 999,999,999 inclusive.`,
If SEV_SNP, min_cpu_platform = "AMD Milan" is currently required.`,
AtLeastOneOf: []string{"confidential_instance_config.0.enable_confidential_compute", "confidential_instance_config.0.confidential_instance_type"},
},
<% end %>
<% end -%>
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -772,9 +772,9 @@ func TestAccComputeInstanceTemplate_ConfidentialInstanceConfigMain(t *testing.T)
t.Parallel()

var instanceTemplate compute.InstanceTemplate
<% unless version == "ga" %>
<% unless version == "ga" -%>
var instanceTemplate2 compute.InstanceTemplate
<% end %>
<% end -%>

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
Expand All @@ -786,13 +786,13 @@ func TestAccComputeInstanceTemplate_ConfidentialInstanceConfigMain(t *testing.T)
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceTemplateExists(t, "google_compute_instance_template.foobar", &instanceTemplate),
testAccCheckComputeInstanceTemplateHasConfidentialInstanceConfig(&instanceTemplate, true, "SEV"),
<% unless version == "ga" %>
<% unless version == "ga" -%>
testAccCheckComputeInstanceTemplateExists(t, "google_compute_instance_template.foobar2", &instanceTemplate2),
testAccCheckComputeInstanceTemplateHasConfidentialInstanceConfig(&instanceTemplate2, true, ""),
<% end %>
<% end -%>
),
},
<% unless version == "ga" %>
<% unless version == "ga" -%>
{
Config: testAccComputeInstanceTemplateConfidentialInstanceConfigNoEnable(acctest.RandString(t, 10), "AMD Milan", "SEV_SNP"),
Check: resource.ComposeTestCheckFunc(
Expand All @@ -802,7 +802,7 @@ func TestAccComputeInstanceTemplate_ConfidentialInstanceConfigMain(t *testing.T)
testAccCheckComputeInstanceTemplateHasConfidentialInstanceConfig(&instanceTemplate2, false, "SEV_SNP"),
),
},
<% end %>
<% end -%>
},
})
}
Expand Down Expand Up @@ -1799,11 +1799,11 @@ func testAccCheckComputeInstanceTemplateHasConfidentialInstanceConfig(instanceTe
if instanceTemplate.Properties.ConfidentialInstanceConfig.EnableConfidentialCompute != EnableConfidentialCompute {
return fmt.Errorf("Wrong ConfidentialInstanceConfig EnableConfidentialCompute: expected %t, got, %t", EnableConfidentialCompute, instanceTemplate.Properties.ConfidentialInstanceConfig.EnableConfidentialCompute)
}
<% unless version == "ga" %>
<% unless version == "ga" -%>
if instanceTemplate.Properties.ConfidentialInstanceConfig.ConfidentialInstanceType != ConfidentialInstanceType {
return fmt.Errorf("Wrong ConfidentialInstanceConfig ConfidentialInstanceType: expected %s, got, %s", ConfidentialInstanceType, instanceTemplate.Properties.ConfidentialInstanceConfig.ConfidentialInstanceType)
}
<% end %>
<% end -%>

return nil
}
Expand Down Expand Up @@ -3124,17 +3124,18 @@ resource "google_compute_instance_template" "foobar" {

confidential_instance_config {
enable_confidential_compute = true
<% unless version == "ga" %>
<% unless version == "ga" -%>
confidential_instance_type = %q
<% end %>
<% end -%>
}

scheduling {
on_host_maintenance = "TERMINATE"
}

}
<% unless version == "ga" %>

<% unless version == "ga" -%>
resource "google_compute_instance_template" "foobar2" {
name = "tf-test-instance2-template-%s"
machine_type = "n2d-standard-2"
Expand All @@ -3158,15 +3159,15 @@ resource "google_compute_instance_template" "foobar2" {
}

}
<% end %>
<% if version == "ga" %>
<% end -%>
<% if version == "ga" -%>
`, suffix)
<% else %>
<% else -%>
`, suffix, confidentialInstanceType, suffix)
<% end %>
<% end -%>
}

<% unless version == "ga" %>
<% unless version == "ga" -%>
func testAccComputeInstanceTemplateConfidentialInstanceConfigNoEnable(suffix string, minCpuPlatform, confidentialInstanceType string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image2" {
Expand Down Expand Up @@ -3227,7 +3228,7 @@ resource "google_compute_instance_template" "foobar4" {
}
`, suffix, minCpuPlatform, confidentialInstanceType, suffix, minCpuPlatform, confidentialInstanceType)
}
<% end %>
<% end -%>

func testAccComputeInstanceTemplateAdvancedMachineFeatures(suffix string) string {
return fmt.Sprintf(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1804,9 +1804,9 @@ func TestAccComputeInstanceConfidentialInstanceConfigMain(t *testing.T) {
t.Parallel()

var instance compute.Instance
<% unless version == "ga" %>
<% unless version == "ga" -%>
var instance2 compute.Instance
<% end %>
<% end -%>
instanceName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))

acctest.VcrTest(t, resource.TestCase{
Expand All @@ -1819,13 +1819,13 @@ func TestAccComputeInstanceConfidentialInstanceConfigMain(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists(t, "google_compute_instance.foobar", &instance),
testAccCheckComputeInstanceHasConfidentialInstanceConfig(&instance, true, "SEV"),
<% unless version == "ga" %>
<% unless version == "ga" -%>
testAccCheckComputeInstanceExists(t, "google_compute_instance.foobar2", &instance2),
testAccCheckComputeInstanceHasConfidentialInstanceConfig(&instance2, true, ""),
<% end %>
<% end -%>
),
},
<% unless version == "ga" %>
<% unless version == "ga" -%>
{
Config: testAccComputeInstanceConfidentialInstanceConfigNoEnable(instanceName, "AMD Milan", "SEV_SNP"),
Check: resource.ComposeTestCheckFunc(
Expand All @@ -1835,7 +1835,7 @@ func TestAccComputeInstanceConfidentialInstanceConfigMain(t *testing.T) {
testAccCheckComputeInstanceHasConfidentialInstanceConfig(&instance2, false, "SEV_SNP"),
),
},
<% end %>
<% end -%>
},
})
}
Expand Down Expand Up @@ -3215,7 +3215,7 @@ func testAccCheckComputeInstanceUpdateMachineType(t *testing.T, n string) resour
}
}

<% unless version == "ga"%>
<% unless version == "ga" -%>
func TestAccComputeInstance_NetworkAttachment(t *testing.T) {
t.Parallel()
suffix := fmt.Sprintf("%s", acctest.RandString(t, 10))
Expand Down Expand Up @@ -3277,7 +3277,7 @@ func TestAccComputeInstance_NetworkAttachmentUpdate(t *testing.T) {
},
})
}
<% end %>
<% end -%>

func TestAccComputeInstance_NicStackTypeUpdate(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -3922,7 +3922,7 @@ func testAccCheckComputeInstanceHasNetworkAttachment(instance *compute.Instance,
return fmt.Errorf("Network Attachment %s, was not found in the instance template", networkAttachmentName)
}
}
<% end %>
<% end -%>

func testAccCheckComputeInstanceHasMachineType(instance *compute.Instance, machineType string) resource.TestCheckFunc {
return func(s *terraform.State) error {
Expand Down Expand Up @@ -4024,11 +4024,11 @@ func testAccCheckComputeInstanceHasConfidentialInstanceConfig(instance *compute.
if instance.ConfidentialInstanceConfig.EnableConfidentialCompute != EnableConfidentialCompute {
return fmt.Errorf("Wrong ConfidentialInstanceConfig EnableConfidentialCompute: expected %t, got, %t", EnableConfidentialCompute, instance.ConfidentialInstanceConfig.EnableConfidentialCompute)
}
<% unless version == "ga" %>
<% unless version == "ga" -%>
if instance.ConfidentialInstanceConfig.ConfidentialInstanceType != ConfidentialInstanceType {
return fmt.Errorf("Wrong ConfidentialInstanceConfig ConfidentialInstanceType: expected %s, got, %s", ConfidentialInstanceType, instance.ConfidentialInstanceConfig.ConfidentialInstanceType)
}
<% end %>
<% end -%>

return nil
}
Expand Down Expand Up @@ -7220,17 +7220,18 @@ resource "google_compute_instance" "foobar" {

confidential_instance_config {
enable_confidential_compute = true
<% unless version == "ga" %>
<% unless version == "ga" -%>
confidential_instance_type = %q
<% end %>
<% end -%>
}

scheduling {
on_host_maintenance = "TERMINATE"
}

}
<% unless version == "ga" %>

<% unless version == "ga" -%>
resource "google_compute_instance" "foobar2" {
name = "%s2"
machine_type = "n2d-standard-2"
Expand All @@ -7255,15 +7256,15 @@ resource "google_compute_instance" "foobar2" {
}

}
<% end %>
<% if version == "ga" %>
<% end -%>
<% if version == "ga" -%>
`, instance)
<% else %>
<% else -%>
`, instance, confidentialInstanceType, instance)
<% end %>
<% end -%>
}

<% unless version == "ga" %>
<% unless version == "ga" -%>
func testAccComputeInstanceConfidentialInstanceConfigNoEnable(instance string, minCpuPlatform, confidentialInstanceType string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image2" {
Expand Down Expand Up @@ -7326,7 +7327,7 @@ resource "google_compute_instance" "foobar4" {
}
`, instance, minCpuPlatform, confidentialInstanceType, instance, minCpuPlatform, confidentialInstanceType)
}
<% end %>
<% end -%>

func testAccComputeInstance_attributionLabelCreate(instance, add, strategy string) string {
return fmt.Sprintf(`
Expand Down Expand Up @@ -8854,7 +8855,7 @@ resource "google_compute_instance" "foobar" {

<% end -%>

<% unless version =="ga" -%>
<% unless version == "ga" -%>
func testAccComputeInstance_networkAttachment(context map[string]interface{}) string {
return acctest.Nprintf(`
data "google_compute_image" "my_image" {
Expand Down Expand Up @@ -8989,7 +8990,7 @@ resource "google_compute_instance" "foobar" {
}
`, suffix, suffix, suffix, region, suffix, region, suffix, region, suffix, region, suffix, region, networkAttachment)
}
<% end %>
<% end -%>

func testAccComputeInstance_nicStackTypeUpdate(suffix, region, stack_type, instance string) string {
return fmt.Sprintf(`
Expand Down
Loading

0 comments on commit e200cd1

Please sign in to comment.