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

Upgrade dcl #7012

Merged
merged 12 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion mmv1/third_party/terraform/go.mod.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.18

require (
cloud.google.com/go/bigtable v1.17.0
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.28.0
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.30.0
github.com/apparentlymart/go-cidr v1.1.0
github.com/client9/misspell v0.3.4
github.com/davecgh/go-spew v1.1.1
Expand Down
6 changes: 6 additions & 0 deletions mmv1/third_party/terraform/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1289,3 +1289,9 @@ rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.29.0 h1:RmGDbvUWkRLYyWngSad04GR4LAnqflbXvzI1iBO2+rU=
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.29.0/go.mod h1:pL2Qt5HT+x6xrTd806oMiM3awW6kNIXB/iiuClz6m6k=
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.29.1-0.20221217025133-b2d522d3684b h1:RgZjFUQKRCJV61R5emEFGhDOX84D0BPZG+p/E0hilSk=
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.29.1-0.20221217025133-b2d522d3684b/go.mod h1:pL2Qt5HT+x6xrTd806oMiM3awW6kNIXB/iiuClz6m6k=
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.30.0 h1:1DMSUzQO2osKXy03/xZmr5n8bMlW3RyMhHR2JpkkVzY=
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.30.0/go.mod h1:pL2Qt5HT+x6xrTd806oMiM3awW6kNIXB/iiuClz6m6k=
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
<% autogen_exception -%>
rileykarson marked this conversation as resolved.
Show resolved Hide resolved

package google

import (
"context"
"fmt"
dcl "github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl"
osconfig "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/osconfig<%= dcl_version(version) -%>"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"strings"
"testing"
)

func TestAccOsConfigOsPolicyAssignment_basicOsPolicyAssignment(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"project_name": getTestProjectFromEnv(),
"zone": getTestZoneFromEnv(),
"random_suffix": randString(t, 10),
"org_id": getTestOrgFromEnv(t),
"billing_act": getTestBillingAccountFromEnv(t),
}

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckOsConfigOsPolicyAssignmentDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccOsConfigOsPolicyAssignment_PercentOsPolicyAssignment(context),
},
{
ResourceName: "google_os_config_os_policy_assignment.primary",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"rollout.0.min_wait_duration"},
},
},
})
}

func testAccOsConfigOsPolicyAssignment_PercentOsPolicyAssignment(context map[string]interface{}) string {
return Nprintf(`
resource "google_project" "project" {
project_id = "tf-test%{random_suffix}"
name = "tf-test%{random_suffix}"
org_id = "%{org_id}"
billing_account = "%{billing_act}"
}

resource "google_project_service" "compute" {
project = google_project.project.project_id
service = "compute.googleapis.com"
}

resource "google_project_service" "osconfig" {
project = google_project.project.project_id
service = "osconfig.googleapis.com"
depends_on = [google_project_service.compute]
}

resource "google_os_config_os_policy_assignment" "primary" {
instance_filter {
all = false
exclusion_labels {
labels = {
label-two = "value-two"
}
}
inclusion_labels {
labels = {
label-one = "value-one"
}
}
inventories {
os_short_name = "centos"
os_version = "8.*"
}
}

location = "%{zone}"
name = "tf-test-assignment%{random_suffix}"

os_policies {
id = "policy"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possibly add allow_no_resource_group_match and description in here to get full coverage?

mode = "VALIDATION"

resource_groups {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possibly add inventory_filters to get full coverage?

resources {
id = "apt-to-yum"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possibly add exec, file, and pkg fields & their subfields here?


repository {
apt {
archive_type = "DEB"
components = ["doc"]
distribution = "debian"
uri = "https://atl.mirrors.clouvider.net/debian"
gpg_key = ".gnupg/pubring.kbx"
}
}
}
inventory_filters {
os_short_name = "centos"
os_version = "8.*"
}

resources {
id = "exec1"
exec {
validate {
interpreter = "SHELL"
args = ["arg1"]
file {
local_path = "$HOME/script.sh"
}
output_file_path = "$HOME/out"
}
enforce {
interpreter = "SHELL"
args = ["arg1"]
file {
allow_insecure = true
remote {
uri = "https://www.example.com/script.sh"
sha256_checksum = "c7938fed83afdccbb0e86a2a2e4cad7d5035012ca3214b4a61268393635c3063"
}
}
output_file_path = "$HOME/out"
}
}
}
}
allow_no_resource_group_match = false
description = "A test os policy"
}

rollout {
disruption_budget {
percent = 100
}

min_wait_duration = "3s"
}

description = "A test os policy assignment"
project = google_project.project.project_id
depends_on = [google_project_service.compute, google_project_service.osconfig]
}


`, context)
}

func testAccCheckOsConfigOsPolicyAssignmentDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
if rs.Type != "rs.google_os_config_os_policy_assignment" {
continue
}
if strings.HasPrefix(name, "data.") {
continue
}

config := googleProviderConfig(t)

billingProject := ""
if config.BillingProject != "" {
billingProject = config.BillingProject
}

obj := &osconfig.OSPolicyAssignment{
Location: dcl.String(rs.Primary.Attributes["location"]),
Name: dcl.String(rs.Primary.Attributes["name"]),
Description: dcl.String(rs.Primary.Attributes["description"]),
Project: dcl.StringOrNil(rs.Primary.Attributes["project"]),
SkipAwaitRollout: dcl.Bool(rs.Primary.Attributes["skip_await_rollout"] == "true"),
Baseline: dcl.Bool(rs.Primary.Attributes["baseline"] == "true"),
Deleted: dcl.Bool(rs.Primary.Attributes["deleted"] == "true"),
Etag: dcl.StringOrNil(rs.Primary.Attributes["etag"]),
Reconciling: dcl.Bool(rs.Primary.Attributes["reconciling"] == "true"),
RevisionCreateTime: dcl.StringOrNil(rs.Primary.Attributes["revision_create_time"]),
RevisionId: dcl.StringOrNil(rs.Primary.Attributes["revision_id"]),
RolloutState: osconfig.OSPolicyAssignmentRolloutStateEnumRef(rs.Primary.Attributes["rollout_state"]),
Uid: dcl.StringOrNil(rs.Primary.Attributes["uid"]),
}

client := NewDCLOsConfigClient(config, config.userAgent, billingProject, 0)
_, err := client.GetOSPolicyAssignment(context.Background(), obj)
if err == nil {
return fmt.Errorf("google_os_config_os_policy_assignment still exists %v", obj)
}
}
return nil
}
}
Loading