-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add plural data source for retrieving Maven artifacts from an Artifact Registry repository #14785
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
Add plural data source for retrieving Maven artifacts from an Artifact Registry repository #14785
Conversation
|
Hello! I am a robot. Tests will require approval from a repository maintainer to run. Googlers: For automatic test runs see go/terraform-auto-test-runs. @hao-nan-li, a repository maintainer, has been assigned to review your changes. If you have not received review feedback within 2 business days, please leave a comment on this PR asking them to take a look. You can help make sure that review is quick by doing a self-review and by running impacted tests locally. |
e9deafa to
feec853
Compare
|
@hao-nan-li This PR has been waiting for review for 3 weekdays. Please take a look! Use the label |
|
Hi there, I'm the Modular magician. I've detected the following information about your changes: Diff reportYour PR generated some diffs in downstreams - here they are.
|
Non-exercised tests🔴 Tests were added that are skipped in VCR:
Tests analyticsTotal tests: 37 Click here to see the affected service packages
🟢 All tests passed! View the build log |
| // At the moment there are no public Maven artifacts available in Artifact Registry. | ||
| // This test is skipped to avoid unnecessary failures. | ||
| // As soon as there are public artifacts available, this test can be enabled by removing the skip and adjusting the configuration accordingly. | ||
| t.Skip("No public Maven artifacts available in Artifact Registry") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you upload a log of the test even if there's no maven artifact fetched?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the output from the go-test:
make testacc TEST="./google/services/artifactregistry" TESTARGS="-run=TestAccDataSourceArtifactRegistryMavenArtifacts_"
TF_ACC=1 TF_SCHEMA_PANIC_ON_ERROR=1 go test ./google/services/artifactregistry -v -run=TestAccDataSourceArtifactRegistryMavenArtifacts_ -timeout 240m -ldflags="-X=github.com/hashicorp/terraform-provider-google/version.ProviderVersion=acc"
=== RUN TestAccDataSourceArtifactRegistryMavenArtifacts_basic
=== PAUSE TestAccDataSourceArtifactRegistryMavenArtifacts_basic
=== CONT TestAccDataSourceArtifactRegistryMavenArtifacts_basic
data_source_artifact_registry_maven_artifacts_test.go:32: No public Maven artifacts available in Artifact Registry
--- SKIP: TestAccDataSourceArtifactRegistryMavenArtifacts_basic (0.00s)
PASS
ok github.com/hashicorp/terraform-provider-google/google/services/artifactregistry 0.026sHere, you can find a snipped which, I've used for testing the data source manually after generating the provider binary from this branch and logged in with gcloud:
# Init configuration
PROJECT_ID="example-project"
REGION="europe-west3"
REPO_NAME="example-maven-repo"
GROUP_ID="com.example"
ARTIFACT_ID="my-artifact"
# Set project id in provider configuration
export GOOGLE_PROJECT="${PROJECT_ID}"
# Generate repository path
repo="${REGION}-maven.pkg.dev/${PROJECT_ID}/${REPO_NAME}"
# Create repository
gcloud artifacts repositories create "${REPO_NAME}" \
--quiet \
--project="${PROJECT_ID}" \
--location="${REGION}" \
--repository-format="maven" \
--description="example maven repo"
# Create Maven project directory and change into it
WORKDIR="maven-example"
mkdir "${WORKDIR}"
cd "${WORKDIR}" || exit
# Create minimal Maven project (pom.xml + source)
mkdir -p "src/main/java/com/example"
# Generate simple Java class
cat > src/main/java/com/example/Main.java << EOF
package ${GROUP_ID};
public class Main {
public static void main(String[] args) {
System.out.println("Hello from Maven package!");
}
}
EOF
# Deploy 3 versions of the Maven artifact
for i in $(seq 1 3); do
# Generate pom.xml for current version
cat > pom.xml << EOF
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>${GROUP_ID}</groupId>
<artifactId>${ARTIFACT_ID}</artifactId>
<version>0.0.${i}</version>
<distributionManagement>
<snapshotRepository>
<id>artifact-registry</id>
<url>artifactregistry://${REGION}-maven.pkg.dev/${PROJECT_ID}/${REPO_NAME}</url>
</snapshotRepository>
<repository>
<id>artifact-registry</id>
<url>artifactregistry://${REGION}-maven.pkg.dev/${PROJECT_ID}/${REPO_NAME}</url>
</repository>
</distributionManagement>
<repositories>
<repository>
<id>artifact-registry</id>
<url>artifactregistry://${REGION}-maven.pkg.dev/${PROJECT_ID}/${REPO_NAME}</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<build>
<extensions>
<extension>
<groupId>com.google.cloud.artifactregistry</groupId>
<artifactId>artifactregistry-maven-wagon</artifactId>
<version>2.2.0</version>
</extension>
</extensions>
</build>
</project>
EOF
# Build and upload current version
mvn deploy
done
# Create Terraform config to read latest Maven artifact
cat > main.tf << EOF
data "google_artifact_registry_maven_artifacts" "this" {
location = "${REGION}"
repository_id = "${REPO_NAME}"
}
EOF
# Initialize and apply Terraform
terraform init
terraform plan -out="out.plan"
terraform apply "out.plan"
# Show artifact data
terraform state show "data.google_artifact_registry_maven_artifacts.this"
# Cleanup
cd ..
rm -rf "${WORKDIR}"
gcloud artifacts repositories delete "${REPO_NAME}" \
--quiet \
--project="${PROJECT_ID}" \
--location="${REGION}"Here is the relevant output (anonymized):
terraform state show "data.google_artifact_registry_maven_artifacts.this"# data.google_artifact_registry_maven_artifacts.this:
data "google_artifact_registry_maven_artifacts" "this" {
id = "projects/example-project/locations/europe-west3/repositories/example-maven-repo/mavenArtifacts"
location = "europe-west3"
maven_artifacts = [
{
artifact_id = "my-artifact"
create_time = "2025-08-13T06:07:06.787517Z"
group_id = "com.example"
name = "projects/example-project/locations/europe-west3/repositories/example-maven-repo/mavenArtifacts/com.example:my-artifact:0.0.1"
pom_uri = "europe-west3-maven.pkg.dev/example-project/example-maven-repo/com/example/my-artifact/0.0.1/my-artifact-0.0.1.pom"
update_time = "2025-08-13T06:07:06.787517Z"
version = "0.0.1"
},
{
artifact_id = "my-artifact"
create_time = "2025-08-13T06:07:13.209787Z"
group_id = "com.example"
name = "projects/example-project/locations/europe-west3/repositories/example-maven-repo/mavenArtifacts/com.example:my-artifact:0.0.2"
pom_uri = "europe-west3-maven.pkg.dev/example-project/example-maven-repo/com/example/my-artifact/0.0.2/my-artifact-0.0.2.pom"
update_time = "2025-08-13T06:07:13.209787Z"
version = "0.0.2"
},
{
artifact_id = "my-artifact"
create_time = "2025-08-13T06:07:18.317992Z"
group_id = "com.example"
name = "projects/example-project/locations/europe-west3/repositories/example-maven-repo/mavenArtifacts/com.example:my-artifact:0.0.3"
pom_uri = "europe-west3-maven.pkg.dev/example-project/example-maven-repo/com/example/my-artifact/0.0.3/my-artifact-0.0.3.pom"
update_time = "2025-08-13T06:07:18.317992Z"
version = "0.0.3"
},
]
project = "example-project"
repository_id = "example-maven-repo"
}And here you can find the whole output (anonymized):
output.txt
@hao-nan-li
Please, let me know, if I can further assist you.
feec853 to
5da9af8
Compare
|
ℹ️ |
Non-exercised tests🔴 Tests were added that are skipped in VCR:
Tests analyticsTotal tests: 38 Click here to see the affected service packages
🟢 All tests passed! View the build log |
|
Thanks for the update! @yiyangw-g do you plan to do a first round of review? |
|
@hao-nan-li This PR has been waiting for review for 3 weekdays. Please take a look! Use the label |
|
@GoogleCloudPlatform/terraform-team @hao-nan-li This PR has been waiting for review for 1 week. Please take a look! Use the label |
|
@GoogleCloudPlatform/terraform-team @hao-nan-li This PR has been waiting for review for 2 weeks. Please take a look! Use the label |
|
@GoogleCloudPlatform/terraform-team @hao-nan-li This PR has been waiting for review for 3 weeks. Please take a look! Use the label |
5da9af8 to
19a4cf2
Compare
|
ℹ️ |
|
Hi @hao-nan-li , please, take a look on this. |
Non-exercised tests🔴 Tests were added that are skipped in VCR:
Tests analyticsTotal tests: 40 Click here to see the affected service packages
🟢 All tests passed! View the build log |
|
@GoogleCloudPlatform/terraform-team @hao-nan-li This PR has been waiting for review for 4 weeks. Please take a look! Use the label |
…try Maven artifacts
19a4cf2 to
660679c
Compare
|
ℹ️ |
|
@GoogleCloudPlatform/terraform-team @hao-nan-li This PR has been waiting for review for 5 weeks. Please take a look! Use the label |
Non-exercised tests🔴 Tests were added that are skipped in VCR:
Tests analyticsTotal tests: 42 Click here to see the affected service packages
Action takenFound 2 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
|
|
@GoogleCloudPlatform/terraform-team @hao-nan-li This PR has been waiting for review for 6 weeks. Please take a look! Use the label |
|
Hi @hao-nan-li @yiyangw-g , please, let me know when the review will be continued. |
da70afa
…t Registry repository (GoogleCloudPlatform#14785)
…t Registry repository (GoogleCloudPlatform#14785)
…t Registry repository (GoogleCloudPlatform#14785)
…t Registry repository (GoogleCloudPlatform#14785)
Adds a new data source
google_artifact_registry_maven_artifacts, allowing to retrieve Maven artifacts from an Artifact Registry repository.Fixes: hashicorp/terraform-provider-google#23911
Release Note Template for Downstream PRs (will be copied)