Skip to content

Commit

Permalink
Composer internal ip (#9507)
Browse files Browse the repository at this point in the history
  • Loading branch information
spapi17 authored Dec 15, 2023
1 parent a0fc14d commit 160dcbc
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,15 @@ func ResourceComposerEnvironment() *schema.Resource {
},
},
},
<% unless version == "ga" -%>
"composer_internal_ipv4_cidr_block": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
Description: `IPv4 cidr range that will be used by Composer internal components.`,
},
<% end -%>
},
},
},
Expand Down Expand Up @@ -1586,8 +1595,10 @@ func flattenComposerEnvironmentConfigPrivateEnvironmentConfig(envCfg *composer.P
if envCfg.NetworkingConfig != nil{
transformed["connection_type"] = envCfg.NetworkingConfig.ConnectionType
}
transformed["enable_private_endpoint"] = envCfg.PrivateClusterConfig.EnablePrivateEndpoint
transformed["master_ipv4_cidr_block"] = envCfg.PrivateClusterConfig.MasterIpv4CidrBlock
if envCfg.PrivateClusterConfig != nil{
transformed["enable_private_endpoint"] = envCfg.PrivateClusterConfig.EnablePrivateEndpoint
transformed["master_ipv4_cidr_block"] = envCfg.PrivateClusterConfig.MasterIpv4CidrBlock
}
transformed["cloud_sql_ipv4_cidr_block"] = envCfg.CloudSqlIpv4CidrBlock
transformed["web_server_ipv4_cidr_block"] = envCfg.WebServerIpv4CidrBlock
transformed["cloud_composer_network_ipv4_cidr_block"] = envCfg.CloudComposerNetworkIpv4CidrBlock
Expand Down Expand Up @@ -1615,6 +1626,9 @@ func flattenComposerEnvironmentConfigNodeConfig(nodeCfg *composer.NodeConfig) in
transformed["enable_ip_masq_agent"] = nodeCfg.EnableIpMasqAgent
transformed["tags"] = flattenComposerEnvironmentConfigNodeConfigTags(nodeCfg.Tags)
transformed["ip_allocation_policy"] = flattenComposerEnvironmentConfigNodeConfigIPAllocationPolicy(nodeCfg.IpAllocationPolicy)
<% unless version == "ga" -%>
transformed["composer_internal_ipv4_cidr_block"] = nodeCfg.ComposerInternalIpv4CidrBlock
<% end -%>
return []interface{}{transformed}
}

Expand Down Expand Up @@ -2157,6 +2171,12 @@ func expandComposerEnvironmentConfigNodeConfig(v interface{}, d *schema.Resource
}
transformed.Tags = transformedTags

<% unless version == "ga" -%>
if transformedComposerInternalIpv4CidrBlock, ok := original["composer_internal_ipv4_cidr_block"]; ok {
transformed.ComposerInternalIpv4CidrBlock = transformedComposerInternalIpv4CidrBlock.(string)
}
<% end -%>

return transformed, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,42 @@ func TestAccComposerEnvironment_customBucket(t *testing.T) {
})
}

<% unless version == "ga" -%>
// Checks Composer 3 environment creation with new fields.
func TestAccComposerEnvironmentComposer3_basic(t *testing.T) {
t.Parallel()

envName := fmt.Sprintf("%s-%d", testComposerEnvironmentPrefix, acctest.RandInt(t))
network := fmt.Sprintf("%s-%d", testComposerNetworkPrefix, acctest.RandInt(t))
subnetwork := network + "-1"

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccComposerEnvironmentDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComposerEnvironmentComposer3_basic(envName, network, subnetwork),
},
{
ResourceName: "google_composer_environment.test",
ImportState: true,
ImportStateVerify: true,
},
// This is a terrible clean-up step in order to get destroy to succeed,
// due to dangling firewall rules left by the Composer Environment blocking network deletion.
// TODO: Remove this check if firewall rules bug gets fixed by Composer.
{
PlanOnly: true,
ExpectNonEmptyPlan: false,
Config: testAccComposerEnvironmentComposer3_basic(envName, network, subnetwork),
Check: testAccCheckClearComposerEnvironmentFirewalls(t, network),
},
},
})
}
<% end -%>

func testAccComposerEnvironment_customBucket(bucketName, envName, network, subnetwork string) string {
return fmt.Sprintf(`
resource "google_storage_bucket" "test" {
Expand Down Expand Up @@ -2677,6 +2713,39 @@ resource "google_project_iam_member" "composer-worker" {
`, environment, network, subnetwork, serviceAccount)
}

<% unless version == "ga" -%>
func testAccComposerEnvironmentComposer3_basic(name, network, subnetwork string) string {
return fmt.Sprintf(`
resource "google_composer_environment" "test" {
name = "%s"
region = "us-central1"
config {
node_config {
composer_internal_ipv4_cidr_block = "100.64.128.0/20"
}
software_config {
image_version = "composer-3-airflow-2"
}
}
}

// use a separate network to avoid conflicts with other tests running in parallel
// that use the default network/subnet
resource "google_compute_network" "test" {
name = "%s"
auto_create_subnetworks = false
}

resource "google_compute_subnetwork" "test" {
name = "%s"
ip_cidr_range = "10.2.0.0/16"
region = "us-central1"
network = google_compute_network.test.self_link
}
`, name, network, subnetwork)
}
<% end -%>

// WARNING: This is not actually a check and is a terrible clean-up step because Composer Environments
// have a bug that hasn't been fixed. Composer will add firewalls to non-default networks for environments
// but will not remove them when the Environment is deleted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,11 @@ The `node_config` block supports:
packets from node IP addresses instead of Pod IP addresses
See the [documentation](https://cloud.google.com/composer/docs/enable-ip-masquerade-agent).

* `composer_internal_ipv4_cidr_block` -
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html), Cloud Composer 3 only)
At least /20 IPv4 cidr range that will be used by Composer internal components.
Cannot be updated.

The `software_config` block supports:

* `airflow_config_overrides` -
Expand Down

0 comments on commit 160dcbc

Please sign in to comment.